diff --git a/jarvis/cogs/admin/warning.py b/jarvis/cogs/admin/warning.py index 81ed296..f484c04 100644 --- a/jarvis/cogs/admin/warning.py +++ b/jarvis/cogs/admin/warning.py @@ -1,12 +1,15 @@ """J.A.R.V.I.S. WarningCog.""" from datetime import datetime, timedelta -from ButtonPaginator import Paginator -from discord import User -from discord.ext.commands import Bot -from discord_slash import SlashContext, cog_ext -from discord_slash.model import ButtonStyle -from discord_slash.utils.manage_commands import create_choice, create_option +from dis_snek import InteractionContext, Permissions, Snek +from dis_snek.ext.paginators import Paginator +from dis_snek.models.discord.user import User +from dis_snek.models.snek.application_commands import ( + OptionTypes, + SlashCommandChoice, + slash_command, + slash_option, +) from jarvis.db.models import Warning from jarvis.utils import build_embed @@ -18,35 +21,29 @@ from jarvis.utils.permissions import admin_or_permissions class WarningCog(CacheCog): """J.A.R.V.I.S. WarningCog.""" - def __init__(self, bot: Bot): + def __init__(self, bot: Snek): super().__init__(bot) - @cog_ext.cog_slash( - name="warn", - description="Warn a user", - options=[ - create_option( - name="user", - description="User to warn", - option_type=6, - required=True, - ), - create_option( - name="reason", - description="Reason for warning", - option_type=3, - required=True, - ), - create_option( - name="duration", - description="Duration of warning in hours, default 24", - option_type=4, - required=False, - ), - ], + @slash_command(name="warn", description="Warn a user") + @slash_option( + name="user", description="User to warn", option_type=OptionTypes.USER, required=True ) - @admin_or_permissions(manage_guild=True) - async def _warn(self, ctx: SlashContext, user: User, reason: str, duration: int = 24) -> None: + @slash_option( + name="reason", + description="Reason for warning", + option_type=OptionTypes.STRING, + required=True, + ) + @slash_option( + name="duration", + description="Duration of warning in hours, default 24", + option_type=OptionTypes.INTEGER, + required=False, + ) + @admin_or_permissions(Permissions.MANAGE_GUILD) + async def _warn( + self, ctx: InteractionContext, user: User, reason: str, duration: int = 24 + ) -> None: if len(reason) > 100: await ctx.send("Reason must be < 100 characters", hidden=True) return @@ -72,37 +69,29 @@ class WarningCog(CacheCog): fields=fields, ) embed.set_author( - name=user.nick if user.nick else user.name, + name=user.display_name, icon_url=user.avatar_url, ) embed.set_footer(text=f"{user.name}#{user.discriminator} | {user.id}") await ctx.send(embed=embed) - @cog_ext.cog_slash( - name="warnings", - description="Get count of user warnings", - options=[ - create_option( - name="user", - description="User to view", - option_type=6, - required=True, - ), - create_option( - name="active", - description="View only active", - option_type=4, - required=False, - choices=[ - create_choice(name="Yes", value=1), - create_choice(name="No", value=0), - ], - ), + @slash_command(name="warnings", description="Get count of user warnings") + @slash_option( + name="user", description="User to view", option_type=OptionTypes.USER, required=True + ) + @slash_option( + name="active", + description="View active only", + option_type=OptionTypes.INTEGER, + required=False, + choices=[ + SlashCommandChoice(name="Yes", value=1), + SlashCommandChoice(name="No", value=0), ], ) - @admin_or_permissions(manage_guild=True) - async def _warnings(self, ctx: SlashContext, user: User, active: bool = 1) -> None: + @admin_or_permissions(Permissions.MANAGE_GUILD) + async def _warnings(self, ctx: InteractionContext, user: User, active: bool = 1) -> None: active = bool(active) exists = self.check_cache(ctx, user_id=user.id, active=active) if exists: @@ -128,7 +117,7 @@ class WarningCog(CacheCog): description=f"{warnings.count()} total | 0 currently active", fields=[], ) - embed.set_author(name=user.name, icon_url=user.avatar_url) + embed.set_author(name=user.username, icon_url=user.avatar_url) embed.set_thumbnail(url=ctx.guild.icon_url) pages.append(embed) else: @@ -137,7 +126,7 @@ class WarningCog(CacheCog): admin = ctx.guild.get_member(warn.admin) admin_name = "||`[redacted]`||" if admin: - admin_name = f"{admin.name}#{admin.discriminator}" + admin_name = f"{admin.username}#{admin.discriminator}" fields.append( Field( name=warn.created_at.strftime("%Y-%m-%d %H:%M:%S UTC"), @@ -154,11 +143,11 @@ class WarningCog(CacheCog): fields=fields[i : i + 5], ) embed.set_author( - name=user.name + "#" + user.discriminator, + name=user.username + "#" + user.discriminator, icon_url=user.avatar_url, ) embed.set_thumbnail(url=ctx.guild.icon_url) - embed.set_footer(text=f"{user.name}#{user.discriminator} | {user.id}") + embed.set_footer(text=f"{user.username}#{user.discriminator} | {user.id}") pages.append(embed) else: fields = [] @@ -181,24 +170,13 @@ class WarningCog(CacheCog): fields=fields[i : i + 5], ) embed.set_author( - name=user.name + "#" + user.discriminator, + name=user.username + "#" + user.discriminator, icon_url=user.avatar_url, ) embed.set_thumbnail(url=ctx.guild.icon_url) pages.append(embed) - paginator = Paginator( - bot=self.bot, - ctx=ctx, - embeds=pages, - only=ctx.author, - timeout=60 * 5, # 5 minute timeout - disable_after_timeout=True, - use_extend=len(pages) > 2, - left_button_style=ButtonStyle.grey, - right_button_style=ButtonStyle.grey, - basic_buttons=["◀", "▶"], - ) + paginator = Paginator(bot=self.bot, *pages, timeout=300) self.cache[hash(paginator)] = { "guild": ctx.guild.id, @@ -210,4 +188,4 @@ class WarningCog(CacheCog): "paginator": paginator, } - await paginator.start() + await paginator.send(ctx)