added top cancellation function

This commit is contained in:
2021-08-02 15:03:23 -05:00
parent 1e1037dbe2
commit 117e9930e4

View File

@@ -49,7 +49,11 @@ class RoboPage(discord.Client):
if message.author != self.user: if message.author != self.user:
if 'most cancelled' in message.content: if 'most cancelled' in message.content:
msg: discord.Message = await message.reply('Hold please...') msg: discord.Message = await message.reply('Hold please...')
await msg.reply(await self.get_cancelled_totals(limit=1000)) await message.reply(await self.get_cancelled_totals(limit=1000, days=14))
elif (m := re.search('top cancelled (?P<name>\w+)', message.content)) is not None:
msg: discord.Message = await message.reply('Hold please...')
await message.reply(await self.top_cancellations(user=m.group('name'), limit=1000, days=14))
for joke in self.jokes: for joke in self.jokes:
if (scan_res := joke.scan(message)): if (scan_res := joke.scan(message)):
@@ -57,9 +61,24 @@ class RoboPage(discord.Client):
await joke.respond(message, self, scan_res) await joke.respond(message, self, scan_res)
async def get_cancelled_totals(self, limit=1000, days: int = 90): async def get_cancelled_totals(self, limit=1000, days: int = 90):
msg_df, react_df = await get_and_save('messages.db', client=self, limit=limit, days=days) msg_df, react_df = await get_and_save(self.db_path, client=self, limit=limit, days=days)
res = cancelled_totals(cancellations(msg_df, react_df, days=days)) res = cancelled_totals(cancellations(msg_df, react_df, days=days))
return report_string(res.iloc[:5]) res = f'Cancellation totals, past {days} days\n' + report_string(res.iloc[:5])
return res
async def top_cancellations(self, user: str, limit: int, days: int):
msg_df, react_df = await get_and_save(self.db_path, client=self, limit=limit, days=days)
cdf = cancellations(msg_df, react_df, 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"]} cancellations`\n{row["link"]}' for idx, row in cdf.iloc[:5].iterrows())
else:
res = f'No cancellations in the past {days} days'
return res
class Joke: class Joke:
@@ -173,6 +192,7 @@ if __name__ == '__main__':
async def on_ready(): async def on_ready():
print(f'{client.user} has connected to Discord!') print(f'{client.user} has connected to Discord!')
# await client.handle_ready() # await client.handle_ready()
# msg_df, react_df = await get_and_save('messages.db', client=client, limit=5000, days=90)
@client.event @client.event