Spaces:
Runtime error
Runtime error
Create handlers.py
Browse files- bot/handlers.py +31 -0
bot/handlers.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PATH: bot/handlers.py
|
| 2 |
+
from hydrogram import Client, filters
|
| 3 |
+
from hydrogram.types import Message
|
| 4 |
+
from bot.config import Telegram
|
| 5 |
+
|
| 6 |
+
def setup_handlers(app: Client) -> None:
|
| 7 |
+
@app.on_message(filters.command(["start"]))
|
| 8 |
+
async def start_handler(_: Client, m: Message):
|
| 9 |
+
await m.reply_text(
|
| 10 |
+
"✅ Online.\n"
|
| 11 |
+
"Commands:\n"
|
| 12 |
+
"/ping\n"
|
| 13 |
+
"/me\n"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
@app.on_message(filters.command(["ping"]))
|
| 17 |
+
async def ping_handler(_: Client, m: Message):
|
| 18 |
+
await m.reply_text("🏓 Pong!")
|
| 19 |
+
|
| 20 |
+
@app.on_message(filters.command(["me"]))
|
| 21 |
+
async def me_handler(_: Client, m: Message):
|
| 22 |
+
uid = m.from_user.id if m.from_user else None
|
| 23 |
+
await m.reply_text(f"👤 Your ID: `{uid}`", quote=True)
|
| 24 |
+
|
| 25 |
+
@app.on_message(filters.private & filters.text & ~filters.command(["start", "ping", "me"]))
|
| 26 |
+
async def echo_handler(_: Client, m: Message):
|
| 27 |
+
# Normal simple reply bot
|
| 28 |
+
txt = (m.text or "").strip()
|
| 29 |
+
if not txt:
|
| 30 |
+
return
|
| 31 |
+
await m.reply_text(f"🗣 You said: {txt}")
|