Spaces:
Runtime error
Runtime error
File size: 2,262 Bytes
b4e11e9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | from hydrogram import filters
from hydrogram.types import Message
from bot import TelegramBot
from bot.config import Telegram
def is_allowed(uid: int) -> bool:
if Telegram.OWNER_ID and uid == Telegram.OWNER_ID:
return True
return uid in Telegram.ALLOWED_USER_IDS
@TelegramBot.on_message(filters.command("start"))
async def start_handler(_, m: Message):
uid = m.from_user.id if m.from_user else 0
if not is_allowed(uid):
return await m.reply_text("โ Not allowed. Contact owner.")
await m.reply_text(
"โ
Bot live.\n"
"Commands:\n"
"/ping\n"
"/id\n"
"/help\n\n"
"Ab normal msg bhejo, main reply dunga."
)
@TelegramBot.on_message(filters.command("help"))
async def help_handler(_, m: Message):
uid = m.from_user.id if m.from_user else 0
if not is_allowed(uid):
return await m.reply_text("โ Not allowed.")
await m.reply_text(
"โ
Help\n"
"/ping -> pong\n"
"/id -> your telegram id\n"
"Send any text -> echo + small talk reply"
)
@TelegramBot.on_message(filters.command("ping"))
async def ping_handler(_, m: Message):
uid = m.from_user.id if m.from_user else 0
if not is_allowed(uid):
return await m.reply_text("โ Not allowed.")
await m.reply_text("pong โ
")
@TelegramBot.on_message(filters.command("id"))
async def id_handler(_, m: Message):
uid = m.from_user.id if m.from_user else 0
await m.reply_text(f"Your ID: `{uid}`")
@TelegramBot.on_message(filters.text & ~filters.command(["start","help","ping","id"]))
async def talk_handler(_, m: Message):
uid = m.from_user.id if m.from_user else 0
if not is_allowed(uid):
return await m.reply_text("โ Not allowed.")
text = (m.text or "").strip()
if not text:
return
# ultra-simple โtalkingโ logic (safe, fast)
low = text.lower()
if any(x in low for x in ["hi", "hello", "hey"]):
return await m.reply_text("Haan bol ๐")
if "kaisa" in low or "kaisi" in low:
return await m.reply_text("Mast. Tu bata ๐")
if "bye" in low:
return await m.reply_text("Bye ๐")
# default echo-style reply
await m.reply_text(f"๐ฃ๏ธ You said: {text}") |