improved reaction handling, added some comments
This commit is contained in:
23
msg.py
23
msg.py
@@ -53,26 +53,21 @@ def message_dict(m: discord.Message) -> Dict:
|
||||
}
|
||||
|
||||
|
||||
async def reaction_df(msgs: Iterable[discord.Message]):
|
||||
return pd.concat([await reaction_series(msg) for msg in msgs if len(msg.reactions) > 0]).set_index(
|
||||
['msg id', 'emoji'])
|
||||
def full_reaction_df(msgs: Iterable[discord.Message]):
|
||||
return pd.concat([reaction_df(msg) for msg in msgs])
|
||||
|
||||
|
||||
async def reaction_series(msg: discord.Message):
|
||||
if len(msg.reactions) > 0:
|
||||
return pd.DataFrame([
|
||||
await reaction_dict(r)
|
||||
for r in msg.reactions
|
||||
])
|
||||
def reaction_df(msg: discord.Message):
|
||||
df = pd.DataFrame([reaction_dict(r) for r in msg.reactions])
|
||||
return df.set_index(['msg id', 'emoji']) if not df.empty else df
|
||||
|
||||
|
||||
async def reaction_dict(r: discord.Reaction) -> Dict:
|
||||
is_emoji = isinstance(r.emoji, (discord.Emoji, discord.PartialEmoji))
|
||||
# LOGGER.info(repr(r.emoji))
|
||||
def reaction_dict(r: discord.Reaction) -> Dict:
|
||||
return {
|
||||
'object': r,
|
||||
'msg id': r.message.id,
|
||||
'emoji': r.emoji.name if is_emoji else r.emoji.encode('unicode-escape').decode('ascii'),
|
||||
'emoji id': r.emoji.id if is_emoji else None,
|
||||
'emoji': r.emoji.name if r.is_custom_emoji() else r.emoji,
|
||||
'emoji id': r.emoji.id if r.is_custom_emoji() else None,
|
||||
'count': int(r.count),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user