diff --git a/msg.py b/msg.py index 0a6ef4e..349c37e 100644 --- a/msg.py +++ b/msg.py @@ -164,7 +164,7 @@ async def message_gen(client: discord.Client, limit=20, days: int = 90, **kwargs channels = filter(lambda c: isinstance(c, discord.TextChannel), channels) channels = filter(lambda c: c.category.name != 'Archive', channels) channels = sorted(channels, key=lambda c: (c.category.name, c.name)) - for channel in channels[:5]: + for channel in channels: LOGGER.info(f'{channel.category.name} #{channel.name}') if 'after' not in kwargs: kwargs['after'] = (datetime.today() - timedelta(days=days)) diff --git a/robopage.py b/robopage.py index 01a17c0..5e9bdb8 100644 --- a/robopage.py +++ b/robopage.py @@ -25,8 +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\w+)(?: in the past (?P\d+) days)?\??$", - re.IGNORECASE) + self.most_regex = re.compile("^who is the most (?P\w+)(?: in the past (?P\d+) days)?\??$", + re.IGNORECASE) self.leaderboard_regex = re.compile('^most (?P\w+) leaderboard$', re.IGNORECASE) def run(self): @@ -39,8 +39,8 @@ class RoboPage(discord.Client): self.data: msg.MsgData = await msg.MsgData.create( client=self, - # limit=3000, - limit=20, + limit=3000, + # limit=20, days=14, ) self.data.to_sql('messages.db') @@ -51,23 +51,26 @@ class RoboPage(discord.Client): await self.data.add_msg(message) if message.author != self.user: - try: - if (m := self.leaderboard_regex.match(message.content)) is not None: + if (m := self.leaderboard_regex.match(message.content)) is not None: + try: await message.reply(self.data.emoji_leaderboard(emoji_name=m.group('emoji'), days=14)) + except KeyError as e: + await message.reply(f"I couldn't find any {m.group('emoji')} reactions. Leave me alone!") - elif (m := self.emoji_regex.match(message.content)) is not None: - days = m.group('days') or 14 + elif (m := self.most_regex.match(message.content)) is not None: + days = m.group('days') or 14 + try: await message.reply( await self.data.biggest_single(client=self, emoji=m.group('emoji'), days=int(days)) ) + except IndexError as e: + await message.reply('NObody') + else: 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__':