lockdown: reduce code repetition
This commit is contained in:
parent
f2e210b9e3
commit
807dd882af
1 changed files with 15 additions and 21 deletions
|
@ -8,18 +8,22 @@ class Lockdown:
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
async def unlock_for_staff(self, channel: discord.TextChannel, issuer):
|
async def set_sendmessgae(self, channel: discord.TextChannel,
|
||||||
for role in config.staff_role_ids:
|
role, allow_send, issuer):
|
||||||
try:
|
try:
|
||||||
roleobj = channel.guild.get_role(role)
|
roleobj = channel.guild.get_role(role)
|
||||||
overrides = channel.overwrites_for(roleobj)
|
overrides = channel.overwrites_for(roleobj)
|
||||||
overrides.send_messages = True
|
overrides.send_messages = allow_send
|
||||||
await channel.set_permissions(roleobj,
|
await channel.set_permissions(roleobj,
|
||||||
overwrite=overrides,
|
overwrite=overrides,
|
||||||
reason=str(issuer))
|
reason=str(issuer))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
async def unlock_for_staff(self, channel: discord.TextChannel, issuer):
|
||||||
|
for role in config.staff_role_ids:
|
||||||
|
await self.set_sendmessage(channel, role, True, issuer)
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@commands.check(check_if_staff)
|
@commands.check(check_if_staff)
|
||||||
@commands.command()
|
@commands.command()
|
||||||
|
@ -39,12 +43,7 @@ class Lockdown:
|
||||||
roles = [config.named_roles["participant"]]
|
roles = [config.named_roles["participant"]]
|
||||||
|
|
||||||
for role in roles:
|
for role in roles:
|
||||||
roleobj = channel.guild.get_role(role)
|
await self.set_sendmessage(channel, role, False, ctx.author)
|
||||||
overrides = channel.overwrites_for(roleobj)
|
|
||||||
overrides.send_messages = False
|
|
||||||
await channel.set_permissions(roleobj,
|
|
||||||
overwrite=overrides,
|
|
||||||
reason=str(ctx.author))
|
|
||||||
|
|
||||||
await self.unlock_for_staff(channel, ctx.author)
|
await self.unlock_for_staff(channel, ctx.author)
|
||||||
|
|
||||||
|
@ -78,12 +77,7 @@ class Lockdown:
|
||||||
await self.unlock_for_staff(channel, ctx.author)
|
await self.unlock_for_staff(channel, ctx.author)
|
||||||
|
|
||||||
for role in roles:
|
for role in roles:
|
||||||
roleobj = channel.guild.get_role(role)
|
await self.set_sendmessage(channel, role, True, ctx.author)
|
||||||
overrides = channel.overwrites_for(roleobj)
|
|
||||||
overrides.send_messages = True
|
|
||||||
await channel.set_permissions(roleobj,
|
|
||||||
overwrite=overrides,
|
|
||||||
reason=str(ctx.author))
|
|
||||||
|
|
||||||
safe_name = await commands.clean_content().convert(ctx, str(ctx.author))
|
safe_name = await commands.clean_content().convert(ctx, str(ctx.author))
|
||||||
await ctx.send("🔓 Channel unlocked.")
|
await ctx.send("🔓 Channel unlocked.")
|
||||||
|
|
Loading…
Reference in a new issue