roles.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import discord
  2. from discord.ext.commands import Cog
  3. from discord.commands import slash_command, Option
  4. from os import getenv
  5. def setup(bot: discord.Bot):
  6. bot.add_cog(Roles(bot))
  7. GUILD = int(getenv("GUILD_ID"))
  8. ROLES = {
  9. 'COLOR_LIGHT_RED': 608191366090063892,
  10. 'COLOR_RED': 519029920530169857,
  11. 'COLOR_SATAN_RED': 608084225115160616,
  12. 'COLOR_DEEP_ORANGE': 519052968155283456,
  13. 'COLOR_ORANGE': 519031205656788993,
  14. 'COLOR_BROWN': 519036336351477761,
  15. 'COLOR_PISS_YELLOW': 608084227485073418,
  16. 'COLOR_YELLOW': 519031288422727745,
  17. 'COLOR_LIGHT_YELLOW': 608084233327476737,
  18. 'COLOR_LIME': 519031608997707797,
  19. 'COLOR_MINT_GREEN': 608084229930090526,
  20. 'COLOR_LIGHT_GREEN': 519052647278444545,
  21. 'COLOR_GREEN': 519031954188795936,
  22. 'COLOR_TREE_GREEN': 608084229825364014,
  23. 'COLOR_AQUAMARINE': 519032187815985152,
  24. 'COLOR_TEAL': 519052208080420865,
  25. 'COLOR_CYAN': 519032473561071675,
  26. 'COLOR_PASTEL_CYAN': 608087343030730753,
  27. 'COLOR_LIGHT_BLUE': 519032676100079626,
  28. 'COLOR_DISCORD_BLUE': 608087654420185104,
  29. 'COLOR_BLUE': 519033502390550530,
  30. 'COLOR_NAVY_BLUE': 608084227027632128,
  31. 'COLOR_INDIGO': 519034578866929674,
  32. 'COLOR_DEEP_PURPLE': 519053870425702430,
  33. 'COLOR_PURPLE': 519033808180477952,
  34. 'COLOR_MAUVE': 608084233625272332,
  35. 'COLOR_MAGENTA': 519033938170216458,
  36. 'COLOR_HOT_PINK': 519034420552794122,
  37. 'COLOR_PINK': 519034029907902484,
  38. 'COLOR_PASTEL_PINK': 608087340434325504,
  39. 'COLOR_IVORY': 608086842428096532,
  40. 'COLOR_WHITE': 519034129069899776,
  41. 'COLOR_LIGHT_GRAY': 519036592254615562,
  42. 'COLOR_BLUE_GRAY': 519055342290862080,
  43. 'COLOR_GRAY': 519036758416031745,
  44. 'COLOR_BLACK': 519034171058946048,
  45. 'COLOR_INVISIBLE': 608080962043117588,
  46. 'COLOR_H4K0R': 726069856528498738,
  47. 'PING_ANNOUNCEMENT': 628767206989103134,
  48. 'PING_CULT': 622168721498177587,
  49. 'PING_VC': 765058996775550996,
  50. 'PING_GAMING': 844985862852313131,
  51. 'PRONOUN_HE': 692142321268949073,
  52. 'PRONOUN_SHE': 725562073420922962,
  53. 'PRONOUN_THEY': 692142321072078918,
  54. }
  55. COLOR_ROLES = {
  56. v for (k,v) in ROLES.items()
  57. if k.startswith('COLOR')
  58. and v != 726069856528498738
  59. }
  60. COLORS = [
  61. "Light Red",
  62. "Red",
  63. "Satan Red",
  64. "Deep Orange",
  65. "Orange",
  66. "Brown",
  67. "Piss Yellow",
  68. "Yellow",
  69. "Light Yellow",
  70. "Lime",
  71. "Mint Green",
  72. "Light Green",
  73. "Green",
  74. "Tree Green",
  75. "Aquamarine",
  76. "Teal",
  77. "Cyan",
  78. "Pastel Cyan",
  79. "Light Blue",
  80. "Discord Blue",
  81. "Blue",
  82. "Navy Blue",
  83. "Indigo",
  84. "Deep Purple",
  85. "Mauve",
  86. "Magenta",
  87. "Hot Pink",
  88. "Pink",
  89. "Pastel Pink",
  90. "Ivory",
  91. "White",
  92. "Light Gray",
  93. "Blue Gray",
  94. "Gray",
  95. "Black",
  96. ]
  97. class Roles(Cog):
  98. """Let users choose their roles"""
  99. def __init__(self, bot: discord.Bot):
  100. self.bot: discord.Bot = bot
  101. self.ROLES = ROLES
  102. print("Initialized Roles cog")
  103. @Cog.listener()
  104. async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent):
  105. guild = self.bot.get_guild(payload.guild_id)
  106. member = guild.get_member(payload.user_id)
  107. role = None
  108. if payload.message_id == 952489920184873030: # pronoun roles
  109. match payload.emoji.name:
  110. # 👨 = He/Him
  111. # 👩 = She/Her
  112. # 🧑 = They/Them
  113. case '👨':
  114. role = guild.get_role(ROLES['PRONOUN_HE'])
  115. case '👩':
  116. role = guild.get_role(ROLES['PRONOUN_SHE'])
  117. case '🧑':
  118. role = guild.get_role(ROLES['PRONOUN_THEY'])
  119. if payload.message_id == 952510538552868884: # ping roles
  120. match payload.emoji.name:
  121. # 📢 = Announcement Ping
  122. # 🎞️ = Cult Movie Night
  123. # 🎙️ = VC Ping
  124. # 🎮 = Gaming Ping
  125. case '📢':
  126. role = guild.get_role(ROLES['PING_ANNOUNCEMENT'])
  127. case '🎞️':
  128. role = guild.get_role(ROLES['PING_CULT'])
  129. case '🎙️':
  130. role = guild.get_role(ROLES['PING_VC'])
  131. case '🎮':
  132. role = guild.get_role(ROLES['PING_GAMING'])
  133. if role:
  134. await member.add_roles(role)
  135. @Cog.listener()
  136. async def on_raw_reaction_remove(self, payload: discord.RawReactionActionEvent):
  137. guild = self.bot.get_guild(payload.guild_id)
  138. member = guild.get_member(payload.user_id)
  139. role = None
  140. if payload.message_id == 952489920184873030: # pronoun roles
  141. match payload.emoji.name:
  142. # 👨 = He/Him
  143. # 👩 = She/Her
  144. # 🧑 = They/Them
  145. case '👨':
  146. role = guild.get_role(ROLES['PRONOUN_HE'])
  147. case '👩':
  148. role = guild.get_role(ROLES['PRONOUN_SHE'])
  149. case '🧑':
  150. role = guild.get_role(ROLES['PRONOUN_THEY'])
  151. case _:
  152. role = None
  153. if payload.message_id == 952510538552868884: # ping roles
  154. match payload.emoji.name:
  155. # 📢 = Announcement Ping
  156. # 🎞️ = Cult Movie Night
  157. # 🎙️ = VC Ping
  158. # 🎮 = Gaming Ping
  159. case '📢':
  160. role = guild.get_role(ROLES['PING_ANNOUNCEMENT'])
  161. case '🎞️':
  162. role = guild.get_role(ROLES['PING_CULT'])
  163. case '🎙️':
  164. role = guild.get_role(ROLES['PING_VC'])
  165. case '🎮':
  166. role = guild.get_role(ROLES['PING_GAMING'])
  167. if role:
  168. await member.remove_roles(role)
  169. async def get_colors(self, ctx: discord.AutocompleteContext) -> list[str]:
  170. """Returns a list of colors matching the partial input"""
  171. return [
  172. color
  173. for color in COLORS
  174. if color.lower().startswith( ctx.value.lower() )
  175. ]
  176. @slash_command(
  177. description="Choose the color of your display name",
  178. guild_ids=[GUILD]
  179. )
  180. async def color(
  181. self,
  182. ctx: discord.ApplicationContext,
  183. name: Option(str, "Color name", autocomplete=get_colors)
  184. ):
  185. """Choose the color of your display name"""
  186. color: str = "COLOR_" + name.replace(" ", "_").upper()
  187. if ROLES[color] == 726069856528498738:
  188. new_color_role = ctx.guild.get_role(ROLES[color])
  189. await ctx.interaction.user.add_roles(new_color_role)
  190. return await ctx.respond(f"You should now have the {name} role.", ephemeral=True)
  191. try:
  192. new_color_role = ctx.guild.get_role(ROLES[color])
  193. all_current_roles = ctx.interaction.user.roles
  194. old_color_roles = []
  195. for role in all_current_roles:
  196. if role.id in COLOR_ROLES:
  197. old_color_roles.append(role)
  198. if old_color_roles:
  199. await ctx.interaction.user.remove_roles(*old_color_roles)
  200. await ctx.interaction.user.add_roles(new_color_role)
  201. except KeyError:
  202. return await ctx.respond("Please provide a valid color name.", ephemeral=True)
  203. await ctx.respond(f"You should now have the {name} role.", ephemeral=True)