jarvis-bot/jarvis/cogs/admin/lock.py

113 lines
4 KiB
Python

"""J.A.R.V.I.S. LockCog."""
from dis_snek import Scale
# TODO: Uncomment 99% of code once implementation is figured out
# from contextlib import suppress
# from typing import Union
#
# from dis_snek import InteractionContext, Scale, Snake
# from dis_snek.models.discord.enums import Permissions
# from dis_snek.models.discord.role import Role
# from dis_snek.models.discord.user import User
# from dis_snek.models.discord.channel import GuildText, GuildVoice, PermissionOverwrite
# from dis_snek.models.snek.application_commands import (
# OptionTypes,
# PermissionTypes,
# slash_command,
# slash_option,
# )
# from dis_snek.models.snek.command import check
#
# from jarvis.db.models import Lock
# from jarvis.utils.permissions import admin_or_permissions
class LockCog(Scale):
"""J.A.R.V.I.S. LockCog."""
# @slash_command(name="lock", description="Lock a channel")
# @slash_option(name="reason",
# description="Lock Reason",
# opt_type=3,
# required=True,)
# @slash_option(name="duration",
# description="Lock duration in minutes (default 10)",
# opt_type=4,
# required=False,)
# @slash_option(name="channel",
# description="Channel to lock",
# opt_type=7,
# required=False,)
# @check(admin_or_permissions(Permissions.MANAGE_CHANNELS))
# async def _lock(
# self,
# ctx: InteractionContext,
# reason: str,
# duration: int = 10,
# channel: Union[GuildText, GuildVoice] = None,
# ) -> None:
# await ctx.defer(ephemeral=True)
# if duration <= 0:
# await ctx.send("Duration must be > 0", ephemeral=True)
# return
#
# elif duration > 60 * 12:
# await ctx.send("Duration must be <= 12 hours", ephemeral=True)
# return
#
# if len(reason) > 100:
# await ctx.send("Reason must be <= 100 characters", ephemeral=True)
# return
# if not channel:
# channel = ctx.channel
#
# # role = ctx.guild.default_role # Uncomment once implemented
# if isinstance(channel, GuildText):
# to_deny = Permissions.SEND_MESSAGES
# elif isinstance(channel, GuildVoice):
# to_deny = Permissions.CONNECT | Permissions.SPEAK
#
# overwrite = PermissionOverwrite(type=PermissionTypes.ROLE, deny=to_deny)
# # TODO: Get original permissions
# # TODO: Apply overwrite
# overwrite = overwrite
# _ = Lock(
# channel=channel.id,
# guild=ctx.guild.id,
# admin=ctx.author.id,
# reason=reason,
# duration=duration,
# ) # .save() # Uncomment once implemented
# # await ctx.send(f"{channel.mention} locked for {duration} minute(s)")
# await ctx.send("Unfortunately, this is not yet implemented", hidden=True)
#
# @cog_ext.cog_slash(
# name="unlock",
# description="Unlocks a channel",
# choices=[
# create_option(
# name="channel",
# description="Channel to lock",
# opt_type=7,
# required=False,
# ),
# ],
# )
# @check(admin_or_permissions(Permissions.MANAGE_CHANNELS))
# async def _unlock(
# self,
# ctx: InteractionContext,
# channel: Union[GuildText, GuildVoice] = None,
# ) -> None:
# if not channel:
# channel = ctx.channel
# lock = Lock.objects(guild=ctx.guild.id, channel=channel.id, active=True).first()
# if not lock:
# await ctx.send(f"{channel.mention} not locked.", ephemeral=True)
# return
# for role in ctx.guild.roles:
# with suppress(Exception):
# await self._unlock_channel(channel, role, ctx.author)
# lock.active = False
# lock.save()
# await ctx.send(f"{channel.mention} unlocked")