diff --git a/robopage.py b/robopage.py index 966ab99..4fd0067 100644 --- a/robopage.py +++ b/robopage.py @@ -4,6 +4,7 @@ import re import discord import nltk +import pandas as pd from dotenv import load_dotenv logging.basicConfig(level=logging.INFO) @@ -17,6 +18,41 @@ class RoboPage(discord.Client): BlackJoke(), AssJoke() ] + print() + + async def reaction_messages(self, target: str, **kwargs): + for c in self.get_all_channels(): + if c.guild.name == 'Family Dinner' and \ + isinstance(c, discord.TextChannel): + if c.id != 704043422276780072: + print(f'Scanning in {c.name} for cancellations') + for m in await c.history(**kwargs).flatten(): + if len(m.reactions) > 0: + for r in m.reactions: + if isinstance(r.emoji, discord.Emoji) and r.emoji.name == target: + print(r.count, m.author.display_name) + yield m, r.count + + + async def get_cancelled_totals(self, limit=1000): + df = pd.DataFrame( + [{ + 'display_name': m.author.display_name, + 'cancelled': count, + 'message': m.content + } + async for m, count in self.reaction_messages('cancelled', limit=limit)] + ) + df.to_csv('msgs.csv', index=False) + + s = df.groupby('display_name')['cancelled'].sum().sort_values(ascending=False) + res = f'Cancellation totals, past {limit} messages in each channel:\n`' + for name, total in s.iteritems(): + res += f'{total} {name}\n' + res = res[:-1] + res += '`' + + return res def run(self): return super().run(os.getenv('DISCORD_TOKEN')) @@ -27,6 +63,10 @@ class RoboPage(discord.Client): async def handle_message(self, message): if message.author != self.user: + if 'most cancelled' in message.content: + msg: discord.Message = await message.reply('Hold please...') + await msg.reply(await self.get_cancelled_totals()) + for joke in self.jokes: if (scan_res := joke.scan(message)): print(f'{joke.__class__.__name__} detected:\n{message.content}\n{scan_res}') @@ -57,7 +97,7 @@ class CumJoke(Joke): 'cumming', 'cummed' ] - return re.compile(f"(?