Skip to content

Commit

Permalink
modules: Implement /help command
Browse files Browse the repository at this point in the history
  • Loading branch information
pranayadmn committed Jul 24, 2024
1 parent 817790b commit 49d250b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

import importlib
import logging
import os
from importlib import import_module

log: logging.Logger = logging.getLogger(__name__)


def load_modules(app):
module_dir = os.path.join(os.path.dirname(__file__), "modules")
for filename in os.listdir(module_dir):
if filename.endswith(".py"):
if filename.endswith(".py") and filename != "help.py":
module_name = filename[:-3]
try:
log.info(f"Loading module: {module_name}")
module = importlib.import_module(f"src.modules.{module_name}")
module = import_module(f"src.modules.{module_name}")
module.register(app)
except Exception as e:
log.error(f"Error loading module {module_name}: {e}")

# Load the help module after other modules
try:
log.info("Loading help module")
help_module = import_module("src.modules.help")
help_module.register(app)
except Exception as e:
log.error(f"Error loading help module: {e}")
25 changes: 25 additions & 0 deletions src/modules/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 StatiXOS
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

from pyrogram import Client, filters

# This dictionary will store commands and their descriptions
cmds = {}


def register(app):
# Register the /help command
@app.on_message(filters.command("help"))
async def help_handler(client, message):
help_text = "Available commands:\n"
for command, description in cmds.items():
help_text += f"/{command}: {description}\n"
await message.reply_text(help_text)


def add_cmd(cmd, desc):
"""Add command to the help module."""
cmds[cmd] = desc
6 changes: 6 additions & 0 deletions src/modules/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@

from pyrogram import Client, filters

from .help import add_cmd


def register(app: Client):
# Register the /start command
@app.on_message(filters.command("start"))
async def start(client, message):
await message.reply_text(
"'Ssup! What would you like me to do?\nUse /help to get a list of all commands and their usage."
)

# Register this command with the help module
add_cmd("start", "Starts the bot.")

0 comments on commit 49d250b

Please sign in to comment.