generalized the cancellation leaderboard

This commit is contained in:
2021-08-11 17:11:30 -05:00
parent 89d9bdcf7b
commit b6d41b6ba5
2 changed files with 49 additions and 35 deletions

View File

@@ -25,7 +25,8 @@ 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)
self.emoji_regex = re.compile("^who is the most (?P<emoji>\w+)(?: in the past (?P<days>\d+) days)?\??$",
re.IGNORECASE)
self.leaderboard_regex = re.compile('^most (?P<emoji>\w+) leaderboard$', re.IGNORECASE)
def run(self):
@@ -50,23 +51,23 @@ class RoboPage(discord.Client):
await self.data.add_msg(message)
if message.author != self.user:
if 'most cancelled' in message.content:
await message.reply(self.data.cancellation_leaderboard(days=14))
try:
if (m := self.leaderboard_regex.match(message.content)) is not None:
await message.reply(self.data.emoji_leaderboard(emoji_name=m.group('emoji'), days=14))
elif (m := re.search('top cancelled (?P<name>\w+)', message.content)) is not None:
async with self.data.lock:
await message.reply(self.data.worst_offsenses(user=m.group('name'), 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))
)
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)):
print(f'{joke.__class__.__name__} detected:\n{message.content}\n{scan_res}')
await joke.respond(message, self, scan_res)
for joke in self.jokes:
if (scan_res := joke.scan(message)):
print(f'{joke.__class__.__name__} detected:\n{message.content}\n{scan_res}')
await joke.respond(message, self, scan_res)
except Exception as e:
# await message.reply('oops')
raise
if __name__ == '__main__':