1
0

role.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import discord.ext.commands as discord_cmds
  2. import myanimebot.globals as globals
  3. import myanimebot.commands.permissions as permissions
  4. @discord_cmds.command(name="role")
  5. @discord_cmds.check(permissions.is_administrator)
  6. async def role_cmd(ctx, role : str):
  7. ''' Processes the command "role" and registers a role to be able to use the bot's commands '''
  8. server = ctx.guild
  9. message = ctx.message
  10. if (role == "everyone") or (role == "@everyone"):
  11. cursor = globals.conn.cursor(buffered=True)
  12. cursor.execute("UPDATE t_servers SET admin_group = NULL WHERE server = %s", [str(server.id)])
  13. globals.conn.commit()
  14. cursor.close()
  15. await ctx.send("Everyone is now allowed to use the bot.")
  16. else: # A role is found
  17. rolesFound = message.role_mentions
  18. if (len(rolesFound) == 0):
  19. return await ctx.send("Please specify a correct role.")
  20. elif (len(rolesFound) > 1):
  21. return await ctx.send("Please specify only 1 role.")
  22. else:
  23. roleFound = rolesFound[0]
  24. # Update db with newly added role
  25. cursor = globals.conn.cursor(buffered=True)
  26. cursor.execute("UPDATE t_servers SET admin_group = %s WHERE server = %s", [str(roleFound.id), str(server.id)])
  27. globals.conn.commit()
  28. cursor.close()
  29. await ctx.send("The role **{}** is now allowed to use this bot!".format(roleFound.name))
  30. @role_cmd.error
  31. async def role_cmd_error(ctx, error):
  32. ''' Processes errors from role cmd '''
  33. if isinstance(error, discord_cmds.MissingRequiredArgument):
  34. return await ctx.send("Usage: {} add **{}**/**{}** **username**".format(globals.prefix, globals.SERVICE_MAL, globals.SERVICE_ANILIST))