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