mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 03:40:11 +01:00
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:
2
bot.py
2
bot.py
@@ -90,7 +90,7 @@ class DiscordBot(commands.Bot):
|
|||||||
if os.path.exists(init_file):
|
if os.path.exists(init_file):
|
||||||
try:
|
try:
|
||||||
await self.load_extension(f"cogs.{folder}")
|
await self.load_extension(f"cogs.{folder}")
|
||||||
if folder != "fun":
|
if folder not in ["fun", "general"]:
|
||||||
self.logger.info(f"Loaded extension '{folder}'")
|
self.logger.info(f"Loaded extension '{folder}'")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exception = f"{type(e).__name__}: {e}"
|
exception = f"{type(e).__name__}: {e}"
|
||||||
|
|||||||
59
cogs/general/__init__.py
Normal file
59
cogs/general/__init__.py
Normal 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'")
|
||||||
@@ -1,23 +1,13 @@
|
|||||||
import platform
|
import platform
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
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(
|
@commands.hybrid_command(
|
||||||
name="botinfo",
|
name="botinfo",
|
||||||
description="Get some useful (or not) information about the bot.",
|
description="Get some useful (or not) information about the bot.",
|
||||||
)
|
)
|
||||||
async def botinfo(self, context: Context) -> None:
|
async def botinfo(self, context):
|
||||||
"""
|
|
||||||
Get some useful (or not) information about the bot.
|
|
||||||
|
|
||||||
:param context: The hybrid command context.
|
|
||||||
"""
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Syntrel Discord Bot",
|
title="Syntrel Discord Bot",
|
||||||
color=0x7289DA,
|
color=0x7289DA,
|
||||||
@@ -36,6 +26,5 @@ class BotInfo(commands.Cog, name="botinfo"):
|
|||||||
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
else:
|
else:
|
||||||
await context.send(embed=embed)
|
await context.send(embed=embed)
|
||||||
|
|
||||||
async def setup(bot) -> None:
|
return botinfo
|
||||||
await bot.add_cog(BotInfo(bot))
|
|
||||||
@@ -2,7 +2,6 @@ import discord
|
|||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
class FeedbackForm(discord.ui.Modal, title="Feeedback"):
|
class FeedbackForm(discord.ui.Modal, title="Feeedback"):
|
||||||
feedback = discord.ui.TextInput(
|
feedback = discord.ui.TextInput(
|
||||||
label="What do you think about this bot?",
|
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.answer = str(self.feedback)
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
def feedback_command():
|
||||||
class Feedback(commands.Cog, name="feedback"):
|
|
||||||
def __init__(self, bot) -> None:
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@app_commands.command(
|
@app_commands.command(
|
||||||
name="feedback", description="Submit a feedback for the owners of the bot"
|
name="feedback", description="Submit a feedback for the owners of the bot"
|
||||||
)
|
)
|
||||||
async def feedback(self, interaction: discord.Interaction) -> None:
|
async def feedback(self, interaction: discord.Interaction):
|
||||||
"""
|
|
||||||
Submit a feedback for the owners of the bot.
|
|
||||||
|
|
||||||
:param interaction: The application command interaction.
|
|
||||||
"""
|
|
||||||
feedback_form = FeedbackForm()
|
feedback_form = FeedbackForm()
|
||||||
await interaction.response.send_modal(feedback_form)
|
await interaction.response.send_modal(feedback_form)
|
||||||
|
|
||||||
@@ -53,7 +43,5 @@ class Feedback(commands.Cog, name="feedback"):
|
|||||||
color=0x7289DA,
|
color=0x7289DA,
|
||||||
).set_author(name="Feedback System", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
).set_author(name="Feedback System", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return feedback
|
||||||
async def setup(bot) -> None:
|
|
||||||
await bot.add_cog(Feedback(bot))
|
|
||||||
@@ -1,22 +1,12 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
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(
|
@commands.hybrid_command(
|
||||||
name="ping",
|
name="ping",
|
||||||
description="Check if the bot is alive.",
|
description="Check if the bot is alive.",
|
||||||
)
|
)
|
||||||
async def ping(self, context: Context) -> None:
|
async def ping(self, context):
|
||||||
"""
|
|
||||||
Check if the bot is alive.
|
|
||||||
|
|
||||||
:param context: The hybrid command context.
|
|
||||||
"""
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="🏓 Pong!",
|
title="🏓 Pong!",
|
||||||
description=f"The bot latency is {round(self.bot.latency * 1000)}ms.",
|
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)
|
await inter.followup.send(embed=embed, ephemeral=True)
|
||||||
else:
|
else:
|
||||||
await context.send(embed=embed)
|
await context.send(embed=embed)
|
||||||
|
|
||||||
|
return ping
|
||||||
async def setup(bot) -> None:
|
|
||||||
await bot.add_cog(Ping(bot))
|
|
||||||
|
|||||||
@@ -1,22 +1,13 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
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(
|
@commands.hybrid_command(
|
||||||
name="serverinfo",
|
name="serverinfo",
|
||||||
description="Get some useful (or not) information about the server.",
|
description="Get some useful (or not) information about the server.",
|
||||||
)
|
)
|
||||||
@commands.guild_only() # This decorator ensures the command only works in servers
|
@commands.guild_only()
|
||||||
async def serverinfo(self, context: Context) -> None:
|
async def serverinfo(self, context):
|
||||||
"""
|
|
||||||
Get some useful (or not) information about the server.
|
|
||||||
:param context: The hybrid command context.
|
|
||||||
"""
|
|
||||||
# Additional check (though @commands.guild_only() should handle this)
|
|
||||||
if context.guild is None:
|
if context.guild is None:
|
||||||
await context.send("This command can only be used in a server, not in DMs!")
|
await context.send("This command can only be used in a server, not in DMs!")
|
||||||
return
|
return
|
||||||
@@ -53,6 +44,5 @@ class ServerInfo(commands.Cog, name="serverinfo"):
|
|||||||
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
await context.interaction.response.send_message(embed=embed, ephemeral=True)
|
||||||
else:
|
else:
|
||||||
await context.send(embed=embed)
|
await context.send(embed=embed)
|
||||||
|
|
||||||
async def setup(bot) -> None:
|
return serverinfo
|
||||||
await bot.add_cog(ServerInfo(bot))
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ext.commands import Context
|
|
||||||
|
|
||||||
|
|
||||||
class UptimeView(discord.ui.View):
|
class UptimeView(discord.ui.View):
|
||||||
def __init__(self, bot):
|
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")
|
embed.set_author(name="Uptime", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
|
||||||
await interaction.response.edit_message(embed=embed, view=self)
|
await interaction.response.edit_message(embed=embed, view=self)
|
||||||
|
|
||||||
|
def uptime_command():
|
||||||
class Uptime(commands.Cog, name="uptime"):
|
|
||||||
def __init__(self, bot) -> None:
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
@commands.hybrid_command(
|
@commands.hybrid_command(
|
||||||
name="uptime",
|
name="uptime",
|
||||||
description="Check how long the bot has been running.",
|
description="Check how long the bot has been running.",
|
||||||
)
|
)
|
||||||
async def uptime(self, context: Context) -> None:
|
async def uptime(self, context):
|
||||||
"""
|
|
||||||
Check how long the bot has been running.
|
|
||||||
|
|
||||||
:param context: The hybrid command context.
|
|
||||||
"""
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Bot Uptime",
|
title="Bot Uptime",
|
||||||
description=f"The bot has been running for **{self.bot.get_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)
|
await inter.followup.send(embed=embed, view=view, ephemeral=True)
|
||||||
else:
|
else:
|
||||||
await context.send(embed=embed, view=view)
|
await context.send(embed=embed, view=view)
|
||||||
|
|
||||||
|
return uptime
|
||||||
async def setup(bot) -> None:
|
|
||||||
await bot.add_cog(Uptime(bot))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user