added a generic command for getting the single person with the most of a certain emoji

This commit is contained in:
2021-08-11 10:49:07 -05:00
parent a5c1c1748a
commit e459c84e1e
2 changed files with 19 additions and 3 deletions

11
msg.py
View File

@@ -139,6 +139,15 @@ class MsgData:
)
return res
async def biggest_single(self, client: discord.Client, emoji: str, days: int) -> str:
data = self.emoji_totals(emoji_name=emoji, days=days)
username = data.index[0]
reacted_msgs = self.emoji_messages(emoji_name=emoji, days=days)
d = reacted_msgs.set_index('display_name')['user id'].drop_duplicates().to_dict()
user: discord.User = await client.fetch_user(user_id=d[username])
LOGGER.info(f'User: {user.mention}')
return f'{user.mention} with {data.iloc[0]["total"]:.0f} over the past {int(days)} days'
async def message_df(client: discord.Client, **kwargs):
return pd.DataFrame(
[message_dict(m) async for m in message_gen(client, **kwargs)]
@@ -213,7 +222,7 @@ def emoji_messages(msg_df, react_df, emoji_name: str, days: int = 10) -> pd.Data
def emoji_totals(edf: pd.DataFrame) -> pd.DataFrame:
totals = edf.groupby('display_name').sum()['count'].sort_values(ascending=False)
totals = edf.groupby('display_name').sum()['count'].sort_values(ascending=False).apply(int)
max_channels = (
edf
.groupby(['display_name', 'channel'])

View File

@@ -25,6 +25,7 @@ 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)
def run(self):
return super().run(os.getenv('DISCORD_TOKEN'))
@@ -37,9 +38,12 @@ class RoboPage(discord.Client):
self.data: msg.MsgData = await msg.MsgData.create(
client=self,
limit=3000,
# limit=20,
days=14,
)
self.data.to_sql('messages.db')
LOGGER.info(f'{self.data.msgs.shape[0]} messages total')
# await alive()
async def handle_message(self, message):
await self.data.add_msg(message)
@@ -52,8 +56,11 @@ class RoboPage(discord.Client):
async with self.data.lock:
await message.reply(self.data.worst_offsenses(user=m.group('name'), days=14))
elif 'biggest daddy' in message.content:
await message.reply(self.data.biggest_daddy(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))
)
for joke in self.jokes:
if (scan_res := joke.scan(message)):