diff --git a/bot.py b/bot.py index 54754d3..6c7e635 100644 --- a/bot.py +++ b/bot.py @@ -90,7 +90,7 @@ class DiscordBot(commands.Bot): if os.path.exists(init_file): try: await self.load_extension(f"cogs.{folder}") - if folder not in ["fun", "general", "idevice"]: + if folder not in ["fun", "general", "idevice", "miscellaneous", "moderation"]: self.logger.info(f"Loaded extension '{folder}'") except Exception as e: exception = f"{type(e).__name__}: {e}" diff --git a/cogs/help.py b/cogs/help.py index ae4b4b2..50941a3 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -79,11 +79,7 @@ class Help(commands.Cog, name="help"): "translate": "utilities", # Miscellaneous Commands - "keanu": "miscellaneous", - "labubu": "miscellaneous", - "piracy": "miscellaneous", - "tryitandsee": "miscellaneous", - "rr": "miscellaneous", + "miscellaneous": "miscellaneous", } category_descriptions = { @@ -170,7 +166,7 @@ class Help(commands.Cog, name="help"): commands_in_category.append((app_command.name, description)) seen_names.add(app_command.name) - if hasattr(app_command, 'commands') and category in ["fun", "general", "idevice"]: + if hasattr(app_command, 'commands') and category in ["fun", "general", "idevice", "miscellaneous", "moderation"]: for subcommand in app_command.commands: if subcommand.name in seen_names: continue diff --git a/cogs/moderation/__init__.py b/cogs/moderation/__init__.py new file mode 100644 index 0000000..0553ba1 --- /dev/null +++ b/cogs/moderation/__init__.py @@ -0,0 +1,77 @@ +import discord +from discord.ext import commands +from discord.ext.commands import Context + +from .ban import ban_command +from .kick import kick_command +from .purge import purge_command +from .warnings import warnings_command +from .archive import archive_command +from .hackban import hackban_command +from .nick import nick_command + +class Moderation(commands.GroupCog, name="moderation"): + def __init__(self, bot) -> None: + self.bot = bot + super().__init__() + + @commands.hybrid_command( + name="ban", + description="Bans a user from the server." + ) + async def ban(self, context, user: discord.User, *, reason: str = "Not specified", delete_messages: str = "none"): + return await ban_command()(self, context, user=user, reason=reason, delete_messages=delete_messages) + + @commands.hybrid_command( + name="kick", + description="Kicks a user from the server." + ) + async def kick(self, context, user: discord.User, *, reason: str = "Not specified"): + return await kick_command()(self, context, user=user, reason=reason) + + @commands.hybrid_command( + name="purge", + description="Delete a number of messages." + ) + async def purge(self, context, amount: int): + return await purge_command()(self, context, amount=amount) + + @commands.hybrid_command( + name="warnings", + description="Manage warnings of a user on a server." + ) + async def warnings(self, context): + return await warnings_command()(self, context) + + @commands.hybrid_command( + name="archive", + description="Archives in a text file the last messages with a chosen limit of messages." + ) + async def archive(self, context, limit: int = 10): + return await archive_command()(self, context, limit=limit) + + @commands.hybrid_command( + name="hackban", + description="Bans a user without the user having to be in the server." + ) + async def hackban(self, context, user_id: int, *, reason: str = "Not specified"): + return await hackban_command()(self, context, user_id=user_id, reason=reason) + + @commands.hybrid_command( + name="nick", + description="Change the nickname of a user on a server." + ) + async def nick(self, context, user: discord.User, *, nickname: str = None): + return await nick_command()(self, context, user=user, nickname=nickname) + +async def setup(bot) -> None: + cog = Moderation(bot) + await bot.add_cog(cog) + + bot.logger.info("Loaded extension 'moderation.ban'") + bot.logger.info("Loaded extension 'moderation.kick'") + bot.logger.info("Loaded extension 'moderation.purge'") + bot.logger.info("Loaded extension 'moderation.warnings'") + bot.logger.info("Loaded extension 'moderation.archive'") + bot.logger.info("Loaded extension 'moderation.hackban'") + bot.logger.info("Loaded extension 'moderation.nick'") diff --git a/cogs/moderation/archive.py b/cogs/moderation/archive.py index 5430086..3c0617d 100644 --- a/cogs/moderation/archive.py +++ b/cogs/moderation/archive.py @@ -6,10 +6,7 @@ from discord.ext import commands from discord.ext.commands import Context -class Archive(commands.Cog, name="archive"): - def __init__(self, bot) -> None: - self.bot = bot - +def archive_command(): @commands.hybrid_command( name="archive", description="Archives in a text file the last messages with a chosen limit of messages.", @@ -18,7 +15,7 @@ class Archive(commands.Cog, name="archive"): @app_commands.describe( limit="The limit of messages that should be archived.", ) - async def archive(self, context: Context, limit: int = 10) -> None: + async def archive(self, context, limit: int = 10): """ Archives in a text file the last messages with a chosen limit of messages. This command requires the MESSAGE_CONTENT intent to work properly. @@ -54,7 +51,5 @@ class Archive(commands.Cog, name="archive"): f = discord.File(log_file) await context.send(file=f) os.remove(log_file) - - -async def setup(bot) -> None: - await bot.add_cog(Archive(bot)) \ No newline at end of file + + return archive \ No newline at end of file diff --git a/cogs/moderation/ban.py b/cogs/moderation/ban.py index fb3405f..d5ef222 100644 --- a/cogs/moderation/ban.py +++ b/cogs/moderation/ban.py @@ -4,10 +4,7 @@ from discord.ext import commands from discord.ext.commands import Context -class Ban(commands.Cog, name="ban"): - def __init__(self, bot) -> None: - self.bot = bot - +def ban_command(): @commands.hybrid_command( name="ban", description="Bans a user from the server.", @@ -27,8 +24,8 @@ class Ban(commands.Cog, name="ban"): app_commands.Choice(name="Last 7 days", value="7d"), ]) async def ban( - self, context: Context, user: discord.User, *, reason: str = "Not specified", delete_messages: str = "none" - ) -> None: + self, context, user: discord.User, *, reason: str = "Not specified", delete_messages: str = "none" + ): try: member = context.guild.get_member(user.id) if not member: @@ -211,7 +208,5 @@ class Ban(commands.Cog, name="ban"): "7d": "Last 7 days" } return time_formats.get(delete_option, "Unknown time period") - - -async def setup(bot) -> None: - await bot.add_cog(Ban(bot)) \ No newline at end of file + + return ban \ No newline at end of file diff --git a/cogs/moderation/hackban.py b/cogs/moderation/hackban.py index 4109db8..009e260 100644 --- a/cogs/moderation/hackban.py +++ b/cogs/moderation/hackban.py @@ -4,10 +4,7 @@ from discord.ext import commands from discord.ext.commands import Context -class HackBan(commands.Cog, name="hackban"): - def __init__(self, bot) -> None: - self.bot = bot - +def hackban_command(): @commands.hybrid_command( name="hackban", description="Bans a user without the user having to be in the server.", @@ -19,8 +16,8 @@ class HackBan(commands.Cog, name="hackban"): reason="The reason why the user should be banned.", ) async def hackban( - self, context: Context, user_id: str, *, reason: str = "Not specified" - ) -> None: + self, context, user_id: str, *, reason: str = "Not specified" + ): """ Bans a user without the user having to be in the server. @@ -47,7 +44,5 @@ class HackBan(commands.Cog, name="hackban"): color=0xE02B2B, ).set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png") await context.send(embed=embed) - - -async def setup(bot) -> None: - await bot.add_cog(HackBan(bot)) + + return hackban diff --git a/cogs/moderation/kick.py b/cogs/moderation/kick.py index 2bdb2a5..6c91ed8 100644 --- a/cogs/moderation/kick.py +++ b/cogs/moderation/kick.py @@ -4,10 +4,7 @@ from discord.ext import commands from discord.ext.commands import Context -class Kick(commands.Cog, name="kick"): - def __init__(self, bot) -> None: - self.bot = bot - +def kick_command(): @commands.hybrid_command( name="kick", description="Kicks a user from the server.", @@ -17,8 +14,8 @@ class Kick(commands.Cog, name="kick"): reason="The reason why the user should be kicked.", ) async def kick( - self, context: Context, user: discord.User, *, reason: str = "Not specified" - ) -> None: + self, context, user: discord.User, *, reason: str = "Not specified" + ): try: member = context.guild.get_member(user.id) if not member: @@ -122,7 +119,5 @@ class Kick(commands.Cog, name="kick"): color=0xE02B2B, ).set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png") await context.send(embed=embed, ephemeral=True) - - -async def setup(bot) -> None: - await bot.add_cog(Kick(bot)) + + return kick diff --git a/cogs/moderation/nick.py b/cogs/moderation/nick.py index 3eb7565..489a75d 100644 --- a/cogs/moderation/nick.py +++ b/cogs/moderation/nick.py @@ -4,10 +4,7 @@ from discord.ext import commands from discord.ext.commands import Context -class Nick(commands.Cog, name="nick"): - def __init__(self, bot) -> None: - self.bot = bot - +def nick_command(): @commands.hybrid_command( name="nick", description="Change the nickname of a user on a server.", @@ -17,8 +14,8 @@ class Nick(commands.Cog, name="nick"): nickname="The new nickname that should be set.", ) async def nick( - self, context: Context, user: discord.User, *, nickname: str = None - ) -> None: + self, context, user: discord.User, *, nickname: str = None + ): """ Change the nickname of a user on a server. @@ -60,7 +57,5 @@ class Nick(commands.Cog, name="nick"): color=0xE02B2B, ).set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png") await context.send(embed=embed, ephemeral=True) - - -async def setup(bot) -> None: - await bot.add_cog(Nick(bot)) + + return nick diff --git a/cogs/moderation/purge.py b/cogs/moderation/purge.py index c56e73e..a18b185 100644 --- a/cogs/moderation/purge.py +++ b/cogs/moderation/purge.py @@ -4,10 +4,7 @@ from discord.ext import commands from discord.ext.commands import Context -class Purge(commands.Cog, name="purge"): - def __init__(self, bot) -> None: - self.bot = bot - +def purge_command(): @commands.hybrid_command( name="purge", description="Delete a number of messages.", @@ -15,13 +12,7 @@ class Purge(commands.Cog, name="purge"): @commands.has_guild_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) @app_commands.describe(amount="The amount of messages that should be deleted.") - async def purge(self, context: Context, amount: int) -> None: - """ - Delete a number of messages. - - :param context: The hybrid command context. - :param amount: The number of messages that should be deleted. - """ + async def purge(self, context, amount: int): await context.send("Deleting messages...") purged_messages = await context.channel.purge(limit=amount + 1) embed = discord.Embed( @@ -31,7 +22,5 @@ class Purge(commands.Cog, name="purge"): ) embed.set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png") await context.channel.send(embed=embed) - - -async def setup(bot) -> None: - await bot.add_cog(Purge(bot)) + + return purge diff --git a/cogs/moderation/warnings.py b/cogs/moderation/warnings.py index dc8f4bf..c803185 100644 --- a/cogs/moderation/warnings.py +++ b/cogs/moderation/warnings.py @@ -4,11 +4,8 @@ from discord.ext import commands from discord.ext.commands import Context -class Warnings(commands.Cog, name="warnings"): - def __init__(self, bot) -> None: - self.bot = bot - - async def send_embed(self, context: Context, embed: discord.Embed, *, ephemeral: bool = False) -> None: +def warnings_command(): + async def send_embed(context, embed: discord.Embed, *, ephemeral: bool = False) -> None: interaction = getattr(context, "interaction", None) if interaction is not None: if interaction.response.is_done(): @@ -22,7 +19,7 @@ class Warnings(commands.Cog, name="warnings"): name="warning", description="Manage warnings of a user on a server.", ) - async def warning(self, context: Context) -> None: + async def warning(self, context) -> None: """ Manage warnings of a user on a server. @@ -170,5 +167,4 @@ class Warnings(commands.Cog, name="warnings"): -async def setup(bot) -> None: - await bot.add_cog(Warnings(bot)) + return warning