reworked update_reaction and emoji calculation. Should work with unicode emojis now

This commit is contained in:
2021-08-15 11:55:49 -05:00
parent 1fd0699d8e
commit 9d41c2bdf1
2 changed files with 32 additions and 31 deletions

30
data.py
View File

@@ -82,27 +82,28 @@ class MsgData:
LOGGER.info(f'Added message id {message.id} from {message.author}: {message.content}')
async def update_reaction(self, msg: discord.Message):
async with self.lock:
# Drop all the reactions for this message id, if there are any
try:
# Drop all the reactions for this message id, if there are any
try:
async with self.lock:
self.reactions.drop(msg.id, level=0, axis=0, inplace=True)
except KeyError as e:
pass
except KeyError as e:
pass
# If there are reactions on the message after the change
if len(msg.reactions) > 0:
new = reaction_df(msg)
# If there are reactions on the message after the change
if len(msg.reactions) > 0:
new = reaction_df(msg)
async with self.lock:
self.reactions = pd.concat([self.reactions, new])
LOGGER.info(str(new.droplevel(level=0, axis=0).loc[:, 'count']))
LOGGER.info(str(new.droplevel(level=0, axis=0).loc[:, 'count']))
if msg.id not in self.msgs.index:
await self.add_msg(msg)
if msg.id not in self.msgs.index:
await self.add_msg(msg)
return new
return new
def emoji_messages(self, emoji_name: str, days: int = None) -> pd.DataFrame:
"""Creates a DataFrame of the messages that have reactions with a certain emoji. Includes a 'count' column"""
counts: pd.DataFrame = self.emoji_counts(emoji_name)
counts: pd.Series = self.emoji_counts(emoji_name)
# Get the ids of messages that that have the targeted emoji
message_id_counts: pd.Index = counts.index.drop_duplicates()
@@ -117,10 +118,11 @@ class MsgData:
res['count'] = counts
if days is not None:
if days is not None and days > 0:
res = res[res['created'] >= (datetime.today() - timedelta(days=days)).astimezone()]
return res.sort_values('created', ascending=False)
else:
raise KeyError(f'No messages found with {emoji_name} reactions')