Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3. import json
  4. from discord.utils import get
  5. class Lockdown:
  6. """USE WITH CAUSION THIS __WILL__ OVERWRITE ALL PERMISSIONS OF A CHANNEL"""
  7.  
  8. def __init__(self, bot):
  9. self.bot = bot
  10. self.states = {}
  11.  
  12. @commands.has_permissions(manage_channels=True)
  13. @commands.command(pass_context=True, name="lockdown")
  14. async def lockdown(self, ctx):
  15. """USE WITH CAUSION THIS WILL OVERWRITE ALL PERMISSIONS OF A CHANNEL."""
  16. try:
  17. try:
  18. mod_strings = load_moderation()
  19. mod_role_strings = mod_strings[ctx.message.guild.name]
  20. mod_roles = []
  21. for m in mod_role_strings:
  22. mod_roles.append(discord.utils.get(ctx.message.guild.roles, name=m))
  23. except:
  24. admin = get(ctx.message.author.guild.roles, name="Moderator")
  25. mod = get(ctx.message.author.guild.roles, name="Admin")
  26. bootl = get(ctx.message.author.guild.roles, name="Bootlagator")
  27. RTBOT = get(ctx.message.author.guild.roles, name="RT-Bot")
  28. SUPER = get(ctx.message.author.guild.roles, name="Supervisor")
  29. mod_roles = [ctx.message.author, admin, mod, bootl, RTBOT, SUPER]
  30. server = ctx.message.guild
  31. overwrites_everyone = ctx.message.channel.overwrites_for(server.default_role)
  32. overwrites_owner = ctx.message.channel.overwrites_for(server.role_hierarchy[0])
  33. if ctx.message.channel.id in self.states:
  34. await ctx.send("🔒 Channel is already locked down. Use `unlock` to unlock.")
  35. return
  36. states = []
  37. for a in ctx.message.guild.role_hierarchy:
  38. states.append([a, ctx.message.channel.overwrites_for(a).send_messages])
  39. self.states[ctx.message.channel.id] = states
  40. overwrites_owner.send_messages = True
  41. overwrites_everyone.send_messages = False
  42. await ctx.message.channel.set_permissions(server.default_role, overwrite=overwrites_everyone)
  43. for modrole in mod_roles:
  44. await ctx.message.channel.set_permissions(modrole, overwrite=overwrites_owner)
  45. await ctx.send(
  46. "🔒 Channel locked down. Only roles with permissions specified in `moderation.json` can speak.")
  47. except discord.errors.Forbidden:
  48. await ctx.send(self.bot.bot_prefix + "Missing permissions.")
  49.  
  50. @commands.has_permissions(manage_channels=True)
  51. @commands.command(pass_context=True, name="unlock")
  52. async def unlock(self, ctx):
  53. """Unlock message sending in the channel."""
  54. try:
  55. if not ctx.message.channel.id in self.states:
  56. await ctx.send("🔓 Channel is already unlocked.")
  57. return
  58. for a in self.states[ctx.message.channel.id]:
  59. overwrites_a = ctx.message.channel.overwrites_for(a[0])
  60. overwrites_a.send_messages = a[1]
  61. await ctx.message.channel.set_permissions(a[0], overwrite=overwrites_a)
  62. self.states.pop(ctx.message.channel.id)
  63. await ctx.send("🔓 Channel unlocked.")
  64. except discord.errors.Forbidden:
  65. await ctx.send(self.bot.bot_prefix + "Missing permissions.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement