Skip to content

Commit

Permalink
Add aliases examples to !roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Tina-otoge committed Jul 10, 2024
1 parent 8abe454 commit 163e3c5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion mechadon/cogs/selfrole.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random

import sqlalchemy as sa
from discord import Role
from discord.ext.commands.errors import CommandError
Expand Down Expand Up @@ -90,7 +92,19 @@ async def roles(self, context: Context):
roles = filter(
lambda x: x.id in [r.role_id for r in roles_db], context.guild.roles
)
await self.reply(context, *roles, sep="\n", sort=True)
aliases = db.session.query(RoleAlias).filter_by(
server_id=context.guild.id
)
aliases_picks = random.sample(list(aliases), min(5, aliases.count()))
roles = [str(x) for x in roles]
roles.sort(key=str.lower)
msg = "\n".join(roles)
if aliases_picks:
msg += (
"\n\nYou can also use aliases for convenience, examples:\n"
+ "\n".join([x.str(context) for x in aliases_picks])
)
await self.reply(context, msg)

@commands.command()
async def aliases(self, context: Context):
Expand Down

0 comments on commit 163e3c5

Please sign in to comment.