Skip to content
This repository has been archived by the owner on Mar 1, 2022. It is now read-only.

Commit

Permalink
Update version.
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Apr 20, 2019
1 parent 661870e commit ae28dc7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 19 additions & 9 deletions discord/ext/buttons/buttons.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
import discord
import inspect
from concurrent.futures import TimeoutError
from discord.ext import commands
from functools import partial
from typing import Union
Expand Down Expand Up @@ -43,6 +42,7 @@ def __init__(self, *, timeout: int = 180, try_remove: bool = True):
self.buttons = self._buttons

self._defaults = {}
self._default_stop = {}

def __init_subclass__(cls, **kwargs):
pass
Expand Down Expand Up @@ -133,12 +133,14 @@ async def _session_loop(self, ctx):
except discord.HTTPException:
pass

if action and button in self._defaults.values():
await button._callback(ctx)
member = ctx.guild.get_member(payload.user_id)

if action and button in self._defaults.values() or button in self._default_stop.values():
await button._callback(ctx, member)
elif action and button._callback:
await button._callback(self, ctx)
await button._callback(self, ctx, member)
elif not action and button._inverse_callback:
await button._inverse_callback(self, ctx)
await button._inverse_callback(self, ctx, member)

@property
def is_cancelled(self):
Expand All @@ -153,7 +155,11 @@ async def cancel(self, ctx):
async def teardown(self, ctx):
"""Clean the session up."""
self._session_task.cancel()
await self.page.delete()

try:
await self.page.delete()
except discord.NotFound:
pass

async def _add_reactions(self, reactions):
for reaction in reactions:
Expand Down Expand Up @@ -224,6 +230,7 @@ def __init__(self, *, title: str = '', length: int = 10, entries: list = None,
(2, '⏹'): Button(emoji='⏹', position=2, callback=partial(self._default_indexer, 'stop')),
(3, '▶'): Button(emoji='▶', position=3, callback=partial(self._default_indexer, +1)),
(4, '⏭'): Button(emoji='⏭', position=4, callback=partial(self._default_indexer, 'end'))}
self._default_stop = {(0, '⏹'): Button(emoji='⏹', position=0, callback=partial(self._default_indexer, 'stop'))}

self.buttons = {}

Expand Down Expand Up @@ -297,17 +304,20 @@ async def _paginate(self, ctx: commands.Context):

async def _session(self, ctx):
if self.use_defaults:
self.buttons = {**self._defaults, **self._buttons}
if len(self._pages) == 1:
self.buttons = {**self._default_stop, **self._buttons}
else:
self.buttons = {**self._defaults, **self._buttons}
else:
self.buttons = self._buttons

self.buttons = self.sort_buttons()

ctx.bot.loop.create_task(self._add_reactions(self.buttons.keys()))
ctx.bot.loop.create_task(self._add_reactions(self.buttons))

await self._session_loop(ctx)

async def _default_indexer(self, control, ctx):
async def _default_indexer(self, control, ctx, member):
previous = self._index

if control == 'stop':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
with open('requirements.txt') as f:
requirements = f.read().splitlines()

version = '0.1.4'
version = '0.1.7'

readme = ''
with open('README.rst') as f:
Expand Down

0 comments on commit ae28dc7

Please sign in to comment.