Disable lock and lockdown until dis-snek permissions work
This commit is contained in:
parent
90506c136e
commit
2a84d50c65
2 changed files with 215 additions and 215 deletions
|
@ -1,7 +1,7 @@
|
|||
"""J.A.R.V.I.S. LockCog."""
|
||||
from dis_snek import Scale
|
||||
|
||||
# TODO: Uncomment 99% of code once implementation is figured out
|
||||
# from dis_snek import Scale
|
||||
#
|
||||
# # TODO: Uncomment 99% of code once implementation is figured out
|
||||
# from contextlib import suppress
|
||||
# from typing import Union
|
||||
#
|
||||
|
@ -20,94 +20,94 @@ from dis_snek import Scale
|
|||
#
|
||||
# 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")
|
||||
#
|
||||
#
|
||||
# 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")
|
||||
|
|
|
@ -1,122 +1,122 @@
|
|||
"""J.A.R.V.I.S. MuteCog."""
|
||||
from datetime import datetime
|
||||
|
||||
from dis_snek import InteractionContext, Permissions, Scale, Snake
|
||||
from dis_snek.models.discord.embed import EmbedField
|
||||
from dis_snek.models.discord.user import Member
|
||||
from dis_snek.models.snek.application_commands import (
|
||||
OptionTypes,
|
||||
SlashCommandChoice,
|
||||
slash_command,
|
||||
slash_option,
|
||||
)
|
||||
from dis_snek.models.snek.command import check
|
||||
|
||||
from jarvis.db.models import Mute
|
||||
from jarvis.utils import build_embed
|
||||
from jarvis.utils.permissions import admin_or_permissions
|
||||
|
||||
|
||||
class MuteCog(Scale):
|
||||
"""J.A.R.V.I.S. MuteCog."""
|
||||
|
||||
def __init__(self, bot: Snake):
|
||||
self.bot = bot
|
||||
|
||||
@slash_command(name="mute", description="Mute a user")
|
||||
@slash_option(name="user", description="User to mute", opt_type=OptionTypes.USER, required=True)
|
||||
@slash_option(
|
||||
name="reason",
|
||||
description="Reason for mute",
|
||||
opt_type=OptionTypes.STRING,
|
||||
required=True,
|
||||
)
|
||||
@slash_option(
|
||||
name="time",
|
||||
description="Duration of mute, default 1",
|
||||
opt_type=OptionTypes.INTEGER,
|
||||
required=False,
|
||||
)
|
||||
@slash_option(
|
||||
name="scale",
|
||||
description="Time scale, default Hour(s)",
|
||||
opt_type=OptionTypes.INTEGER,
|
||||
required=False,
|
||||
choices=[
|
||||
SlashCommandChoice(name="Minute(s)", value=1),
|
||||
SlashCommandChoice(name="Hour(s)", value=60),
|
||||
SlashCommandChoice(name="Day(s)", value=3600),
|
||||
SlashCommandChoice(name="Week(s)", value=604800),
|
||||
],
|
||||
)
|
||||
@check(
|
||||
admin_or_permissions(
|
||||
Permissions.MUTE_MEMBERS, Permissions.BAN_MEMBERS, Permissions.KICK_MEMBERS
|
||||
)
|
||||
)
|
||||
async def _timeout(
|
||||
self, ctx: InteractionContext, user: Member, reason: str, time: int = 1, scale: int = 60
|
||||
) -> None:
|
||||
if user == ctx.author:
|
||||
await ctx.send("You cannot mute yourself.", ephemeral=True)
|
||||
return
|
||||
if user == self.bot.user:
|
||||
await ctx.send("I'm afraid I can't let you do that", ephemeral=True)
|
||||
return
|
||||
if len(reason) > 100:
|
||||
await ctx.send("Reason must be < 100 characters", ephemeral=True)
|
||||
return
|
||||
|
||||
# Max 4 weeks (2419200 seconds) per API
|
||||
duration = time * scale
|
||||
if duration > 2419200:
|
||||
await ctx.send("Mute must be less than 4 weeks (2419200 seconds)", ephemeral=True)
|
||||
return
|
||||
|
||||
await user.timeout(communication_disabled_until=duration, reason=reason)
|
||||
m = Mute(
|
||||
user=user.id,
|
||||
reason=reason,
|
||||
admin=ctx.author.id,
|
||||
guild=ctx.guild.id,
|
||||
duration=duration,
|
||||
active=True,
|
||||
)
|
||||
await m.commit()
|
||||
|
||||
embed = build_embed(
|
||||
title="User Muted",
|
||||
description=f"{user.mention} has been muted",
|
||||
fields=[EmbedField(name="Reason", value=reason)],
|
||||
)
|
||||
embed.set_author(name=user.display_name, icon_url=user.display_avatar.url)
|
||||
embed.set_thumbnail(url=user.display_avatar.url)
|
||||
embed.set_footer(text=f"{user.username}#{user.discriminator} | {user.id}")
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@slash_command(name="unmute", description="Unmute a user")
|
||||
@slash_option(
|
||||
name="user", description="User to unmute", opt_type=OptionTypes.USER, required=True
|
||||
)
|
||||
@check(
|
||||
admin_or_permissions(
|
||||
Permissions.MUTE_MEMBERS, Permissions.BAN_MEMBERS, Permissions.KICK_MEMBERS
|
||||
)
|
||||
)
|
||||
async def _unmute(self, ctx: InteractionContext, user: Member) -> None:
|
||||
if (
|
||||
not user.communication_disabled_until
|
||||
or user.communication_disabled_until < datetime.now() # noqa: W503
|
||||
):
|
||||
await ctx.send("User is not muted", ephemeral=True)
|
||||
return
|
||||
|
||||
embed = build_embed(
|
||||
title="User Unmuted",
|
||||
description=f"{user.mention} has been unmuted",
|
||||
fields=[],
|
||||
)
|
||||
embed.set_author(name=user.display_name, icon_url=user.display_avatar.url)
|
||||
embed.set_thumbnail(url=user.display_avatar.url)
|
||||
embed.set_footer(text=f"{user.username}#{user.discriminator} | {user.id}")
|
||||
await ctx.send(embed=embed)
|
||||
# from datetime import datetime
|
||||
#
|
||||
# from dis_snek import InteractionContext, Permissions, Scale, Snake
|
||||
# from dis_snek.models.discord.embed import EmbedField
|
||||
# from dis_snek.models.discord.user import Member
|
||||
# from dis_snek.models.snek.application_commands import (
|
||||
# OptionTypes,
|
||||
# SlashCommandChoice,
|
||||
# slash_command,
|
||||
# slash_option,
|
||||
# )
|
||||
# from dis_snek.models.snek.command import check
|
||||
#
|
||||
# from jarvis.db.models import Mute
|
||||
# from jarvis.utils import build_embed
|
||||
# from jarvis.utils.permissions import admin_or_permissions
|
||||
#
|
||||
#
|
||||
# class MuteCog(Scale):
|
||||
# """J.A.R.V.I.S. MuteCog."""
|
||||
#
|
||||
# def __init__(self, bot: Snake):
|
||||
# self.bot = bot
|
||||
#
|
||||
# @slash_command(name="mute", description="Mute a user")
|
||||
# @slash_option(name="user", description="User to mute", opt_type=OptionTypes.USER, required=True)
|
||||
# @slash_option(
|
||||
# name="reason",
|
||||
# description="Reason for mute",
|
||||
# opt_type=OptionTypes.STRING,
|
||||
# required=True,
|
||||
# )
|
||||
# @slash_option(
|
||||
# name="time",
|
||||
# description="Duration of mute, default 1",
|
||||
# opt_type=OptionTypes.INTEGER,
|
||||
# required=False,
|
||||
# )
|
||||
# @slash_option(
|
||||
# name="scale",
|
||||
# description="Time scale, default Hour(s)",
|
||||
# opt_type=OptionTypes.INTEGER,
|
||||
# required=False,
|
||||
# choices=[
|
||||
# SlashCommandChoice(name="Minute(s)", value=1),
|
||||
# SlashCommandChoice(name="Hour(s)", value=60),
|
||||
# SlashCommandChoice(name="Day(s)", value=3600),
|
||||
# SlashCommandChoice(name="Week(s)", value=604800),
|
||||
# ],
|
||||
# )
|
||||
# @check(
|
||||
# admin_or_permissions(
|
||||
# Permissions.MUTE_MEMBERS, Permissions.BAN_MEMBERS, Permissions.KICK_MEMBERS
|
||||
# )
|
||||
# )
|
||||
# async def _timeout(
|
||||
# self, ctx: InteractionContext, user: Member, reason: str, time: int = 1, scale: int = 60
|
||||
# ) -> None:
|
||||
# if user == ctx.author:
|
||||
# await ctx.send("You cannot mute yourself.", ephemeral=True)
|
||||
# return
|
||||
# if user == self.bot.user:
|
||||
# await ctx.send("I'm afraid I can't let you do that", ephemeral=True)
|
||||
# return
|
||||
# if len(reason) > 100:
|
||||
# await ctx.send("Reason must be < 100 characters", ephemeral=True)
|
||||
# return
|
||||
#
|
||||
# # Max 4 weeks (2419200 seconds) per API
|
||||
# duration = time * scale
|
||||
# if duration > 2419200:
|
||||
# await ctx.send("Mute must be less than 4 weeks (2419200 seconds)", ephemeral=True)
|
||||
# return
|
||||
#
|
||||
# await user.timeout(communication_disabled_until=duration, reason=reason)
|
||||
# m = Mute(
|
||||
# user=user.id,
|
||||
# reason=reason,
|
||||
# admin=ctx.author.id,
|
||||
# guild=ctx.guild.id,
|
||||
# duration=duration,
|
||||
# active=True,
|
||||
# )
|
||||
# await m.commit()
|
||||
#
|
||||
# embed = build_embed(
|
||||
# title="User Muted",
|
||||
# description=f"{user.mention} has been muted",
|
||||
# fields=[EmbedField(name="Reason", value=reason)],
|
||||
# )
|
||||
# embed.set_author(name=user.display_name, icon_url=user.display_avatar.url)
|
||||
# embed.set_thumbnail(url=user.display_avatar.url)
|
||||
# embed.set_footer(text=f"{user.username}#{user.discriminator} | {user.id}")
|
||||
# await ctx.send(embed=embed)
|
||||
#
|
||||
# @slash_command(name="unmute", description="Unmute a user")
|
||||
# @slash_option(
|
||||
# name="user", description="User to unmute", opt_type=OptionTypes.USER, required=True
|
||||
# )
|
||||
# @check(
|
||||
# admin_or_permissions(
|
||||
# Permissions.MUTE_MEMBERS, Permissions.BAN_MEMBERS, Permissions.KICK_MEMBERS
|
||||
# )
|
||||
# )
|
||||
# async def _unmute(self, ctx: InteractionContext, user: Member) -> None:
|
||||
# if (
|
||||
# not user.communication_disabled_until
|
||||
# or user.communication_disabled_until < datetime.now() # noqa: W503
|
||||
# ):
|
||||
# await ctx.send("User is not muted", ephemeral=True)
|
||||
# return
|
||||
#
|
||||
# embed = build_embed(
|
||||
# title="User Unmuted",
|
||||
# description=f"{user.mention} has been unmuted",
|
||||
# fields=[],
|
||||
# )
|
||||
# embed.set_author(name=user.display_name, icon_url=user.display_avatar.url)
|
||||
# embed.set_thumbnail(url=user.display_avatar.url)
|
||||
# embed.set_footer(text=f"{user.username}#{user.discriminator} | {user.id}")
|
||||
# await ctx.send(embed=embed)
|
||||
|
|
Loading…
Add table
Reference in a new issue