-
Notifications
You must be signed in to change notification settings - Fork 9
Add command that let's Tyrant pick a user's role #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Bluenix2
wants to merge
7
commits into
lemonsaurus:master
Choose a base branch
from
Bluenix2:pick-role
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
26e3045
Add command that let's Tyrant pick a user's role
Bluenix2 adfa98a
Automatically assign team role in 'pick' command
Bluenix2 f493d6d
Merge branch 'master' into pick-role
Bluenix2 900740f
Migrate pick team command to disnake
Bluenix2 9e5166c
Make team reveal more dramatic
Bluenix2 fc3e36b
Limit pick team command from being used in DMs
Bluenix2 a9b00c8
Rename pick team command to `random_team`
Bluenix2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| from disnake import AllowedMentions | ||
| from disnake.ext import commands | ||
| from disnake.ext.commands import Bot, Cog, Context | ||
| from loguru import logger | ||
|
|
||
| from tyrant import constants | ||
|
|
||
|
|
||
| class PickTeam(Cog): | ||
| """Command letting the Tyrant pick a team for the user.""" | ||
|
|
||
| def __init__(self, bot: Bot): | ||
| """Initialize this cog with the Bot instance.""" | ||
| self.bot = bot | ||
|
|
||
| @commands.command(aliases=("team",)) | ||
| async def pick(self, ctx: Context): | ||
| """Let the Tyrant pick a fruit or vegetable for you.""" | ||
Bluenix2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if ctx.guild is None: | ||
| return await ctx.send('This command can only be used in the server.') | ||
|
|
||
| # We want a sense of randomness from this algorithm so that the chosen | ||
| # roles are evenly spread out, at the same time we want the command to | ||
| # choose the same roles even if invoked twice. | ||
| key = hash( | ||
| ctx.author.display_name + | ||
| ctx.author.discriminator + | ||
| ctx.author.display_avatar.key | ||
| ) | ||
|
|
||
| index = key % len(constants.ALL_FRUIT_AND_VEG_ROLES) | ||
| choice = constants.ALL_FRUIT_AND_VEG_ROLES[index] | ||
|
|
||
| if cog := self.bot.get_cog("FruitVsVegetables"): | ||
| await cog.assign_roles( | ||
| ctx.author, | ||
| ctx.guild.get_role(choice), | ||
| ctx.guild.get_role(constants.ROLE_TO_TEAM[choice]) | ||
| ) | ||
| else: | ||
| # The FruitVsVegetables cog being loaded is a pretty important | ||
| # aspect of this command but we can still recover without it | ||
| logger.warning('Could not assign role because FruitVsVegetables cog is unloaded') | ||
|
|
||
| await ctx.send( | ||
| f"**The Tyrant decided that your role will be**... <@&{choice}>", | ||
| allowed_mentions=AllowedMentions.none() | ||
| ) | ||
|
|
||
|
|
||
| def setup(bot: Bot) -> None: | ||
| """Called by discord.py to load the extension which will add the above cog.""" | ||
| bot.add_cog(PickTeam(bot)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These command names and alises feel wrong.
.teamor.pickfeels like commands that you would use if the user used them to pick a team, not a command that would randomly assign a team for you.I think we should find a more descriptive name for this. something like
.random_teamfeels like an obvious choice, and.enlistand.enrollfeel like fun tyrant-themed aliases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to rename the cog and file with these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, the cog and the file can sort of be defended with the rationale that this bot is the tyrant and the tyrant is the one picking the role. But I don't think we can defend the commands, because the users are the ones running those commands.
I'll leave it up to you.