Browse Source

fixed error where sa wasn't catching errors for when roles were already in the db

pull/57/head
Roxie Gibson 5 years ago
parent
commit
94266b543f
No known key found for this signature in database
1 changed files with 29 additions and 21 deletions
  1. +29
    -21
      roxbot/cogs/selfassign.py

+ 29
- 21
roxbot/cogs/selfassign.py View File

@@ -71,32 +71,40 @@ class SelfAssign(commands.Cog):
"""
with db_session:
self_assign = SelfAssignSingle.get(guild_id=ctx.guild.id)
if setting == "enable":
if setting == "enable":
with db_session:
self_assign.enabled = True
await ctx.send("'self_assign' was enabled!")
elif setting == "disable":
await ctx.send("'self_assign' was enabled!")

elif setting == "disable":
with db_session:
self_assign.enabled = False
await ctx.send("'self_assign' was disabled :cry:")
elif setting == "add":
try:
await ctx.send("'self_assign' was disabled :cry:")

elif setting == "add":
try:
with db_session:
SelfAssignRoles(role_id=role.id, guild_id=ctx.guild.id)
await ctx.send('Role "{}" added'.format(str(role)))
except AttributeError:
raise commands.BadArgument("Could not find that role.")
except TransactionIntegrityError:
raise commands.BadArgument("{} is already a self-assignable role.".format(role.name))
elif setting == "remove":
try:
return await ctx.send('Role "{}" added'.format(str(role)))
except AttributeError:
raise commands.BadArgument("Could not find that role.")
except TransactionIntegrityError:
raise commands.BadArgument("{} is already a self-assignable role.".format(role.name))

elif setting == "remove":
try:
with db_session:
query = SelfAssignRoles.get(role_id=role.id)
if query:
if query:
with db_session:
query.delete()
return await ctx.send('"{}" has been removed from the self-assignable roles.'.format(str(role)))
else:
return await ctx.send("That role was not in the list.")
except AttributeError:
raise commands.BadArgument("Could not find that role.")
else:
return await ctx.send("No valid option given.")
return await ctx.send('"{}" has been removed from the self-assignable roles.'.format(str(role)))
else:
return await ctx.send("That role was not in the list.")
except AttributeError:
raise commands.BadArgument("Could not find that role.")
else:
return await ctx.send("No valid option given.")

@commands.guild_only()
@commands.command(pass_context=True)

Loading…
Cancel
Save