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.

103 lines
4.4KB

  1. # -*- coding: utf-8 -*-
  2. # MIT License
  3. #
  4. # Copyright (c) 2017-2018 Roxanne Gibson
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the "Software"), to deal
  8. # in the Software without restriction, including without limitation the rights
  9. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. # copies of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be included in all
  14. # copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. # SOFTWARE.
  23. import datetime
  24. import discord
  25. from discord.ext import commands
  26. import roxbot
  27. class AssortedGenderSounds(commands.Cog):
  28. """Custom Cog for the AssortedGenderSounds Discord Server."""
  29. def __init__(self, bot_client):
  30. self.bot = bot_client
  31. self.required_score = 2000
  32. self.days = 5
  33. self.logging_channel_id = 394959819796381697
  34. self.newbie_role_id = 450042170112475136
  35. self.selfie_role_id = 394939389823811584
  36. self.ags_id = 393764974444675073
  37. self.tat_token = roxbot.config["Tokens"]["Tatsumaki"]
  38. self.bot.add_listener(self.grab_objects, "on_ready")
  39. self.ags = None
  40. self.selfie_role = None
  41. self.newbie_role = None
  42. self.logging_channel = None
  43. async def cog_check(self, ctx):
  44. return ctx.guild.id == self.ags_id
  45. async def grab_objects(self):
  46. self.ags = self.bot.get_guild(self.ags_id)
  47. self.selfie_role = self.ags.get_role(self.selfie_role_id)
  48. self.newbie_role = self.ags.get_role(self.newbie_role_id)
  49. self.logging_channel = self.ags.get_channel(self.logging_channel_id)
  50. @commands.Cog.listener()
  51. async def on_member_join(self, member):
  52. if member.guild == self.ags:
  53. await member.add_roles(self.newbie_role, reason="Auto-add role on join")
  54. await member.send("Please read our <#396697172139180033> and <#422514427263188993> channels. To gain access to the server, you must agree to the rules.")
  55. async def tatsumaki_api_call(self, member, guild):
  56. base = "https://api.tatsumaki.xyz/"
  57. url = base + "guilds/" + str(guild.id) + "/members/" + str(member.id) + "/stats"
  58. return await roxbot.http.api_request(url, headers={"Authorization": self.tat_token})
  59. @commands.command()
  60. async def agree(self, ctx):
  61. try:
  62. return await ctx.author.remove_roles(self.newbie_role, reason="User has agreed the rules and has been given access to the server.")
  63. except discord.HTTPException:
  64. pass
  65. @commands.command(name="selfieperms")
  66. async def selfie_perms(self, ctx):
  67. """Requests the selfie perm role."""
  68. member = ctx.author
  69. data = await self.tatsumaki_api_call(member, ctx.guild)
  70. if data is None:
  71. return await ctx.send("Tatsumaki API call returned nothing. Maybe the API is down?")
  72. if self.selfie_role in member.roles:
  73. await member.remove_roles(self.selfie_role, reason="Requested removal of {0.name}".format(self.selfie_role))
  74. return await ctx.send("You already had {0.name}. It has now been removed.".format(self.selfie_role))
  75. time = datetime.datetime.now() - ctx.author.joined_at
  76. if time > datetime.timedelta(days=self.days) and int(data["score"]) >= self.required_score:
  77. await member.add_roles(self.selfie_role, reason="Requested {0.name}".format(self.selfie_role))
  78. await ctx.send("You now have the {0.name} role".format(self.selfie_role))
  79. else:
  80. return await ctx.send(
  81. "You do not meet the requirements for this role. You need at least {} score with <@!172002275412279296> and to have been in the server for {} days.".format(self.required_score, self.days)
  82. )
  83. def setup(bot_client):
  84. bot_client.add_cog(AssortedGenderSounds(bot_client))