Skip to content

Commit

Permalink
Issue parafoxia#71: Fixed fallback emojis on Selector class
Browse files Browse the repository at this point in the history
  • Loading branch information
bradykelly committed Oct 7, 2020
1 parent 3e78b37 commit 11eeeb4
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions solaris/utils/menu/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

from asyncio import TimeoutError
from datetime import timedelta
from solaris.utils.emoji import ALTERNATIVES
from solaris.utils import emoji

from solaris.utils import chron

Expand All @@ -40,11 +42,23 @@ def selection(self):
def selection(self, value):
self._base_selection = value

def get_emoji_name(self, emoji):
emoji_name = None
if isinstance(emoji, str):
for name, value in ALTERNATIVES.items():
if value == emoji:
emoji_name = name
break
elif hasattr(emoji, "name"):
emoji_name = emoji.name
return emoji_name

def _default_check(self, reaction, user):
emoji_name = self.get_emoji_name(reaction.emoji)
return (
reaction.message.id == self.menu.message.id
and user == self.menu.ctx.author
and reaction.emoji.name in self.selection
and emoji_name in self.selection
)

async def _serve(self):
Expand All @@ -61,7 +75,8 @@ async def response(self):
except TimeoutError:
await self.menu.timeout(chron.long_delta(timedelta(seconds=self.timeout)))
else:
if (r := reaction.emoji.name) == "exit" and self.auto_exit:
emoji_name = self.get_emoji_name(reaction.emoji)
if (r := emoji_name) == "exit" and self.auto_exit:
await self.menu.stop()
else:
return r
Expand Down Expand Up @@ -150,7 +165,8 @@ async def response(self):
except TimeoutError:
await self.menu.timeout(chron.long_delta(timedelta(seconds=self.timeout)))
else:
if (r := reaction.emoji.name) == "exit":
emoji_name = self.get_emoji_name(reaction.emoji)
if (r := emoji_name) == "exit":
if self.auto_exit:
await self.menu.stop()
return
Expand Down Expand Up @@ -243,7 +259,8 @@ async def response(self):
except TimeoutError:
await self.menu.timeout(chron.long_delta(timedelta(seconds=self.timeout)))
else:
if (r := reaction.emoji.name) == "exit":
emoji_name = self.get_emoji_name(reaction.emoji)
if (r := emoji_name) == "exit":
if self.auto_exit:
await self.menu.stop()
return
Expand Down

0 comments on commit 11eeeb4

Please sign in to comment.