Now matching in-line emojis with the leaderboard regex
This commit is contained in:
21
robopage.py
21
robopage.py
@@ -30,7 +30,7 @@ class RoboPage(discord.Client):
|
||||
re.IGNORECASE & re.UNICODE,
|
||||
)
|
||||
self.leaderboard_regex = re.compile(
|
||||
'^most (?P<emoji>.+)(?=(?:.+)?leaderboard)(?:.+(?P<days>\d+) days)?',
|
||||
'^most (?P<emoji>\S+) (leaderboard|((?:.+?(?P<days>\d+) days)))',
|
||||
re.IGNORECASE & re.UNICODE
|
||||
)
|
||||
|
||||
@@ -60,10 +60,11 @@ class RoboPage(discord.Client):
|
||||
|
||||
if (m := self.leaderboard_regex.match(message.content)) is not None:
|
||||
days = m.group('days') or 14
|
||||
emoji = m.group('emoji').lower().strip()
|
||||
try:
|
||||
await message.reply(
|
||||
await self.data.emoji_leaderboard(client=self, emoji_name=emoji, days=int(days))
|
||||
await self.data.emoji_leaderboard(client=self,
|
||||
emoji_name=get_emoji_name(m.group('emoji')),
|
||||
days=int(days))
|
||||
)
|
||||
except KeyError as e:
|
||||
LOGGER.exception(e)
|
||||
@@ -72,10 +73,11 @@ class RoboPage(discord.Client):
|
||||
|
||||
elif (m := self.most_regex.match(message.content)) is not None:
|
||||
days = m.group('days') or 14
|
||||
emoji = m.group('emoji').lower().strip()
|
||||
try:
|
||||
await message.reply(
|
||||
await self.data.biggest_single(client=self, emoji=emoji, days=int(days)))
|
||||
await self.data.biggest_single(client=self,
|
||||
emoji=get_emoji_name(m.group('emoji')),
|
||||
days=int(days)))
|
||||
except IndexError as e:
|
||||
await message.reply('NObody')
|
||||
return
|
||||
@@ -104,6 +106,11 @@ class RoboPage(discord.Client):
|
||||
await self.data.update_reaction(msg=message)
|
||||
|
||||
|
||||
def get_emoji_name(string: str) -> str:
|
||||
if (m := re.search('<:(?P<name>\w+):(?P<id>\d+)>', string)):
|
||||
string = m.group('name')
|
||||
return string.lower().strip()
|
||||
|
||||
if __name__ == '__main__':
|
||||
load_dotenv()
|
||||
|
||||
@@ -112,9 +119,7 @@ if __name__ == '__main__':
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
# print(len(list(client.get_all_members())))
|
||||
await client.handle_ready()
|
||||
# print('\n'.join(client.data.reactions.index.get_level_values(1).drop_duplicates().sort_values()))
|
||||
|
||||
|
||||
@client.event
|
||||
@@ -128,7 +133,7 @@ if __name__ == '__main__':
|
||||
|
||||
|
||||
@client.event
|
||||
async def on_raw_reaction_remove(payload: RawReactionClearEmojiEvent):
|
||||
async def on_raw_reaction_remove(payload: RawReactionActionEvent):
|
||||
await client.handle_raw_reaction(payload)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user