Added slash-commands to reload all cogs aswell as print general information

This commit is contained in:
2024-10-12 23:44:42 +02:00
parent 57282d9c56
commit 709f5df4db
8 changed files with 154 additions and 1 deletions
+45
View File
@@ -0,0 +1,45 @@
import discord
from discord import app_commands
from discord.ext import commands
from cogs.base_cog import Base_Cog
import logging
from utils.portal import Portal
class About_Command(Base_Cog):
def __init__(self, bot:commands.Bot):
self.__bot = bot
super().__init__(logging.getLogger("cmds.about"))
@app_commands.command(name = "about", description = "Provides general information about the bot")
async def about(self, ctx: discord.Interaction):
portal:Portal = Portal.instance()
embed = discord.Embed(title=f"POST IT - `{portal.PROGRAM_VERSION}`",
description="### Übersicht der Befehle\n- `/post` Veröffentlicht einen Post einer anderen Plattform, mit beliebigen Bildern als Anhang\n- `/help` Zeigt diese Übersicht an\n- `/settings` Persönliche Einstellungen für das verhalten des Bots\n- `/stats` Zeigt persönliche und globale Statistiken\n- `/debug` Erweiterte Informationen zum Betriebszustandes des Bots",
colour=0x5a5a5a)
embed.add_field(name="Status des Bots",
value="Fehlerfrei :green_circle:",
inline=True)
embed.add_field(name="Besitzer der Bot Instanz",
value=f"<@{portal.bot_config['DISCORD']['OWNER_ID']}>",
inline=True)
await ctx.response.send_message(embed = embed, ephemeral = True)
async def setup(bot:commands.Bot):
await bot.add_cog(About_Command(bot))
# class AddCog(commands.Cog):
# def __init__(self, bot):
# self.bot = bot
# @app_commands.command(name="add", description="Füge ein neues Wort zur Liste hinzu")
# async def add(self, interaction: discord.Interaction, new_word: str):
# if new_word.lower() not in self.bot.known_words:
# self.bot.known_words.append(new_word.lower())
# await interaction.response.send_message(f"Wort '{new_word}' wurde zur Liste hinzugefügt.")
# else:
# await interaction.response.send_message(f"Wort '{new_word}' existiert bereits.")
# async def setup(bot):
# await bot.add_cog(AddCog(bot))
+14
View File
@@ -0,0 +1,14 @@
import discord
from discord import app_commands
from discord.ext import commands
import logging
class Base_Cog(commands.Cog):
def __init__(self, logger:logging.Logger):
self._logger = logger
async def cog_load(self):
self._logger.debug(f"Cog for the '{self.__class__.__name__}' command got loaded")
async def cog_unload(self):
self._logger.debug(f"Cog for the '{self.__class__.__name__}' command got unloaded")
+25
View File
@@ -0,0 +1,25 @@
import discord
from discord import app_commands
from discord.ext import commands
from cogs.base_cog import Base_Cog
import logging
from datetime import datetime
class Reload_Command(Base_Cog):
def __init__(self, bot:commands.Bot):
self.__bot = bot
super().__init__(logging.getLogger("cmds.reload"))
@app_commands.command(name = "reload_all", description = "Reloads all cogs")
async def about(self, ctx: discord.Interaction):
self._logger.info("Reloading all cogs ...")
task_start = datetime.now().timestamp()
cog_names = list(self.__bot.extensions.keys())
for extension_name in cog_names:
await self.__bot.reload_extension(extension_name)
await ctx.response.send_message("Cogs successfully reloaded.")
async def setup(bot:commands.Bot):
await bot.add_cog(Reload_Command(bot))