From bc85174a51f2d7d4b4d3060f264deb7ed04f1646 Mon Sep 17 00:00:00 2001 From: Ave Ozkal Date: Sun, 23 Dec 2018 23:33:03 +0300 Subject: [PATCH] lockdown: Add lockdown --- README.md | 4 +-- Robocop.py | 1 + cogs/legacy.py | 8 +++++ cogs/lockdown.py | 79 ++++++++++++++++++++++++++++++++++-------------- 4 files changed, 68 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 7b5f3f8..eaf375a 100755 --- a/README.md +++ b/README.md @@ -26,10 +26,10 @@ Based on https://gitlab.com/ao/dpybotbase - [x] Moderation: approve-revoke (community) - [x] Moderation: addhacker-removehacker (hacker) - [x] Moderation: probate-unprobate (participant) -- [ ] Moderation: lock-soft-unlock (channel lockdown) +- [x] Moderation: lock-softlock-unlock (channel lockdown) - [ ] Moderation: timelock (channel lockdown with time) - [ ] Moderation: mute-unmute -- [ ] Moderation: mutetime +- [ ] Moderation: mutetime (mute with time) - [x] Moderation: playing - [x] Moderation: botnickname - [x] Moderation: nickname diff --git a/Robocop.py b/Robocop.py index 3d0ea84..7a54600 100755 --- a/Robocop.py +++ b/Robocop.py @@ -43,6 +43,7 @@ initial_extensions = ['cogs.common', 'cogs.err', 'cogs.verification', 'cogs.logs', + 'cogs.lockdown', 'cogs.legacy', 'cogs.links', 'cogs.mod', diff --git a/cogs/legacy.py b/cogs/legacy.py index d047dd0..d18973d 100644 --- a/cogs/legacy.py +++ b/cogs/legacy.py @@ -11,6 +11,14 @@ class Legacy: await ctx.send("This command was replaced with `.revoke `" " on Robocop-NG, please use that instead.") + @commands.command(hidden=True) + async def softlock(self, ctx): + """Use .lock True""" + await ctx.send("This command was replaced with `.lock True`" + " on Robocop-NG, please use that instead.\n" + "Also... good luck, and sorry for taking your time. " + "Lockdown rarely means anything good.") + @commands.command(hidden=True, aliases=["addhacker"]) async def unprobate(self, ctx): """Use .approve """ diff --git a/cogs/lockdown.py b/cogs/lockdown.py index 15311fd..02c4f2b 100644 --- a/cogs/lockdown.py +++ b/cogs/lockdown.py @@ -1,33 +1,68 @@ -import discord -import asyncio from discord.ext import commands -from config import log_channel, staff_role_ids, named_roles, community_channels, general_channels +import config class Lockdown: - "Lockdown Commands" - def __init__(self, bot): self.bot = bot - @commands.has_permissions(manage_messages=True) - @commands.command(pass_context=True) - async def lock(self, ctx): - """Locks the channel""" - log_chan = self.bot.get_channel(log_channel) - if ctx.message.channel in community_channels: - roles = (named_roles["hacker"], named_roles["community"]) + def check_if_staff(ctx): + return any(r.id in config.staff_role_ids for r in ctx.author.roles) + + @commands.guild_only() + @commands.check(check_if_staff) + @commands.command() + async def lock(self, ctx, soft: bool = False): + """Prevents people from speaking in current channel, staff only.""" + log_channel = self.bot.get_channel(config.log_channel) + + if ctx.channel.id in config.community_channels: + roles = [config.named_roles["community"], + config.named_roles["hacker"]] else: - roles = named_roles["participant"] - overwrites = ctx.message.channel.overwrites_for(roles[0]) - if not overwrites.send_message: - await ctx.send("This channel is already locked!") - return - overwrites.send_message = False - overwrites.add_reactions = False - await asyncio.gather(*(self.bot.edit_channel_permissions(ctx.channel, role, overwrites) for role in roles)) - await ctx.send("🔒 Channel locked down. Only staff members may speak. Do not bring the topic to other channels or risk disciplinary actions.") - await log_chan.send(f"Channel Lockdown for {ctx.channel.mention} by {ctx.author.mention}") + roles = [config.named_roles["participant"], + ctx.guild.default_role.id] + + for role in roles: + await ctx.channel.set_permissions(ctx.guild.get_role(role), + send_messages=False, + reason=str(ctx.author)) + + public_msg = "🔒 Channel locked down. " + if not soft: + public_msg += "Only staff members may speak. "\ + "Do not bring the topic to other channels or risk "\ + "disciplinary actions." + + await ctx.send(public_msg) + msg = f"🔒 **Lockdown**: {ctx.channel.mention} by {ctx.author.mention} "\ + f"| {self.bot.escape_message(ctx.author)}" + # ":unlock: Channel unlocked." + await log_channel.send(msg) + + @commands.guild_only() + @commands.check(check_if_staff) + @commands.command() + async def unlock(self, ctx): + """Unlocks speaking in current channel, staff only.""" + log_channel = self.bot.get_channel(config.log_channel) + + if ctx.channel.id in config.community_channels: + roles = [config.named_roles["community"], + config.named_roles["hacker"]] + else: + roles = [config.named_roles["participant"], + ctx.guild.default_role.id] + + for role in roles: + await ctx.channel.set_permissions(ctx.guild.get_role(role), + send_messages=True, + reason=str(ctx.author)) + + await ctx.send("🔓 Channel unlocked.") + msg = f"🔓 **Unlock**: {ctx.channel.mention} by {ctx.author.mention} "\ + f"| {self.bot.escape_message(ctx.author)}" + await log_channel.send(msg) def setup(bot):