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