added a generic command for getting the single person with the most of a certain emoji

This commit is contained in:
2021-08-11 10:49:07 -05:00
parent a5c1c1748a
commit e459c84e1e
2 changed files with 19 additions and 3 deletions

View File

@@ -25,6 +25,7 @@ class RoboPage(discord.Client):
attrs = map(lambda n: getattr(jokes, n)(), attrs)
self.jokes = list(attrs)
self.lock = Lock()
self.emoji_regex = re.compile("^who is the most (?P<emoji>\w+)(?: in the past (?P<days>\d+) days)?\??$", re.IGNORECASE)
def run(self):
return super().run(os.getenv('DISCORD_TOKEN'))
@@ -37,9 +38,12 @@ class RoboPage(discord.Client):
self.data: msg.MsgData = await msg.MsgData.create(
client=self,
limit=3000,
# limit=20,
days=14,
)
self.data.to_sql('messages.db')
LOGGER.info(f'{self.data.msgs.shape[0]} messages total')
# await alive()
async def handle_message(self, message):
await self.data.add_msg(message)
@@ -52,8 +56,11 @@ class RoboPage(discord.Client):
async with self.data.lock:
await message.reply(self.data.worst_offsenses(user=m.group('name'), days=14))
elif 'biggest daddy' in message.content:
await message.reply(self.data.biggest_daddy(days=14))
elif (m := self.emoji_regex.match(message.content)) is not None:
days = m.group('days') or 14
await message.reply(
await self.data.biggest_single(client=self, emoji=m.group('emoji'), days=int(days))
)
for joke in self.jokes:
if (scan_res := joke.scan(message)):