Skip to content

Commit

Permalink
Add a context menu for profile view
Browse files Browse the repository at this point in the history
  • Loading branch information
MattBSG committed Jun 24, 2024
1 parent 3a89345 commit 17e39d1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/social.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def __init__(self, bot):
self.bucket_storage = token_bucket.MemoryStorage()
self.profile_bucket = token_bucket.Limiter(1 / 30, 2, self.bucket_storage) # burst limit 2, renews at 1 / 30 s

# Add context menus to command tree
self.profileContextMenu = app_commands.ContextMenu(
name='View Profile Card', callback=self._profile_view, type=discord.AppCommandType.user
)
self.bot.tree.add_command(self.profileContextMenu, guild=discord.Object(id=config.nintendoswitch))

# Profile generation
self.twemojiPath = 'resources/twemoji/assets/72x72/'
self.bot_contributors = [
Expand Down Expand Up @@ -180,6 +186,9 @@ async def _profile(self, interaction: discord.Interaction, member: typing.Option
if not member:
member = interaction.user

await self._profile_view(interaction, member)

async def _profile_view(self, interaction: discord.Interaction, member: discord.Member):
# If channel can be ratelimited
if interaction.channel.id not in [config.commandsChannel, config.debugChannel]:
channel_being_rate_limited = not self.profile_bucket.consume(str(interaction.channel.id))
Expand Down

0 comments on commit 17e39d1

Please sign in to comment.