-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathmain.py
More file actions
81 lines (62 loc) · 2.41 KB
/
main.py
File metadata and controls
81 lines (62 loc) · 2.41 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
import os
import random
import asyncio
import time
from datetime import datetime
from pymongo import MongoClient # ✅ REQUIRED
from pyrogram import Client, filters, enums
from pyrogram.types import *
from pyrogram.errors import ChatAdminRequired, UserNotParticipant
from pyrogram.enums import ChatAction
mongo = MongoClient(MONGO_URL)
vickdb = mongo["VickDb"]["Vick"]
chatai = mongo["Word"]["WordDb"]
async def is_admin(chat_id: int, user_id: int):
async for member in BRANDEDCHAT.get_chat_members(
chat_id, filter=enums.ChatMembersFilter.ADMINISTRATORS
):
if member.user.id == user_id:
return True
return False
@BRANDEDCHAT.on_message(filters.command("chatbot on") & ~filters.private)
async def chatbot_on(_, message: Message):
if not await is_admin(message.chat.id, message.from_user.id):
return await message.reply_text("❌ You are not admin")
if not vickdb.find_one({"chat_id": message.chat.id}):
return await message.reply_text("✅ Chatbot already enabled")
vickdb.delete_one({"chat_id": message.chat.id})
await message.reply_text("✅ Chatbot enabled")
@BRANDEDCHAT.on_message(filters.command("chatbot off") & ~filters.private)
async def chatbot_off(_, message: Message):
if not await is_admin(message.chat.id, message.from_user.id):
return await message.reply_text("❌ You are not admin")
if vickdb.find_one({"chat_id": message.chat.id}):
return await message.reply_text("⚠️ Chatbot already disabled")
vickdb.insert_one({"chat_id": message.chat.id})
await message.reply_text("🚫 Chatbot disabled")
@BRANDEDCHAT.on_message(filters.text & ~filters.private & ~filters.bot)
async def ai_text(_, message: Message):
if vickdb.find_one({"chat_id": message.chat.id}):
return
data = list(chatai.find({"word": message.text}))
if not data:
return
reply = random.choice(data)
if reply.get("check") == "sticker":
await message.reply_sticker(reply["text"])
else:
await message.reply_text(reply["text"])
# ❌ OLD (BROKEN)
toggle.insert_one(...)
# ✅ FIX
chatai.insert_one(...)
@BRANDEDCHAT.on_message(filters.command("start"))
async def start(_, message: Message):
await message.reply_photo(
photo=START_IMG,
caption=START,
reply_markup=InlineKeyboardMarkup(MAIN)
)
if __name__ == "__main__":
print(f"{BOT_NAME} is alive")
BRANDEDCHAT.run()