refactor(general): commands into GroupCog

Migrated general commands (ping, uptime, botinfo, serverinfo, feedback) into a single GroupCog in cogs/general/__init__.py for better organization and maintainability. Converted individual command files to export command functions instead of Cogs. Updated bot.py to load the new general extension. Renamed help.py for consistency.
This commit is contained in:
neoarz
2025-09-28 22:53:25 -04:00
parent e7ee97074b
commit 72cdd9b403
8 changed files with 81 additions and 80 deletions

2
bot.py
View File

@@ -90,7 +90,7 @@ class DiscordBot(commands.Bot):
if os.path.exists(init_file):
try:
await self.load_extension(f"cogs.{folder}")
if folder != "fun":
if folder not in ["fun", "general"]:
self.logger.info(f"Loaded extension '{folder}'")
except Exception as e:
exception = f"{type(e).__name__}: {e}"

59
cogs/general/__init__.py Normal file
View File

@@ -0,0 +1,59 @@
import discord
from discord.ext import commands
from discord.ext.commands import Context
from .ping import ping_command
from .uptime import uptime_command
from .botinfo import botinfo_command
from .serverinfo import serverinfo_command
from .feedback import feedback_command
class General(commands.GroupCog, name="general"):
def __init__(self, bot) -> None:
self.bot = bot
super().__init__()
@commands.hybrid_command(
name="ping",
description="Check if the bot is alive.",
)
async def ping(self, context):
return await ping_command()(self, context)
@commands.hybrid_command(
name="uptime",
description="Check how long the bot has been running.",
)
async def uptime(self, context):
return await uptime_command()(self, context)
@commands.hybrid_command(
name="botinfo",
description="Get some useful (or not) information about the bot.",
)
async def botinfo(self, context):
return await botinfo_command()(self, context)
@commands.hybrid_command(
name="serverinfo",
description="Get some useful (or not) information about the server.",
)
async def serverinfo(self, context):
return await serverinfo_command()(self, context)
@commands.hybrid_command(
name="feedback",
description="Submit a feedback for the owners of the bot"
)
async def feedback(self, context):
return await feedback_command()(self, context)
async def setup(bot) -> None:
cog = General(bot)
await bot.add_cog(cog)
bot.logger.info("Loaded extension 'general.ping'")
bot.logger.info("Loaded extension 'general.uptime'")
bot.logger.info("Loaded extension 'general.botinfo'")
bot.logger.info("Loaded extension 'general.serverinfo'")
bot.logger.info("Loaded extension 'general.feedback'")

View File

@@ -1,23 +1,13 @@
import platform
import discord
from discord.ext import commands
from discord.ext.commands import Context
class BotInfo(commands.Cog, name="botinfo"):
def __init__(self, bot) -> None:
self.bot = bot
def botinfo_command():
@commands.hybrid_command(
name="botinfo",
description="Get some useful (or not) information about the bot.",
)
async def botinfo(self, context: Context) -> None:
"""
Get some useful (or not) information about the bot.
:param context: The hybrid command context.
"""
async def botinfo(self, context):
embed = discord.Embed(
title="Syntrel Discord Bot",
color=0x7289DA,
@@ -36,6 +26,5 @@ class BotInfo(commands.Cog, name="botinfo"):
await context.interaction.response.send_message(embed=embed, ephemeral=True)
else:
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(BotInfo(bot))
return botinfo

View File

@@ -2,7 +2,6 @@ import discord
from discord import app_commands
from discord.ext import commands
class FeedbackForm(discord.ui.Modal, title="Feeedback"):
feedback = discord.ui.TextInput(
label="What do you think about this bot?",
@@ -17,20 +16,11 @@ class FeedbackForm(discord.ui.Modal, title="Feeedback"):
self.answer = str(self.feedback)
self.stop()
class Feedback(commands.Cog, name="feedback"):
def __init__(self, bot) -> None:
self.bot = bot
def feedback_command():
@app_commands.command(
name="feedback", description="Submit a feedback for the owners of the bot"
)
async def feedback(self, interaction: discord.Interaction) -> None:
"""
Submit a feedback for the owners of the bot.
:param interaction: The application command interaction.
"""
async def feedback(self, interaction: discord.Interaction):
feedback_form = FeedbackForm()
await interaction.response.send_modal(feedback_form)
@@ -53,7 +43,5 @@ class Feedback(commands.Cog, name="feedback"):
color=0x7289DA,
).set_author(name="Feedback System", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
)
async def setup(bot) -> None:
await bot.add_cog(Feedback(bot))
return feedback

View File

@@ -1,22 +1,12 @@
import discord
from discord.ext import commands
from discord.ext.commands import Context
class Ping(commands.Cog, name="ping"):
def __init__(self, bot) -> None:
self.bot = bot
def ping_command():
@commands.hybrid_command(
name="ping",
description="Check if the bot is alive.",
)
async def ping(self, context: Context) -> None:
"""
Check if the bot is alive.
:param context: The hybrid command context.
"""
async def ping(self, context):
embed = discord.Embed(
title="🏓 Pong!",
description=f"The bot latency is {round(self.bot.latency * 1000)}ms.",
@@ -31,7 +21,5 @@ class Ping(commands.Cog, name="ping"):
await inter.followup.send(embed=embed, ephemeral=True)
else:
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(Ping(bot))
return ping

View File

@@ -1,22 +1,13 @@
import discord
from discord.ext import commands
from discord.ext.commands import Context
class ServerInfo(commands.Cog, name="serverinfo"):
def __init__(self, bot) -> None:
self.bot = bot
def serverinfo_command():
@commands.hybrid_command(
name="serverinfo",
description="Get some useful (or not) information about the server.",
)
@commands.guild_only() # This decorator ensures the command only works in servers
async def serverinfo(self, context: Context) -> None:
"""
Get some useful (or not) information about the server.
:param context: The hybrid command context.
"""
# Additional check (though @commands.guild_only() should handle this)
@commands.guild_only()
async def serverinfo(self, context):
if context.guild is None:
await context.send("This command can only be used in a server, not in DMs!")
return
@@ -53,6 +44,5 @@ class ServerInfo(commands.Cog, name="serverinfo"):
await context.interaction.response.send_message(embed=embed, ephemeral=True)
else:
await context.send(embed=embed)
async def setup(bot) -> None:
await bot.add_cog(ServerInfo(bot))
return serverinfo

View File

@@ -1,7 +1,5 @@
import discord
from discord.ext import commands
from discord.ext.commands import Context
class UptimeView(discord.ui.View):
def __init__(self, bot):
@@ -18,21 +16,12 @@ class UptimeView(discord.ui.View):
embed.set_author(name="Uptime", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
await interaction.response.edit_message(embed=embed, view=self)
class Uptime(commands.Cog, name="uptime"):
def __init__(self, bot) -> None:
self.bot = bot
def uptime_command():
@commands.hybrid_command(
name="uptime",
description="Check how long the bot has been running.",
)
async def uptime(self, context: Context) -> None:
"""
Check how long the bot has been running.
:param context: The hybrid command context.
"""
async def uptime(self, context):
embed = discord.Embed(
title="Bot Uptime",
description=f"The bot has been running for **{self.bot.get_uptime()}**",
@@ -48,7 +37,5 @@ class Uptime(commands.Cog, name="uptime"):
await inter.followup.send(embed=embed, view=view, ephemeral=True)
else:
await context.send(embed=embed, view=view)
async def setup(bot) -> None:
await bot.add_cog(Uptime(bot))
return uptime