2023-03-09 23:01:10 +01:00
|
|
|
import discord
|
2018-12-23 20:06:32 +01:00
|
|
|
from discord.ext import commands
|
2019-02-28 23:10:30 +01:00
|
|
|
from discord.ext.commands import Cog
|
2023-03-09 23:01:10 +01:00
|
|
|
|
|
|
|
from robocop_ng.helpers.checks import check_if_staff
|
2018-12-23 20:06:32 +01:00
|
|
|
|
2020-04-21 01:05:32 +03:00
|
|
|
|
2019-02-28 23:10:30 +01:00
|
|
|
class Lockdown(Cog):
|
2018-12-23 20:06:32 +01:00
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
|
2020-04-21 01:05:32 +03:00
|
|
|
async def set_sendmessage(
|
|
|
|
self, channel: discord.TextChannel, role, allow_send, issuer
|
|
|
|
):
|
2019-02-21 01:20:03 +03:00
|
|
|
try:
|
|
|
|
roleobj = channel.guild.get_role(role)
|
|
|
|
overrides = channel.overwrites_for(roleobj)
|
|
|
|
overrides.send_messages = allow_send
|
2020-04-21 01:05:32 +03:00
|
|
|
await channel.set_permissions(
|
|
|
|
roleobj, overwrite=overrides, reason=str(issuer)
|
|
|
|
)
|
2019-02-21 01:20:03 +03:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2018-12-28 00:36:18 +03:00
|
|
|
async def unlock_for_staff(self, channel: discord.TextChannel, issuer):
|
2023-04-05 12:10:18 +02:00
|
|
|
for role in self.bot.config.staff_role_ids:
|
2019-02-21 01:20:03 +03:00
|
|
|
await self.set_sendmessage(channel, role, True, issuer)
|
2018-12-28 00:36:18 +03:00
|
|
|
|
2018-12-23 23:33:03 +03:00
|
|
|
@commands.guild_only()
|
|
|
|
@commands.check(check_if_staff)
|
|
|
|
@commands.command()
|
2020-04-21 01:05:32 +03:00
|
|
|
async def lock(self, ctx, channel: discord.TextChannel = None, soft: bool = False):
|
2018-12-28 00:36:18 +03:00
|
|
|
"""Prevents people from speaking in a channel, staff only.
|
|
|
|
|
|
|
|
Defaults to current channel."""
|
2018-12-24 03:26:25 +03:00
|
|
|
if not channel:
|
|
|
|
channel = ctx.channel
|
2023-04-05 12:10:18 +02:00
|
|
|
log_channel = self.bot.get_channel(self.bot.config.modlog_channel)
|
2018-12-23 23:33:03 +03:00
|
|
|
|
2021-01-08 23:37:37 +01:00
|
|
|
roles = None
|
2023-04-05 12:10:18 +02:00
|
|
|
for key, lockdown_conf in self.bot.config.lockdown_configs.items():
|
2019-03-01 07:07:47 +01:00
|
|
|
if channel.id in lockdown_conf["channels"]:
|
|
|
|
roles = lockdown_conf["roles"]
|
|
|
|
|
|
|
|
if roles is None:
|
2023-04-05 12:10:18 +02:00
|
|
|
roles = self.bot.config.lockdown_configs["default"]["roles"]
|
2018-12-23 23:33:03 +03:00
|
|
|
|
|
|
|
for role in roles:
|
2019-02-21 01:20:03 +03:00
|
|
|
await self.set_sendmessage(channel, role, False, ctx.author)
|
2018-12-28 00:36:18 +03:00
|
|
|
|
|
|
|
await self.unlock_for_staff(channel, ctx.author)
|
2018-12-23 23:33:03 +03:00
|
|
|
|
|
|
|
public_msg = "🔒 Channel locked down. "
|
|
|
|
if not soft:
|
2020-04-21 01:05:32 +03:00
|
|
|
public_msg += (
|
|
|
|
"Only staff members may speak. "
|
|
|
|
"Do not bring the topic to other channels or risk "
|
|
|
|
"disciplinary actions."
|
|
|
|
)
|
2018-12-23 23:33:03 +03:00
|
|
|
|
|
|
|
await ctx.send(public_msg)
|
2020-10-01 20:03:41 -04:00
|
|
|
safe_name = await commands.clean_content(escape_markdown=True).convert(
|
|
|
|
ctx, str(ctx.author)
|
|
|
|
)
|
2020-04-21 01:05:32 +03:00
|
|
|
msg = (
|
|
|
|
f"🔒 **Lockdown**: {ctx.channel.mention} by {ctx.author.mention} "
|
|
|
|
f"| {safe_name}"
|
|
|
|
)
|
2018-12-23 23:33:03 +03:00
|
|
|
await log_channel.send(msg)
|
|
|
|
|
|
|
|
@commands.guild_only()
|
|
|
|
@commands.check(check_if_staff)
|
|
|
|
@commands.command()
|
2018-12-24 03:26:25 +03:00
|
|
|
async def unlock(self, ctx, channel: discord.TextChannel = None):
|
2018-12-23 23:33:03 +03:00
|
|
|
"""Unlocks speaking in current channel, staff only."""
|
2018-12-24 03:26:25 +03:00
|
|
|
if not channel:
|
|
|
|
channel = ctx.channel
|
2023-04-05 12:10:18 +02:00
|
|
|
log_channel = self.bot.get_channel(self.bot.config.modlog_channel)
|
2018-12-23 23:33:03 +03:00
|
|
|
|
2021-01-08 23:37:37 +01:00
|
|
|
roles = None
|
2023-04-05 12:10:18 +02:00
|
|
|
for key, lockdown_conf in self.bot.config.lockdown_configs.items():
|
2019-03-01 07:07:47 +01:00
|
|
|
if channel.id in lockdown_conf["channels"]:
|
|
|
|
roles = lockdown_conf["roles"]
|
|
|
|
|
|
|
|
if roles is None:
|
2023-04-05 12:10:18 +02:00
|
|
|
roles = self.bot.config.lockdown_configs["default"]["roles"]
|
2018-12-23 23:33:03 +03:00
|
|
|
|
2018-12-28 00:36:18 +03:00
|
|
|
await self.unlock_for_staff(channel, ctx.author)
|
|
|
|
|
2018-12-23 23:33:03 +03:00
|
|
|
for role in roles:
|
2019-02-21 01:20:03 +03:00
|
|
|
await self.set_sendmessage(channel, role, True, ctx.author)
|
2018-12-23 23:33:03 +03:00
|
|
|
|
2020-10-01 20:03:41 -04:00
|
|
|
safe_name = await commands.clean_content(escape_markdown=True).convert(
|
|
|
|
ctx, str(ctx.author)
|
|
|
|
)
|
2018-12-23 23:33:03 +03:00
|
|
|
await ctx.send("🔓 Channel unlocked.")
|
2020-04-21 01:05:32 +03:00
|
|
|
msg = (
|
|
|
|
f"🔓 **Unlock**: {ctx.channel.mention} by {ctx.author.mention} "
|
|
|
|
f"| {safe_name}"
|
|
|
|
)
|
2018-12-23 23:33:03 +03:00
|
|
|
await log_channel.send(msg)
|
2018-12-23 22:15:44 +03:00
|
|
|
|
2018-12-23 20:08:34 +01:00
|
|
|
|
2022-05-24 20:35:42 +02:00
|
|
|
async def setup(bot):
|
|
|
|
await bot.add_cog(Lockdown(bot))
|