refactor(botinfo): now seperate command

This commit is contained in:
neoarz
2025-10-09 00:24:43 -04:00
parent 71cb384ff3
commit 50af638e2d
4 changed files with 31 additions and 22 deletions

5
bot.py
View File

@@ -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 in ["owner", "help"]: if folder in ["owner", "help", "botinfo"]:
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}"
@@ -122,7 +122,8 @@ class DiscordBot(commands.Bot):
continue continue
try: try:
await self.load_extension(f"cogs.{extension}") await self.load_extension(f"cogs.{extension}")
self.logger.info(f"Loaded extension '{extension}'") if extension in ["owner", "help", "botinfo"]:
self.logger.info(f"Loaded extension '{extension}'")
except Exception as e: except Exception as e:
exception = f"{type(e).__name__}: {e}" exception = f"{type(e).__name__}: {e}"
self.logger.error( self.logger.error(

View File

@@ -1,13 +1,21 @@
import platform import platform
import discord import discord
from discord import app_commands
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): @app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
@app_commands.allowed_installs(guilds=True, users=True)
async def botinfo(self, context: Context) -> None:
embed = discord.Embed( embed = discord.Embed(
title="Syntrel Discord Bot", title="Syntrel Discord Bot",
color=0x7289DA, color=0x7289DA,
@@ -22,9 +30,11 @@ def botinfo_command():
value=f"/ (Slash Commands) or {self.bot.bot_prefix} for normal commands", value=f"/ (Slash Commands) or {self.bot.bot_prefix} for normal commands",
inline=False, inline=False,
) )
if getattr(context, "interaction", None): if context.interaction:
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)
return botinfo
async def setup(bot) -> None:
await bot.add_cog(BotInfo(bot))

View File

@@ -4,7 +4,6 @@ from discord.ext.commands import Context
from .ping import ping_command from .ping import ping_command
from .uptime import uptime_command from .uptime import uptime_command
from .botinfo import botinfo_command
from .serverinfo import serverinfo_command from .serverinfo import serverinfo_command
from .feedback import feedback_command from .feedback import feedback_command
@@ -32,7 +31,7 @@ class General(commands.GroupCog, name="general"):
color=0x7289DA color=0x7289DA
) )
embed.set_author(name="General", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp") embed.set_author(name="General", icon_url="https://yes.nighty.works/raw/y5SEZ9.webp")
embed.add_field(name="Available", value="ping, uptime, botinfo, serverinfo, feedback", inline=False) embed.add_field(name="Available", value="ping, uptime, serverinfo, feedback", inline=False)
await context.send(embed=embed) await context.send(embed=embed)
async def _invoke_hybrid(self, context: Context, name: str): async def _invoke_hybrid(self, context: Context, name: str):
@@ -50,10 +49,6 @@ class General(commands.GroupCog, name="general"):
async def general_group_uptime(self, context: Context): async def general_group_uptime(self, context: Context):
await self._invoke_hybrid(context, "uptime") await self._invoke_hybrid(context, "uptime")
@general_group.command(name="botinfo")
async def general_group_botinfo(self, context: Context):
await self._invoke_hybrid(context, "botinfo")
@general_group.command(name="serverinfo") @general_group.command(name="serverinfo")
async def general_group_serverinfo(self, context: Context): async def general_group_serverinfo(self, context: Context):
await self._invoke_hybrid(context, "serverinfo") await self._invoke_hybrid(context, "serverinfo")
@@ -78,14 +73,6 @@ class General(commands.GroupCog, name="general"):
async def uptime(self, context): async def uptime(self, context):
return await uptime_command()(self, context) return await uptime_command()(self, context)
@commands.check(_require_group_prefix)
@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.check(_require_group_prefix) @commands.check(_require_group_prefix)
@commands.hybrid_command( @commands.hybrid_command(
name="serverinfo", name="serverinfo",
@@ -108,6 +95,5 @@ async def setup(bot) -> None:
bot.logger.info("Loaded extension 'general.ping'") bot.logger.info("Loaded extension 'general.ping'")
bot.logger.info("Loaded extension 'general.uptime'") 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.serverinfo'")
bot.logger.info("Loaded extension 'general.feedback'") bot.logger.info("Loaded extension 'general.feedback'")

View File

@@ -79,6 +79,18 @@ class Help(commands.Cog, name="help"):
) )
embed.set_author(name="Help", icon_url="https://yes.nighty.works/raw/T9mnBO.png") embed.set_author(name="Help", icon_url="https://yes.nighty.works/raw/T9mnBO.png")
standalone_commands = []
botinfo_cmd = self.bot.tree.get_command("botinfo")
if botinfo_cmd:
standalone_commands.append("**/botinfo** » Get information about this bot")
if standalone_commands:
embed.add_field(
name="",
value="".join(standalone_commands) + "\n",
inline=False
)
available_categories = set() available_categories = set()
for cog_name in self.bot.cogs: for cog_name in self.bot.cogs:
mapped_category = category_mapping.get(cog_name.lower()) mapped_category = category_mapping.get(cog_name.lower())