quantumlyconfused / qcadmin-discord-bot

Discord Bot framework and loadable cogs
https://blog.quantumlyconfused.com/
MIT License
3 stars 0 forks source link

[Feature] toggle for which cogs to automatically start #1

Closed padraignix closed 1 week ago

padraignix commented 1 week ago

While there are load/unload cog commands once started, it would be nice to have a blank slate when loading. Load no cogs by default, but also provide optional variables to chose which cogs to load on start.

For the Ptero cogs (most recent one we are working on) - something like

- PTERO_ACTIVE=true

Loading the ptero cog on start.


This behaviour would avoid default failures and ensure a cleaner startup process.

Log file created at: /app/quantumly_confused_bot.log
QCAdmin initialized
Loading cogs...
2024-11-11 03:40:03,225:INFO:quantumly_confused_bot_log: Loading cogs from ['grafana_discord_integration', 'rcon_commands', 'qc_status', 'quantum_pterodactyl']
Failed to load cogs.grafana_discord_integration.grafana_discord_integration, Extension 'cogs.grafana_discord_integration.grafana_discord_integration' raised an error: FileNotFoundError: [Errno 2] No such file or directory: '.\\grafana_dash_json_modal.json'
2024-11-11 03:40:03,228:ERROR:quantumly_confused_bot_log: Failed to load cogs.grafana_discord_integration.grafana_discord_integration, Extension 'cogs.grafana_discord_integration.grafana_discord_integration' raised an error: FileNotFoundError: [Errno 2] No such file or directory: '.\\grafana_dash_json_modal.json'
Failed to load cogs.rcon_commands.qc_rcon_commands, Extension 'cogs.rcon_commands.qc_rcon_commands' raised an error: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
2024-11-11 03:40:03,232:ERROR:quantumly_confused_bot_log: Failed to load cogs.rcon_commands.qc_rcon_commands, Extension 'cogs.rcon_commands.qc_rcon_commands' raised an error: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
2024-11-11 03:40:03,233:INFO:quantumly_confused_bot_log: Initalizing QuantumlyConfusedStatusCog
2024-11-11 03:40:03,233:INFO:quantumly_confused_bot_log: Loaded cogs.qc_status.qc_status successfully.
2024-11-11 03:40:03,234:INFO:quantumly_confused_bot_log: Cog loaded: QuantumPterodactyl v0.1
2024-11-11 03:40:03,234:INFO:quantumly_confused_bot_log: Loaded cogs.quantum_pterodactyl.quantum_pterodactyl successfully.
Finished loading cogs
padraignix commented 1 week ago

Further discussion with @ropeadope62 - going to adjust this to not have any cogs loaded by default, avoiding additional variable introduction, and letting individuals use /cog commands to load whichever cogs wanted.

ropeadope62 commented 1 week ago

I addressed this by removing the code to run the QCAdmin.load_cogs method on bot start. commit https://github.com/quantumlyconfused/qcadmin-discord-bot/commit/141735f7ed54de4fbb560602162c8a101747b56c

async def main():
    bot = commands.Bot(command_prefix="/", intents=intents)
    qc_admin = QCAdmin(bot)
    bot.logger = qc_admin.logger
    **await qc_admin.load_cogs()** # Removed, 
    await bot.add_cog(qc_admin)
    await bot.start(os.getenv('DISCORD_API_TOKEN'))

Cogs can be loaded and unloaded as needed with QCAdmin.load_cog which will load cogs by name.

I propose we keep QCAdmin.load_cogs for now, to repurpose into a command to load all available cog. (Remove any references to cog names, simply detect all available cogs and load them. )

ropeadope62 commented 1 week ago

Cogs are no longer automatically loading when the bot client is started. I will create another issue to make required changes for QCAdmin.load_cogs.

ropeadope62 commented 1 week ago

Done