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.

80 lines
2.8KB

  1. import datetime
  2. import requests
  3. from Roxbot import load_config
  4. import discord
  5. from discord.ext import commands
  6. from discord.ext.commands import bot
  7. from Roxbot.settings import guild_settings
  8. from json import JSONDecodeError
  9. def is_gss():
  10. return commands.check(lambda ctx: ctx.guild.id == 393764974444675073)
  11. def is_not_nsfw_disabled():
  12. def predicate(ctx):
  13. role = discord.utils.get(ctx.guild.roles, id=397866388145831937)
  14. return role not in ctx.author.roles
  15. return commands.check(lambda ctx: predicate(ctx))
  16. class GaySoundsShitposting():
  17. def __init__(self, bot_client):
  18. self.bot = bot_client
  19. self.acceptable_roles = [394939389823811584, 394941004043649036]
  20. def tatsumaki_api_call(self, member, guild):
  21. base = "https://api.tatsumaki.xyz/"
  22. url = base + "guilds/" + str(guild.id) + "/members/" + str(member.id) + "/stats"
  23. r = requests.get(url, headers={"Authorization": load_config.tat_token})
  24. try:
  25. return r.json()
  26. except JSONDecodeError:
  27. return False
  28. @bot.command(hidden=True)
  29. async def perms(self, ctx, *, role: discord.Role):
  30. """Shell command to do the perm assigning. Only should be invoked by another command."""
  31. # Just in case some cunt looks at the source code and thinks they can give themselves Admin.
  32. if role.id not in self.acceptable_roles:
  33. print("lol no")
  34. return False
  35. settings = guild_settings.get(ctx.guild)
  36. member = ctx.author
  37. required_score = settings.gss["required_score"]
  38. days = int(settings.gss["required_days"])
  39. data = self.tatsumaki_api_call(member, ctx.guild)
  40. if not data:
  41. return await ctx.send("Tatsumaki API call returned nothing. Maybe the API is down?")
  42. if role in member.roles:
  43. await member.remove_roles(role, reason="Requested removal of {0.name}".format(role))
  44. return await ctx.send("You already had {0.name}. It has now been removed.".format(role))
  45. time = datetime.datetime.now() - ctx.author.joined_at
  46. if time > datetime.timedelta(days=days) and int(data["score"]) >= required_score:
  47. await member.add_roles(member, role, reason="Requested {0.name}".format(role))
  48. await ctx.send("You have now have the {0.name} role".format(role))
  49. else:
  50. return await ctx.send(
  51. "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(required_score, days)
  52. )
  53. @is_gss()
  54. @bot.command()
  55. async def selfieperms(self, ctx):
  56. """Requests the selfie perm role."""
  57. role = 394939389823811584
  58. return await ctx.invoke(self.perms, role=role)
  59. @is_not_nsfw_disabled()
  60. @is_gss()
  61. @bot.command()
  62. async def nsfwperms(self, ctx):
  63. """Requests the NSFW Image Perm role."""
  64. role = 394941004043649036
  65. return await ctx.invoke(self.perms, role=role)
  66. def setup(bot_client):
  67. bot_client.add_cog(GaySoundsShitposting(bot_client))