diff --git a/msg.py b/msg.py index f8d4220..fbd10b1 100644 --- a/msg.py +++ b/msg.py @@ -114,6 +114,19 @@ class MsgData: ) return res + def worst_offsenses(self, user: str, days: int): + cdf = self.cancellations(days=days) + cdf = cdf[cdf['display_name'].str.contains(user, case=False)] + + if cdf.shape[0] > 0: + res = f'{user}\'s top 5 cancellations in the last {days} days:\n' + res += f'\n'.join( + f'`{row["count"]:<2.0f}cancellations`\n{row["link"]}' for idx, row in cdf.iloc[:5].iterrows()) + else: + res = f'No cancellations for {user} in the past {days} days' + + return res + async def message_df(client: discord.Client, **kwargs): return pd.DataFrame( @@ -203,7 +216,7 @@ def cancelled_totals(cdf: pd.DataFrame) -> pd.DataFrame: return pd.DataFrame({ 'total': totals, 'max channel': max_channels, - 'worst': cdf.groupby('display_name').max()['link'] + # 'worst': cdf.groupby('display_name').max()['link'] }).sort_values('total', ascending=False) diff --git a/robopage.py b/robopage.py index 91b75af..6c70eac 100644 --- a/robopage.py +++ b/robopage.py @@ -40,8 +40,6 @@ class RoboPage(discord.Client): days=14, ) self.data.to_sql('messages.db') - LOGGER.info(str(self.data.msgs.columns)) - LOGGER.info(str(self.data.reactions.columns)) async def handle_message(self, message): await self.data.add_msg(message) @@ -52,25 +50,13 @@ class RoboPage(discord.Client): elif (m := re.search('top cancelled (?P\w+)', message.content)) is not None: async with self.data.lock: - await message.reply(self.top_cancellations(user=m.group('name'), days=14)) + await message.reply(self.data.worst_offsenses(user=m.group('name'), days=14)) 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) - def top_cancellations(self, user: str, days: int): - cdf = self.data.cancellations(days) - cdf = cdf[cdf['display_name'].str.contains(user, case=False)] - - if cdf.shape[0] > 0: - res = f'{user}\'s top 5 cancellations in the last {days} days:\n' - res += f'\n'.join(f'`{row["count"]} cancellations`\n{row["link"]}' for idx, row in cdf.iloc[:5].iterrows()) - else: - res = f'No cancellations for {user} in the past {days} days' - - return res - if __name__ == '__main__': load_dotenv() @@ -80,7 +66,7 @@ if __name__ == '__main__': @client.event async def on_ready(): - print(len(list(client.get_all_members()))) + # print(len(list(client.get_all_members()))) await client.handle_ready() print(client.data.cancellation_totals(14)) @@ -94,6 +80,7 @@ if __name__ == '__main__': async def on_raw_reaction_add(payload): LOGGER.info(payload) await client.data.update_reaction(payload=payload, client=client) + LOGGER.info(f'Leaderboard:\n{str(client.data.cancellation_totals(14)["total"].apply(int))}') @client.event