Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- import json
- from discord.utils import get
- class Lockdown:
- """USE WITH CAUSION THIS __WILL__ OVERWRITE ALL PERMISSIONS OF A CHANNEL"""
- def __init__(self, bot):
- self.bot = bot
- self.states = {}
- @commands.has_permissions(manage_channels=True)
- @commands.command(pass_context=True, name="lockdown")
- async def lockdown(self, ctx):
- """USE WITH CAUSION THIS WILL OVERWRITE ALL PERMISSIONS OF A CHANNEL."""
- try:
- try:
- mod_strings = load_moderation()
- mod_role_strings = mod_strings[ctx.message.guild.name]
- mod_roles = []
- for m in mod_role_strings:
- mod_roles.append(discord.utils.get(ctx.message.guild.roles, name=m))
- except:
- admin = get(ctx.message.author.guild.roles, name="Moderator")
- mod = get(ctx.message.author.guild.roles, name="Admin")
- bootl = get(ctx.message.author.guild.roles, name="Bootlagator")
- RTBOT = get(ctx.message.author.guild.roles, name="RT-Bot")
- SUPER = get(ctx.message.author.guild.roles, name="Supervisor")
- mod_roles = [ctx.message.author, admin, mod, bootl, RTBOT, SUPER]
- server = ctx.message.guild
- overwrites_everyone = ctx.message.channel.overwrites_for(server.default_role)
- overwrites_owner = ctx.message.channel.overwrites_for(server.role_hierarchy[0])
- if ctx.message.channel.id in self.states:
- await ctx.send("🔒 Channel is already locked down. Use `unlock` to unlock.")
- return
- states = []
- for a in ctx.message.guild.role_hierarchy:
- states.append([a, ctx.message.channel.overwrites_for(a).send_messages])
- self.states[ctx.message.channel.id] = states
- overwrites_owner.send_messages = True
- overwrites_everyone.send_messages = False
- await ctx.message.channel.set_permissions(server.default_role, overwrite=overwrites_everyone)
- for modrole in mod_roles:
- await ctx.message.channel.set_permissions(modrole, overwrite=overwrites_owner)
- await ctx.send(
- "🔒 Channel locked down. Only roles with permissions specified in `moderation.json` can speak.")
- except discord.errors.Forbidden:
- await ctx.send(self.bot.bot_prefix + "Missing permissions.")
- @commands.has_permissions(manage_channels=True)
- @commands.command(pass_context=True, name="unlock")
- async def unlock(self, ctx):
- """Unlock message sending in the channel."""
- try:
- if not ctx.message.channel.id in self.states:
- await ctx.send("🔓 Channel is already unlocked.")
- return
- for a in self.states[ctx.message.channel.id]:
- overwrites_a = ctx.message.channel.overwrites_for(a[0])
- overwrites_a.send_messages = a[1]
- await ctx.message.channel.set_permissions(a[0], overwrite=overwrites_a)
- self.states.pop(ctx.message.channel.id)
- await ctx.send("🔓 Channel unlocked.")
- except discord.errors.Forbidden:
- await ctx.send(self.bot.bot_prefix + "Missing permissions.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement