2018-12-23 19:06:32 +00:00
|
|
|
from discord.ext import commands
|
2018-12-23 20:33:03 +00:00
|
|
|
import config
|
2018-12-24 00:26:25 +00:00
|
|
|
import discord
|
2018-12-26 11:36:55 +00:00
|
|
|
from helpers.checks import check_if_staff
|
2018-12-23 19:06:32 +00:00
|
|
|
|
2018-12-23 19:15:44 +00:00
|
|
|
|
2018-12-23 19:06:32 +00:00
|
|
|
class Lockdown:
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
|
2018-12-27 21:36:18 +00:00
|
|
|
async def unlock_for_staff(self, channel: discord.TextChannel, issuer):
|
|
|
|
for role in config.staff_role_ids:
|
|
|
|
try:
|
|
|
|
await channel.set_permissions(channel.guild.get_role(role),
|
2019-01-07 08:54:13 +00:00
|
|
|
send_messages=True,
|
2018-12-27 21:36:18 +00:00
|
|
|
reason=str(issuer))
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2018-12-23 20:33:03 +00:00
|
|
|
@commands.guild_only()
|
|
|
|
@commands.check(check_if_staff)
|
|
|
|
@commands.command()
|
2018-12-24 00:26:25 +00:00
|
|
|
async def lock(self, ctx, channel: discord.TextChannel = None,
|
|
|
|
soft: bool = False):
|
2018-12-27 21:36:18 +00:00
|
|
|
"""Prevents people from speaking in a channel, staff only.
|
|
|
|
|
|
|
|
Defaults to current channel."""
|
2018-12-24 00:26:25 +00:00
|
|
|
if not channel:
|
|
|
|
channel = ctx.channel
|
2018-12-23 20:33:03 +00:00
|
|
|
log_channel = self.bot.get_channel(config.log_channel)
|
|
|
|
|
2018-12-27 21:36:18 +00:00
|
|
|
if channel.id in config.community_channels:
|
2018-12-23 20:33:03 +00:00
|
|
|
roles = [config.named_roles["community"],
|
|
|
|
config.named_roles["hacker"]]
|
2018-12-23 19:06:32 +00:00
|
|
|
else:
|
2018-12-23 20:33:03 +00:00
|
|
|
roles = [config.named_roles["participant"],
|
|
|
|
ctx.guild.default_role.id]
|
|
|
|
|
|
|
|
for role in roles:
|
2018-12-27 21:36:18 +00:00
|
|
|
await channel.set_permissions(channel.guild.get_role(role),
|
|
|
|
send_messages=False,
|
|
|
|
reason=str(ctx.author))
|
|
|
|
|
|
|
|
await self.unlock_for_staff(channel, ctx.author)
|
2018-12-23 20:33:03 +00:00
|
|
|
|
|
|
|
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)
|
2019-01-07 08:49:19 +00:00
|
|
|
safe_name = await commands.clean_content().convert(ctx, str(ctx.author))
|
2018-12-23 20:33:03 +00:00
|
|
|
msg = f"🔒 **Lockdown**: {ctx.channel.mention} by {ctx.author.mention} "\
|
2019-01-07 08:49:19 +00:00
|
|
|
f"| {safe_name}"
|
2018-12-23 20:33:03 +00:00
|
|
|
await log_channel.send(msg)
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.check(check_if_staff)
|
|
|
|
@commands.command()
|
2018-12-24 00:26:25 +00:00
|
|
|
async def unlock(self, ctx, channel: discord.TextChannel = None):
|
2018-12-23 20:33:03 +00:00
|
|
|
"""Unlocks speaking in current channel, staff only."""
|
2018-12-24 00:26:25 +00:00
|
|
|
if not channel:
|
|
|
|
channel = ctx.channel
|
2018-12-23 20:33:03 +00:00
|
|
|
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]
|
|
|
|
|
2018-12-27 21:36:18 +00:00
|
|
|
await self.unlock_for_staff(channel, ctx.author)
|
|
|
|
|
2018-12-23 20:33:03 +00:00
|
|
|
for role in roles:
|
|
|
|
await ctx.channel.set_permissions(ctx.guild.get_role(role),
|
|
|
|
send_messages=True,
|
|
|
|
reason=str(ctx.author))
|
|
|
|
|
2019-01-07 08:49:19 +00:00
|
|
|
safe_name = await commands.clean_content().convert(ctx, str(ctx.author))
|
2018-12-23 20:33:03 +00:00
|
|
|
await ctx.send("🔓 Channel unlocked.")
|
|
|
|
msg = f"🔓 **Unlock**: {ctx.channel.mention} by {ctx.author.mention} "\
|
2019-01-07 08:49:19 +00:00
|
|
|
f"| {safe_name}"
|
2018-12-23 20:33:03 +00:00
|
|
|
await log_channel.send(msg)
|
2018-12-23 19:15:44 +00:00
|
|
|
|
2018-12-23 19:08:34 +00:00
|
|
|
|
2018-12-23 19:06:32 +00:00
|
|
|
def setup(bot):
|
2018-12-23 19:15:44 +00:00
|
|
|
bot.add_cog(Lockdown(bot))
|