Skip to content

Commit

Permalink
More work on reaction logging
Browse files Browse the repository at this point in the history
Co-authored-by: SaltyCatNS <[email protected]>
  • Loading branch information
MattBSG and SaltyCatNS committed Aug 11, 2024
1 parent 7200520 commit 56d7fb7
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions modules/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,51 @@ async def process_affiliate_reactions(self, payload):
# async def _archive(self, ctx, members: commands.Greey[discord.Member], channels: commands.Greedy[discord.Channel], limit: typing.Optional[int] = 200, channel_limiter: typing.Greedy[discord.Channel]):
# pass

@app_commands.guilds(discord.Object(id=config.nintendoswitch))
@app_commands.default_permissions(view_audit_log=True)
@app_commands.checks.has_any_role(config.moderator, config.eh)
class ReactionCommand(app_commands.Group):
pass

react_group = ReactionCommand(name='react', description='View info about reactions in the server')

@react_group.command(name='stats', description='View reaction log for a given user or message')
async def _react_stats(self, interaction: discord.Interaction):
await interaction.response.defer(ephemeral=tools.mod_cmd_invoke_delete(interaction.channel))

docs = list(self.reactDB.find({}))
users = {}

for d in docs:
if d['user'] not in users:
users[d['user']] = {
'count': 1,
'emojis': [d['emoji']]
}

else:
users[d['user']]["count"] += 1
emojiList = users[d['user']]["emojis"]

if d['emoji'] not in emojiList:
emojiList.append(d['emoji'])


embed = discord.Embed(color=0xff08bd, title = "Stat Overview")
embed.description = "Here's a list of most frequent reactors."
embed.set_author(name=interaction.user.name, icon_url=interaction.user.display_avatar.url)

unsortedList = [{'user': key, 'values': value} for key, value in users.items()]
sortedList = sorted(unsortedList, key=lambda u: u['values']['count'], reverse=True)
for x in sortedList[0:6]:
embed.add_field(name=x['user'], value=f'reaction count: {x["values"]["count"]}\n{", ".join(x["values"]["emojis"])}')


await interaction.followup.send(embed=embed)


# Then sort this list by highest to lowest count

@app_commands.command(name='clean', description='Delete upto 2000 messages, optionally only from 1 or more users')
@app_commands.describe(
count='The number of messages to search for and delete that match the user filter',
Expand Down

0 comments on commit 56d7fb7

Please sign in to comment.