Skip to content

Commit

Permalink
[RoleTools] 1.5.16 Fix selfrole checks
Browse files Browse the repository at this point in the history
- Remove early checks in `[p]roletools selfrole` for requirements and cost since they're already handled in the giverole function.
  - This also fixes an issue where give_role might not have actually given the role causing the user to receive a message stating they got the role when they didn't.
  • Loading branch information
TrustyJAID committed Dec 15, 2024
1 parent 49f7e72 commit 4b78564
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ TrustyJAID's Cogs for [Red-DiscordBot](https://github.com/Cog-Creators/Red-Disc
| Reddit | 1.2.0 | <details><summary>A cog to post updates from reddit.</summary>Reddit commands for getting updates on specified subreddits.</details> | TrustyJAID |
| Rekt | 1.0.0 | <details><summary>Get REKT</summary>Are you REKT?</details> | TrustyJAID |
| ReTrigger | 2.29.1 | <details><summary>Trigger events via Regular Expressions!</summary>Trigger events based on regex! Check out <https://regex101.com/> and <https://github.com/TrustyJAID/Trusty-cogs/blob/master/retrigger/README.md> for help setting up the cog. Note: This cog can become quite resource heavy. Optional features are available if the requirements are present such as pillow for image resizing and pytesseract to scan images for text (OCR).</details> | TrustyJAID |
| RoleTools | 1.5.15 | <details><summary>Various role related tools.</summary>Various role utility commands. Including Reaction roles, Sticky roles, and Auto role.</details> | TrustyJAID |
| RoleTools | 1.5.16 | <details><summary>Various role related tools.</summary>Various role utility commands. Including Reaction roles, Sticky roles, and Auto role.</details> | TrustyJAID |
| runescape | 1.5.2 | <details><summary>Show your Runescape stats in discord!</summary>A cog to grab Runescape and OSRS stats and profile information.</details> | TrustyJAID |
| ServerStats | 1.8.0 | <details><summary>A plethora of potentially useful commands for any bot owner.</summary>A plethora of potentially useful commands for any bot owner. Includes a way to track the bot joining new servers, find cheaters on global economies, get user avatars and even larger emojis.</details> | TrustyJAID and Preda |
| Spotify | 1.7.3 | <details><summary>Control Spotify through Discord!</summary>This cog allows you to control Spotify via OAuth through the bot on discord. Use `[p]spotify` to see available commands.</details> | TrustyJAID and NeuroAssassin |
Expand Down
44 changes: 12 additions & 32 deletions roletools/roletools.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class RoleTools(
"""

__author__ = ["TrustyJAID"]
__version__ = "1.5.15"
__version__ = "1.5.16"

def __init__(self, bot: Red):
self.bot = bot
Expand Down Expand Up @@ -280,57 +280,37 @@ async def selfrole(self, ctx: Context, *, role: SelfRoleConverter) -> None:
else:
await self.selfrole_remove(ctx, role=role)

async def selfrole_add(self, ctx: Context, *, role: SelfRoleConverter) -> None:
async def selfrole_add(self, ctx: Context, *, role: discord.Role) -> None:
"""
Give yourself a role
`<role>` The role you want to give yourself
"""
await ctx.typing()
author = ctx.author
author: discord.Member = ctx.author

if not await self.config.role(role).selfassignable():
msg = _("The {role} role is not currently selfassignable.").format(role=role.mention)
await ctx.send(msg)
return
if required := await self.config.role(role).required():
has_required = True
for role_id in required:
r = ctx.guild.get_role(role_id)
if r is None:
async with self.config.role(role).required() as required_roles:
required_roles.remove(role_id)
continue
if r not in author.roles:
has_required = False
if not has_required:
msg = _(
"I cannot grant you the {role} role because you "
"are missing a required role."
).format(role=role.mention)
await ctx.send(msg)
return
if cost := await self.config.role(role).cost():
currency_name = await bank.get_currency_name(ctx.guild)
if not await bank.can_spend(author, cost):
msg = _(
"You do not have enough {currency_name} to acquire "
"this role. You need {cost} {currency_name}."
).format(currency_name=currency_name, cost=cost)
await ctx.send(msg)
return
await self.give_roles(author, [role], _("Selfrole command."))
response = await self.give_roles(author, [role], _("Selfrole command."))
if response:
msg = _("I could not assign that role for the following reasons:\n")
for r in response:
msg += r.reason
await ctx.send(msg)
return
msg = _("You have been given the {role} role.").format(role=role.mention)
await ctx.send(msg)

async def selfrole_remove(self, ctx: Context, *, role: SelfRoleConverter) -> None:
async def selfrole_remove(self, ctx: Context, *, role: discord.Role) -> None:
"""
Remove a role from yourself
`<role>` The role you want to remove.
"""
await ctx.typing()
author = ctx.author
author: discord.Member = ctx.author

if not await self.config.role(role).selfremovable():
msg = _("The {role} role is not currently self removable.").format(role=role.mention)
Expand Down

0 comments on commit 4b78564

Please sign in to comment.