diff --git a/extensions/speak.py b/extensions/speak.py index cfdd7ab..0284bd5 100644 --- a/extensions/speak.py +++ b/extensions/speak.py @@ -1,6 +1,6 @@ from discord.ext import commands from discord import Member, VoiceState, Embed, Reaction, Guild -from discord.ext.commands import CommandNotFound, BadArgument +from discord.ext.commands import BadArgument from discord_slash import SlashContext, cog_ext, SlashCommandOptionType from discord_slash.utils import manage_commands diff --git a/extensions/tex.py b/extensions/tex.py index 36311d1..53a601e 100644 --- a/extensions/tex.py +++ b/extensions/tex.py @@ -1,6 +1,5 @@ from urllib.parse import urlencode -from discord import Embed from discord.ext import commands from discord_slash import cog_ext, SlashContext, SlashCommandOptionType from discord_slash.utils import manage_commands diff --git a/extensions/warn.py b/extensions/warn.py index ecf3255..e2c082e 100644 --- a/extensions/warn.py +++ b/extensions/warn.py @@ -1,9 +1,11 @@ from discord import Embed, Forbidden, Member, Guild from discord.ext import commands from discord.ext.commands import BadArgument +from discord_slash import cog_ext, SlashCommandOptionType, SlashContext +from discord_slash.utils import manage_commands -from administrator import db -from administrator.check import is_enabled +from administrator import db, slash +from administrator.check import is_enabled, guild_only, has_permissions from administrator.logger import logger from administrator.utils import time_pars, seconds_to_time_string @@ -14,12 +16,13 @@ logger = logger.getChild(extension_name) class Warn(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot + slash.get_cog_commands(self) def description(self): return "Send warning to user and make custom action after a number of warn" @staticmethod - async def check_warn(ctx: commands.Context, target: Member): + async def check_warn(ctx: SlashContext, target: Member): s = db.Session() c = s.query(db.Warn).filter(db.Warn.guild == ctx.guild.id, db.Warn.user == target.id).count() a = s.query(db.WarnAction).filter(db.WarnAction.guild == ctx.guild.id, db.WarnAction.count == c).first() @@ -32,96 +35,72 @@ class Warn(commands.Cog): elif a.action == "mute": pass # Integration with upcoming ban & mute extension - @staticmethod - def get_target(ctx: commands.Context, user: str) -> Member: - users = {str(m): m for m in ctx.guild.members} - if user not in users: - raise BadArgument() - return users[user] - - @commands.group("warn", pass_context=True) + @cog_ext.cog_subcommand(base="warn", name="add", description="Send a warn to a user", options=[ + manage_commands.create_option("user", "The user", SlashCommandOptionType.USER, True), + manage_commands.create_option("description", "The description", SlashCommandOptionType.STRING, True) + ]) @is_enabled() - @commands.guild_only() - #@commands.has_permissions(manage_roles=True, kick_members=True, ban_members=True, mute_members=True) - async def warn(self, ctx: commands.Context): - if ctx.invoked_subcommand is None: - await ctx.invoke(self.warn_help) - - @warn.group("help", pass_context=True) - async def warn_help(self, ctx: commands.Context): - embed = Embed(title="Warn help") - embed.add_field(name="add ", value="Send a warn to a user", inline=False) - embed.add_field(name="remove ", value="Remove a number of warn to a user", inline=False) - embed.add_field(name="purge ", value="Remove all warn of a user", inline=False) - embed.add_field(name="list [user#discriminator|actions]", value="List warn of the guild or a specified user\n" - "If you specify `actions` instead of a user, " - "all the actions of the guild will be listed", - inline=False) - embed.add_field(name="action ", value="Set an action for a count of warn\n" - "Actions: `mute