Remove implentations for time being
This commit is contained in:
parent
56661d96b8
commit
9647f9c746
3 changed files with 118 additions and 137 deletions
3
.flake8
3
.flake8
|
@ -1,6 +1,7 @@
|
||||||
[flake8]
|
[flake8]
|
||||||
extend-ignore =
|
extend-ignore =
|
||||||
Q0, E501, C812, E203, W503 # These default to arguing with Black. We might configure some of them eventually
|
Q0, E501, C812, E203, W503, # These default to arguing with Black. We might configure some of them eventually
|
||||||
|
ANN101, # Ignore self annotation
|
||||||
ANN204, ANN206, # return annotations for special methods and class methods
|
ANN204, ANN206, # return annotations for special methods and class methods
|
||||||
D105, D107, # Missing Docstrings in magic method and __init__
|
D105, D107, # Missing Docstrings in magic method and __init__
|
||||||
S311, # Standard pseudo-random generators are not suitable for security/cryptographic purposes.
|
S311, # Standard pseudo-random generators are not suitable for security/cryptographic purposes.
|
||||||
|
|
|
@ -1,134 +1,113 @@
|
||||||
"""J.A.R.V.I.S. LockCog."""
|
"""J.A.R.V.I.S. LockCog."""
|
||||||
from contextlib import suppress
|
from dis_snek import Scale
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from discord import Role, TextChannel, User, VoiceChannel
|
# TODO: Uncomment 99% of code once implementation is figured out
|
||||||
from discord.ext.commands import Bot
|
# from contextlib import suppress
|
||||||
from discord_slash import SlashContext, cog_ext
|
# from typing import Union
|
||||||
from discord_slash.utils.manage_commands import create_option
|
#
|
||||||
|
# from dis_snek import InteractionContext, Scale, Snake
|
||||||
from jarvis.db.models import Lock
|
# from dis_snek.models.discord.enums import Permissions
|
||||||
from jarvis.utils.cachecog import CacheCog
|
# from dis_snek.models.discord.role import Role
|
||||||
from jarvis.utils.permissions import admin_or_permissions
|
# 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(CacheCog):
|
class LockCog(Scale):
|
||||||
"""J.A.R.V.I.S. LockCog."""
|
"""J.A.R.V.I.S. LockCog."""
|
||||||
|
|
||||||
def __init__(self, bot: Bot):
|
# @slash_command(name="lock", description="Lock a channel")
|
||||||
super().__init__(bot)
|
# @slash_option(name="reason",
|
||||||
|
# description="Lock Reason",
|
||||||
async def _lock_channel(
|
# opt_type=3,
|
||||||
self,
|
# required=True,)
|
||||||
channel: Union[TextChannel, VoiceChannel],
|
# @slash_option(name="duration",
|
||||||
role: Role,
|
# description="Lock duration in minutes (default 10)",
|
||||||
admin: User,
|
# opt_type=4,
|
||||||
reason: str,
|
# required=False,)
|
||||||
allow_send: bool = False,
|
# @slash_option(name="channel",
|
||||||
) -> None:
|
# description="Channel to lock",
|
||||||
overrides = channel.overwrites_for(role)
|
# opt_type=7,
|
||||||
if isinstance(channel, TextChannel):
|
# required=False,)
|
||||||
overrides.send_messages = allow_send
|
# @check(admin_or_permissions(Permissions.MANAGE_CHANNELS))
|
||||||
elif isinstance(channel, VoiceChannel):
|
# async def _lock(
|
||||||
overrides.speak = allow_send
|
# self,
|
||||||
await channel.set_permissions(role, overwrite=overrides, reason=reason)
|
# ctx: InteractionContext,
|
||||||
|
# reason: str,
|
||||||
async def _unlock_channel(
|
# duration: int = 10,
|
||||||
self,
|
# channel: Union[GuildText, GuildVoice] = None,
|
||||||
channel: Union[TextChannel, VoiceChannel],
|
# ) -> None:
|
||||||
role: Role,
|
# await ctx.defer(ephemeral=True)
|
||||||
admin: User,
|
# if duration <= 0:
|
||||||
) -> None:
|
# await ctx.send("Duration must be > 0", ephemeral=True)
|
||||||
overrides = channel.overwrites_for(role)
|
# return
|
||||||
if isinstance(channel, TextChannel):
|
#
|
||||||
overrides.send_messages = None
|
# elif duration > 60 * 12:
|
||||||
elif isinstance(channel, VoiceChannel):
|
# await ctx.send("Duration must be <= 12 hours", ephemeral=True)
|
||||||
overrides.speak = None
|
# return
|
||||||
await channel.set_permissions(role, overwrite=overrides)
|
#
|
||||||
|
# if len(reason) > 100:
|
||||||
@cog_ext.cog_slash(
|
# await ctx.send("Reason must be <= 100 characters", ephemeral=True)
|
||||||
name="lock",
|
# return
|
||||||
description="Locks a channel",
|
# if not channel:
|
||||||
choices=[
|
# channel = ctx.channel
|
||||||
create_option(
|
#
|
||||||
name="reason",
|
# # role = ctx.guild.default_role # Uncomment once implemented
|
||||||
description="Lock Reason",
|
# if isinstance(channel, GuildText):
|
||||||
option_type=3,
|
# to_deny = Permissions.SEND_MESSAGES
|
||||||
required=True,
|
# elif isinstance(channel, GuildVoice):
|
||||||
),
|
# to_deny = Permissions.CONNECT | Permissions.SPEAK
|
||||||
create_option(
|
#
|
||||||
name="duration",
|
# overwrite = PermissionOverwrite(type=PermissionTypes.ROLE, deny=to_deny)
|
||||||
description="Lock duration in minutes (default 10)",
|
# # TODO: Get original permissions
|
||||||
option_type=4,
|
# # TODO: Apply overwrite
|
||||||
required=False,
|
# overwrite = overwrite
|
||||||
),
|
# _ = Lock(
|
||||||
create_option(
|
# channel=channel.id,
|
||||||
name="channel",
|
# guild=ctx.guild.id,
|
||||||
description="Channel to lock",
|
# admin=ctx.author.id,
|
||||||
option_type=7,
|
# reason=reason,
|
||||||
required=False,
|
# 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)
|
||||||
@admin_or_permissions(manage_channels=True)
|
#
|
||||||
async def _lock(
|
# @cog_ext.cog_slash(
|
||||||
self,
|
# name="unlock",
|
||||||
ctx: SlashContext,
|
# description="Unlocks a channel",
|
||||||
reason: str,
|
# choices=[
|
||||||
duration: int = 10,
|
# create_option(
|
||||||
channel: Union[TextChannel, VoiceChannel] = None,
|
# name="channel",
|
||||||
) -> None:
|
# description="Channel to lock",
|
||||||
await ctx.defer(hidden=True)
|
# opt_type=7,
|
||||||
if duration <= 0:
|
# required=False,
|
||||||
await ctx.send("Duration must be > 0", hidden=True)
|
# ),
|
||||||
return
|
# ],
|
||||||
elif duration >= 300:
|
# )
|
||||||
await ctx.send("Duration must be < 5 hours", hidden=True)
|
# @check(admin_or_permissions(Permissions.MANAGE_CHANNELS))
|
||||||
return
|
# async def _unlock(
|
||||||
if len(reason) > 100:
|
# self,
|
||||||
await ctx.send("Reason must be < 100 characters", hidden=True)
|
# ctx: InteractionContext,
|
||||||
return
|
# channel: Union[GuildText, GuildVoice] = None,
|
||||||
if not channel:
|
# ) -> None:
|
||||||
channel = ctx.channel
|
# if not channel:
|
||||||
for role in ctx.guild.roles:
|
# channel = ctx.channel
|
||||||
with suppress(Exception):
|
# lock = Lock.objects(guild=ctx.guild.id, channel=channel.id, active=True).first()
|
||||||
await self._lock_channel(channel, role, ctx.author, reason)
|
# if not lock:
|
||||||
_ = Lock(
|
# await ctx.send(f"{channel.mention} not locked.", ephemeral=True)
|
||||||
channel=channel.id,
|
# return
|
||||||
guild=ctx.guild.id,
|
# for role in ctx.guild.roles:
|
||||||
admin=ctx.author.id,
|
# with suppress(Exception):
|
||||||
reason=reason,
|
# await self._unlock_channel(channel, role, ctx.author)
|
||||||
duration=duration,
|
# lock.active = False
|
||||||
).save()
|
# lock.save()
|
||||||
await ctx.send(f"{channel.mention} locked for {duration} minute(s)")
|
# await ctx.send(f"{channel.mention} unlocked")
|
||||||
|
|
||||||
@cog_ext.cog_slash(
|
|
||||||
name="unlock",
|
|
||||||
description="Unlocks a channel",
|
|
||||||
choices=[
|
|
||||||
create_option(
|
|
||||||
name="channel",
|
|
||||||
description="Channel to lock",
|
|
||||||
option_type=7,
|
|
||||||
required=False,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
@admin_or_permissions(manage_channels=True)
|
|
||||||
async def _unlock(
|
|
||||||
self,
|
|
||||||
ctx: SlashContext,
|
|
||||||
channel: Union[TextChannel, VoiceChannel] = 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.", hidden=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")
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ from discord_slash.utils.manage_commands import create_option
|
||||||
|
|
||||||
from jarvis.db.models import Lock
|
from jarvis.db.models import Lock
|
||||||
from jarvis.utils.cachecog import CacheCog
|
from jarvis.utils.cachecog import CacheCog
|
||||||
from jarvis.utils.permissions import admin_or_permissions
|
|
||||||
|
# from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
|
||||||
|
|
||||||
class LockdownCog(CacheCog):
|
class LockdownCog(CacheCog):
|
||||||
|
@ -25,30 +26,30 @@ class LockdownCog(CacheCog):
|
||||||
create_option(
|
create_option(
|
||||||
name="reason",
|
name="reason",
|
||||||
description="Lockdown Reason",
|
description="Lockdown Reason",
|
||||||
option_type=3,
|
opt_type=3,
|
||||||
required=True,
|
required=True,
|
||||||
),
|
),
|
||||||
create_option(
|
create_option(
|
||||||
name="duration",
|
name="duration",
|
||||||
description="Lockdown duration in minutes (default 10)",
|
description="Lockdown duration in minutes (default 10)",
|
||||||
option_type=4,
|
opt_type=4,
|
||||||
required=False,
|
required=False,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@admin_or_permissions(manage_channels=True)
|
# @check(admin_or_permissions(manage_channels=True))
|
||||||
async def _lockdown_start(
|
async def _lockdown_start(
|
||||||
self,
|
self,
|
||||||
ctx: SlashContext,
|
ctx: SlashContext,
|
||||||
reason: str,
|
reason: str,
|
||||||
duration: int = 10,
|
duration: int = 10,
|
||||||
) -> None:
|
) -> None:
|
||||||
await ctx.defer(hidden=True)
|
await ctx.defer(ephemeral=True)
|
||||||
if duration <= 0:
|
if duration <= 0:
|
||||||
await ctx.send("Duration must be > 0", hidden=True)
|
await ctx.send("Duration must be > 0", ephemeral=True)
|
||||||
return
|
return
|
||||||
elif duration >= 300:
|
elif duration >= 300:
|
||||||
await ctx.send("Duration must be < 5 hours", hidden=True)
|
await ctx.send("Duration must be < 5 hours", ephemeral=True)
|
||||||
return
|
return
|
||||||
channels = ctx.guild.channels
|
channels = ctx.guild.channels
|
||||||
roles = ctx.guild.roles
|
roles = ctx.guild.roles
|
||||||
|
@ -87,7 +88,7 @@ class LockdownCog(CacheCog):
|
||||||
update = False
|
update = False
|
||||||
locks = Lock.objects(guild=ctx.guild.id, active=True)
|
locks = Lock.objects(guild=ctx.guild.id, active=True)
|
||||||
if not locks:
|
if not locks:
|
||||||
await ctx.send("No lockdown detected.", hidden=True)
|
await ctx.send("No lockdown detected.", ephemeral=True)
|
||||||
return
|
return
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
|
|
Loading…
Add table
Reference in a new issue