You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.2KB

  1. import discord
  2. from discord.ext import commands
  3. from Roxbot import load_config
  4. from Roxbot.settings import guild_settings as gs
  5. class SelfAssign():
  6. def __init__(self, Bot):
  7. self.bot = Bot
  8. self.embed_colour = load_config.embedcolour
  9. @commands.command(pass_context=True)
  10. async def listroles(self, ctx):
  11. """
  12. List's all roles that can be self-assigned on this server.
  13. Usage:
  14. {command_prefix}listroles
  15. """
  16. settings = gs.get(ctx.guild)
  17. if not settings.self_assign["enabled"]:
  18. embed = discord.Embed(colour=discord.Colour(self.embed_colour),
  19. description="SelfAssignable roles are not enabled on this server")
  20. return await ctx.send(embed=embed)
  21. roles = []
  22. for role in settings.self_assign["roles"]:
  23. for serverrole in ctx.guild.roles:
  24. if role == serverrole.id:
  25. roles.append("**"+serverrole.name+"**")
  26. roles = '\n'.join(roles)
  27. embed = discord.Embed(colour=self.embed_colour,
  28. description="The self-assignable roles for this server are: \n"+roles)
  29. return await ctx.send(embed=embed)
  30. @commands.command(pass_context=True)
  31. async def iam(self, ctx, *, role: discord.Role = None):
  32. """
  33. Self-assign yourself a role. Only one role at a time.
  34. Usage:
  35. {command_prefix}iam [role]
  36. Example:
  37. .iam OverwatchPing
  38. """
  39. settings = gs.get(ctx.guild)
  40. if not settings.self_assign["enabled"]:
  41. embed = discord.Embed(colour=discord.Colour(self.embed_colour),
  42. description="SelfAssignable roles are not enabled on this server")
  43. return await ctx.send(embed=embed)
  44. member = ctx.author
  45. if role in member.roles:
  46. return await ctx.send("You already have that role.")
  47. if role.id in settings.self_assign["roles"]:
  48. await member.add_roles(role, reason="'iam' command triggered.")
  49. return await ctx.send("Yay {}! You now have the {} role!".format(member.mention, role.name))
  50. else:
  51. return await ctx.send("That role is not self-assignable.")
  52. @commands.command(pass_context=True)
  53. async def iamn(self, ctx, *, role: discord.Role = None):
  54. """
  55. Remove a self-assigned role
  56. Usage:
  57. {command_prefix}iamn [role]
  58. Example:
  59. .iamn OverwatchPing
  60. """
  61. settings = gs.get(ctx.guild)
  62. if not settings.self_assign["enabled"]:
  63. embed = discord.Embed(colour=discord.Colour(self.embed_colour),
  64. description="SelfAssignable roles are not enabled on this server")
  65. return await ctx.send(embed=embed)
  66. member = ctx.author
  67. if role in member.roles and role.id in settings.self_assign["roles"]:
  68. await member.remove_roles(role, reason="'iamn' command triggered.")
  69. return await ctx.send("{} has been successfully removed.".format(role.name))
  70. elif role not in member.roles and role.id in settings.self_assign["roles"]:
  71. return await ctx.send("You do not have {}.".format(role.name))
  72. else:
  73. return await ctx.send("That role is not self-assignable.")
  74. @iam.error
  75. async def iam_err(self, ctx, error):
  76. if isinstance(error, commands.BadArgument):
  77. return await ctx.send("This role doesn't exist. Reminder, roles are case-sensitive.")
  78. @iamn.error
  79. async def iamn_err(self, ctx, error):
  80. if isinstance(error, commands.BadArgument):
  81. return await ctx.send("This role doesn't exist. Reminder, roles are case-sensitive.")
  82. def setup(Bot):
  83. Bot.add_cog(SelfAssign(Bot))