added a generic command for getting the single person with the most of a certain emoji
This commit is contained in:
11
msg.py
11
msg.py
@@ -139,6 +139,15 @@ class MsgData:
|
|||||||
)
|
)
|
||||||
return res
|
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):
|
async def message_df(client: discord.Client, **kwargs):
|
||||||
return pd.DataFrame(
|
return pd.DataFrame(
|
||||||
[message_dict(m) async for m in message_gen(client, **kwargs)]
|
[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:
|
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 = (
|
max_channels = (
|
||||||
edf
|
edf
|
||||||
.groupby(['display_name', 'channel'])
|
.groupby(['display_name', 'channel'])
|
||||||
|
|||||||
11
robopage.py
11
robopage.py
@@ -25,6 +25,7 @@ class RoboPage(discord.Client):
|
|||||||
attrs = map(lambda n: getattr(jokes, n)(), attrs)
|
attrs = map(lambda n: getattr(jokes, n)(), attrs)
|
||||||
self.jokes = list(attrs)
|
self.jokes = list(attrs)
|
||||||
self.lock = Lock()
|
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):
|
def run(self):
|
||||||
return super().run(os.getenv('DISCORD_TOKEN'))
|
return super().run(os.getenv('DISCORD_TOKEN'))
|
||||||
@@ -37,9 +38,12 @@ class RoboPage(discord.Client):
|
|||||||
self.data: msg.MsgData = await msg.MsgData.create(
|
self.data: msg.MsgData = await msg.MsgData.create(
|
||||||
client=self,
|
client=self,
|
||||||
limit=3000,
|
limit=3000,
|
||||||
|
# limit=20,
|
||||||
days=14,
|
days=14,
|
||||||
)
|
)
|
||||||
self.data.to_sql('messages.db')
|
self.data.to_sql('messages.db')
|
||||||
|
LOGGER.info(f'{self.data.msgs.shape[0]} messages total')
|
||||||
|
# await alive()
|
||||||
|
|
||||||
async def handle_message(self, message):
|
async def handle_message(self, message):
|
||||||
await self.data.add_msg(message)
|
await self.data.add_msg(message)
|
||||||
@@ -52,8 +56,11 @@ class RoboPage(discord.Client):
|
|||||||
async with self.data.lock:
|
async with self.data.lock:
|
||||||
await message.reply(self.data.worst_offsenses(user=m.group('name'), days=14))
|
await message.reply(self.data.worst_offsenses(user=m.group('name'), days=14))
|
||||||
|
|
||||||
elif 'biggest daddy' in message.content:
|
elif (m := self.emoji_regex.match(message.content)) is not None:
|
||||||
await message.reply(self.data.biggest_daddy(days=14))
|
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:
|
for joke in self.jokes:
|
||||||
if (scan_res := joke.scan(message)):
|
if (scan_res := joke.scan(message)):
|
||||||
|
|||||||
Reference in New Issue
Block a user