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 8216ced commit 32b4a9c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Module.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@
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.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 = importlib.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"))
def help_handler(client, message):
help_text = "Available commands:\n"
for command, description in cmds.items():
help_text += f"/{command} - {description}\n"
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,8 +6,14 @@

from pyrogram import Client, filters

from .help import add_cmd


def register(app: Client):
# Register the /start command
@app.on_message(filters.command("start"))
def start(client, message):
message.reply_text("womp womp")

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

0 comments on commit 32b4a9c

Please sign in to comment.