forked from Devarora-0981/Mickey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
581 lines (522 loc) · 20.6 KB
/
main.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
#Don't remove This Line From Here. @Dev_Arora_0981 | @DevArora0981
#Github :- Devarora0981 | Devarora0987
import requests
import random
import os
import re
import asyncio
import time
from datetime import datetime
from pyrogram import Client, filters
from pyrogram.types import *
from config import *
from inline import *
from read import *
from pymongo import MongoClient
from motor.motor_asyncio import AsyncIOMotorClient as MongoCli
bot = Client(
"Mickey" ,
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
)
mongo = MongoCli(MONGO_URL)
db = mongo.Anonymous
chatsdb = db.chatsdb
usersdb = db.users
async def is_admins(chat_id: int):
return [
member.user.id
async for member in bot.iter_chat_members(
chat_id, filter="administrators"
)
]
PHOTO = [
START_IMG1,
START_IMG2,
START_IMG3,
START_IMG4,
START_IMG5,
START_IMG6,
START_IMG7,
START_IMG8,
START_IMG9,
START_IMG10,
]
EMOJIOS = [
"💣",
"💥",
"🪄",
"🧨",
"⚡",
"🤡",
"👻",
"🎃",
"🎩",
"🕊",
]
STICKER = [
STKR,
STKR1,
STKR2,
STKR3,
STKR4,
STKR5,
STKR6,
STKR7,
STKR8,
]
async def is_served_user(user_id: int) -> bool:
user = await usersdb.find_one({"user_id": user_id})
if not user:
return False
return True
async def get_served_users() -> list:
users_list = []
async for user in usersdb.find({"user_id": {"$gt": 0}}):
users_list.append(user)
return users_list
async def add_served_user(user_id: int):
is_served = await is_served_user(user_id)
if is_served:
return
return await usersdb.insert_one({"user_id": user_id})
async def get_served_chats() -> list:
chats = chatsdb.find({"chat_id": {"$lt": 0}})
if not chats:
return []
chats_list = []
for chat in await chats.to_list(length=1000000000):
chats_list.append(chat)
return chats_list
async def is_served_chat(chat_id: int) -> bool:
chat = await chatsdb.find_one({"chat_id": chat_id})
if not chat:
return False
return True
async def add_served_chat(chat_id: int):
is_served = await is_served_chat(chat_id)
if is_served:
return
return await chatsdb.insert_one({"chat_id": chat_id})
@bot.on_message(filters.command(["start", "aistart", f"start@{BOT_USERNAME}"]))
async def restart(client, m: Message):
if m.chat.type == "private":
accha = await m.reply_text(
text = random.choice(EMOJIOS),
)
await asyncio.sleep(1.3)
await accha.edit("__ᴅιиg ᴅσиg ꨄ︎ ѕтαятιиg..__")
await asyncio.sleep(0.2)
await accha.edit("__ᴅιиg ᴅσиg ꨄ sтαятιиg.....__")
await asyncio.sleep(0.2)
await accha.edit("__ᴅιиg ᴅσиg ꨄ︎ sтαятιиg..__")
await asyncio.sleep(0.2)
await accha.delete()
umm = await m.reply_sticker(sticker=random.choice(STICKER))
await asyncio.sleep(2)
await umm.delete()
await m.reply_photo(
photo = random.choice(PHOTO),
caption=f"""**๏ ʜᴇʏ, ɪ ᴀᴍ [{BOT_NAME}](t.me/{BOT_USERNAME})**\n**➻ ᴀɴ ᴀɪ ʙᴀsᴇᴅ ᴄʜᴀᴛʙᴏᴛ.**\n**──────────────**\n**➻ ᴜsᴀɢᴇ /chatbot [ᴏɴ/ᴏғғ]**\n<b>||๏ ʜɪᴛ ʜᴇʟᴘ ʙᴜᴛᴛᴏɴ ғᴏʀ ʜᴇʟᴘ||</b>""",
reply_markup=InlineKeyboardMarkup(DEV_OP),
)
await add_served_user(m.from_user.id)
else:
await m.reply_photo(
photo=random.choice(PHOTO),
caption=START,
reply_markup=InlineKeyboardMarkup(HELP_START),
)
await add_served_chat(m.chat.id)
@bot.on_callback_query()
async def cb_handler(Client, query: CallbackQuery):
vickdb = MongoClient(MONGO_URL)
vick = vickdb["VickDb"]["Vick"]
if query.data == "HELP":
await query.message.edit_text(
text = HELP_READ,
reply_markup=InlineKeyboardMarkup(HELP_BTN),
disable_web_page_preview=True,
)
elif query.data == "CLOSE":
await query.message.delete()
elif query.data == "BACK":
await query.message.edit(
text = START,
reply_markup=InlineKeyboardMarkup(DEV_OP),
)
elif query.data == "SOURCE":
await query.message.edit(
text = SOURCE_READ,
reply_markup = InlineKeyboardMarkup(BACK),
disable_web_page_preview = True,
)
elif query.data == "ABOUT":
await query.message.edit(
text = ABOUT_READ,
reply_markup = InlineKeyboardMarkup(ABOUT_BTN),
disable_web_page_preview=True,
)
elif query.data == "ADMINS":
await query.message.edit(
text = ADMIN_READ,
reply_markup = InlineKeyboardMarkup(MUSIC_BACK_BTN),
)
elif query.data== "TOOLS_DATA":
await query.message.edit(
text= TOOLS_DATA_READ,
reply_markup = InlineKeyboardMarkup(CHATBOT_BACK),
)
elif query.data == "BACK_HELP":
await query.message.edit(
text = HELP_READ,
reply_markup = InlineKeyboardMarkup(HELP_BTN),
)
elif query.data == "CHATBOT_CMD":
await query.message.edit(
text = CHATBOT_READ,
reply_markup = InlineKeyboardMarkup(CHATBOT_BACK),
)
elif query.data == "CHATBOT_BACK":
await query.message.edit(
text = HELP_READ,
reply_markup = InlineKeyboardMarkup(HELP_BTN),
)
elif query.data == "addchat":
if query.from_user.id not in (await is_admins(query.message.chat.id)):
return query.answer(
"You don't have permissions to do this baby.",
show_alert=True,
)
else:
is_vick = vick.find_one({"chat_id": query.message.chat.id})
if not is_vick:
await query.edit_message_text(f"**ᴄʜᴀᴛ-ʙᴏᴛ ᴀʟʀᴇᴀᴅʏ ᴇɴᴀʙʟᴇᴅ.**")
if is_vick:
vick.delete_one({"chat_id": query.message.chat.id})
await query.edit_message_text(f"**ᴄʜᴀᴛ-ʙᴏᴛ ᴇɴᴀʙʟᴇᴅ ʙʏ** {query.from_user.mention}.")
elif query.data == "rmchat":
if query.from_user.id not in (await is_admins(query.message.chat.id)):
return query.answer(
"**ʏᴏᴜ ᴅᴏɴ'ᴛ ʜᴀᴠᴇ ᴘᴇʀᴍs ᴛᴏ ᴅᴏ ᴛʜɪs ʙᴀʙʏ!**",
show_alert=True,
)
else:
is_vick = vick.find_one({"chat_id": query.message.chat.id})
if not is_vick:
vick.insert_one({"chat_id": query.message.chat.id})
await query.edit_message_text(f"**ᴄʜᴀᴛ-ʙᴏᴛ ᴅɪsᴀʙʟᴇᴅ ʙʏ** {query.from_user.mention}.")
if is_vick:
await query.edit_message_text("**ᴄʜᴀᴛ-ʙᴏᴛ ᴀʟʀᴇᴀᴅʏ ᴅɪsᴀʙʟᴇᴅ.**")
@bot.on_message(filters.command("repo"))
async def repo(client, message):
await message.reply_text(
text=SOURCE_READ,
reply_markup=InlineKeyboardMarkup(CLOSE_BTN),
disable_web_page_preview=True,
)
@bot.on_message(filters.command("id"))
async def getid(client, message):
chat = message.chat
your_id = message.from_user.id
message_id = message.message_id
reply = message.reply_to_message
text = f"**ᴍᴇssᴀɢᴇ ɪᴅ:** `{message_id}`\n"
text += f"**ʏᴏᴜʀ ɪᴅ:** `{your_id}`\n"
if not message.command:
message.command = message.text.split()
if not message.command:
message.command = message.text.split()
if len(message.command) == 2:
try:
split = message.text.split(None, 1)[1].strip()
user_id = (await client.get_users(split)).id
text += f"**ᴜsᴇʀ ɪᴅ:** `{user_id}`\n"
except Exception:
return await message.reply_text("ᴛʜɪs ᴜsᴇʀ ᴅᴏᴇsɴ'ᴛ ᴇxɪsᴛ.", quote=True)
text += f"**ᴄʜᴀᴛ ɪᴅ:** `{chat.id}`\n\n"
if (
not getattr(reply, "empty", True)
and not message.forward_from_chat
and not reply.sender_chat
):
text += f"**ʀᴇᴘʟɪᴇᴅ ᴍᴇssᴀɢᴇ ɪᴅ:** `{reply.message_id}`\n"
text += f"**ʀᴇᴘʟɪᴇᴅ ᴜsᴇʀ ɪᴅ:** `{reply.from_user.id}`\n\n"
if reply and reply.forward_from_chat:
text += f"ᴛʜᴇ ғᴏʀᴡᴀʀᴅᴇᴅ ᴄʜᴀɴɴᴇʟ, {reply.forward_from_chat.title}, ʜᴀs ᴀɴ ɪᴅ ᴏғ `{reply.forward_from_chat.id}`\n\n"
print(reply.forward_from_chat)
if reply and reply.sender_chat:
text += f"ɪᴅ ᴏғ ᴛʜᴇ ʀᴇᴘʟɪᴇᴅ ᴄʜᴀᴛ/ᴄʜᴀɴɴᴇʟ, ɪs `{reply.sender_chat.id}`"
print(reply.sender_chat)
await message.reply_text(
text,
disable_web_page_preview=True,
parse_mode="md",
)
@bot.on_message(filters.command(["help", f"help@{BOT_USERNAME}"], prefixes=["+", ".", "/", "-", "?", "$"]))
async def restart(client, m: Message):
if m.chat.type == "private":
hmm = await m.reply_photo(
photo=random.choice(PHOTO),
caption=HELP_READ,
reply_markup=InlineKeyboardMarkup(HELP_BTN),
)
await add_served_user(m.from_user.id)
else:
await m.reply_photo(
photo=random.choice(PHOTO),
caption="**ʜᴇʏ, ᴘᴍ ᴍᴇ ғᴏʀ ʜᴇʟᴘ ᴄᴏᴍᴍᴀɴᴅs!**",
reply_markup=InlineKeyboardMarkup(HELP_BUTN),
)
await add_served_chat(m.chat.id)
@bot.on_message(filters.new_chat_members)
async def welcome(client, message: Message):
for member in message.new_chat_members:
await message.reply_photo(photo = random.choice(PHOTO),
caption = START)
@bot.on_message(filters.command("stats") & filters.user(OWNER_ID))
async def get_st(_, msg: Message):
users = len(await get_served_users())
chats = len(await get_served_chats())
await msg.reply_photo(
photo="https://te.legra.ph/file/2d5b054acddf865d4d83e.png",
caption=f"ᴛᴏᴛᴀʟ sᴛᴀᴛs ᴏғ {BOT_NAME}\n\n➻ **ᴄʜᴀᴛs :** {chats}\n➻ **ᴜsᴇʀs :** {users}",
)
@bot.on_message(filters.command("ping", prefixes=["+", "/", "-", "?", "$", "&"]))
async def ping(client, message: Message):
if message.chat.type == "private":
await add_served_user(message.from_user.id)
else:
await add_served_chat(message.chat.id)
await message.delete()
start = datetime.now()
wtfbhemchomd = await message.reply_sticker(sticker= random.choice(STICKER))
ms = (datetime.now()-start).microseconds / 1000
await message.reply_photo(
photo=random.choice(PHOTO),
caption=f"нey вαву!!\n**[{BOT_NAME}](t.me/{BOT_USERNAME})** ιѕ alιve 🥀 αnd worĸιng ғιne wιтн a pιng oғ\n➥ `{ms}` ms\n\n<b>||мαdє ωιтн ❣️ ву [Developer](https://t.me/{OWNER_USERNAME})||</b>",
reply_markup=InlineKeyboardMarkup(PNG_BTN),
)
@bot.on_message(
filters.command(["chatbot", f"chatbot@{BOT_USERNAME}"])
& ~filters.private)
async def chatonoff(client: Client, message: Message):
if not message.from_user:
return
else:
user = message.from_user.id
chat_id = message.chat.id
if user not in (await is_admins(chat_id)):
return await message.reply_text(
"**ʏᴏᴜ ᴀʀᴇ'ɴᴛ ᴀɴ ᴀᴅᴍɪɴ.**"
)
else:
await message.reply_text(
text="» <u>**ᴄʜᴏᴏsᴇ ᴀɴ ᴏᴩᴛɪᴏɴ ᴛᴏ ᴇɴᴀʙʟᴇ/ᴅɪsᴀʙʟᴇ ᴄʜᴀᴛʙᴏᴛ.**</u>",
reply_markup=InlineKeyboardMarkup(CHATBOT_ON),
)
@bot.on_message(
(
filters.text
| filters.sticker
)
& ~filters.private
& ~filters.bot,
)
async def vickai(client: Client, message: Message):
chatdb = MongoClient(MONGO_URL)
chatai = chatdb["Word"]["WordDb"]
if not message.reply_to_message:
vickdb = MongoClient(MONGO_URL)
vick = vickdb["VickDb"]["Vick"]
is_vick = vick.find_one({"chat_id": message.chat.id})
if not is_vick:
await bot.send_chat_action(message.chat.id, "typing")
K = []
is_chat = chatai.find({"word": message.text})
k = chatai.find_one({"word": message.text})
if k:
for x in is_chat:
K.append(x['text'])
hey = random.choice(K)
is_text = chatai.find_one({"text": hey})
Yo = is_text['check']
if Yo == "sticker":
await message.reply_sticker(f"{hey}")
if not Yo == "sticker":
await message.reply_text(f"{hey}")
if message.reply_to_message:
vickdb = MongoClient(MONGO_URL)
vick = vickdb["VickDb"]["Vick"]
is_vick = vick.find_one({"chat_id": message.chat.id})
getme = await bot.get_me()
bot_id = getme.id
if message.reply_to_message.from_user.id == bot_id:
if not is_vick:
await bot.send_chat_action(message.chat.id, "typing")
K = []
is_chat = chatai.find({"word": message.text})
k = chatai.find_one({"word": message.text})
if k:
for x in is_chat:
K.append(x['text'])
hey = random.choice(K)
is_text = chatai.find_one({"text": hey})
Yo = is_text['check']
if Yo == "sticker":
await message.reply_sticker(f"{hey}")
if not Yo == "sticker":
await message.reply_text(f"{hey}")
if not message.reply_to_message.from_user.id == bot_id:
if message.sticker:
is_chat = chatai.find_one({"word": message.reply_to_message.text, "id": message.sticker.file_unique_id})
if not is_chat:
chatai.insert_one({"word": message.reply_to_message.text, "text": message.sticker.file_id, "check": "sticker", "id": message.sticker.file_unique_id})
if message.text:
is_chat = chatai.find_one({"word": message.reply_to_message.text, "text": message.text})
if not is_chat:
chatai.insert_one({"word": message.reply_to_message.text, "text": message.text, "check": "none"})
@bot.on_message(
(
filters.sticker
| filters.text
)
& ~filters.private
& ~filters.bot,
)
async def vickstickerai(client: Client, message: Message):
chatdb = MongoClient(MONGO_URL)
chatai = chatdb["Word"]["WordDb"]
if not message.reply_to_message:
vickdb = MongoClient(MONGO_URL)
vick = vickdb["VickDb"]["Vick"]
is_vick = vick.find_one({"chat_id": message.chat.id})
if not is_vick:
await bot.send_chat_action(message.chat.id, "typing")
K = []
is_chat = chatai.find({"word": message.sticker.file_unique_id})
k = chatai.find_one({"word": message.text})
if k:
for x in is_chat:
K.append(x['text'])
hey = random.choice(K)
is_text = chatai.find_one({"text": hey})
Yo = is_text['check']
if Yo == "text":
await message.reply_text(f"{hey}")
if not Yo == "text":
await message.reply_sticker(f"{hey}")
if message.reply_to_message:
vickdb = MongoClient(MONGO_URL)
vick = vickdb["VickDb"]["Vick"]
is_vick = vick.find_one({"chat_id": message.chat.id})
getme = await bot.get_me()
bot_id = getme.id
if message.reply_to_message.from_user.id == bot_id:
if not is_vick:
await bot.send_chat_action(message.chat.id, "typing")
K = []
is_chat = chatai.find({"word": message.text})
k = chatai.find_one({"word": message.text})
if k:
for x in is_chat:
K.append(x['text'])
hey = random.choice(K)
is_text = chatai.find_one({"text": hey})
Yo = is_text['check']
if Yo == "text":
await message.reply_text(f"{hey}")
if not Yo == "text":
await message.reply_sticker(f"{hey}")
if not message.reply_to_message.from_user.id == bot_id:
if message.text:
is_chat = chatai.find_one({"word": message.reply_to_message.sticker.file_unique_id, "text": message.text})
if not is_chat:
toggle.insert_one({"word": message.reply_to_message.sticker.file_unique_id, "text": message.text, "check": "text"})
if message.sticker:
is_chat = chatai.find_one({"word": message.reply_to_message.sticker.file_unique_id, "text": message.sticker.file_id})
if not is_chat:
chatai.insert_one({"word": message.reply_to_message.sticker.file_unique_id, "text": message.sticker.file_id, "check": "none"})
@bot.on_message(
(
filters.text
| filters.sticker
)
& filters.private
& ~filters.bot,
)
async def vickprivate(client: Client, message: Message):
chatdb = MongoClient(MONGO_URL)
chatai = chatdb["Word"]["WordDb"]
if not message.reply_to_message:
await bot.send_chat_action(message.chat.id, "typing")
K = []
is_chat = chatai.find({"word": message.text})
for x in is_chat:
K.append(x['text'])
hey = random.choice(K)
is_text = chatai.find_one({"text": hey})
Yo = is_text['check']
if Yo == "sticker":
await message.reply_sticker(f"{hey}")
if not Yo == "sticker":
await message.reply_text(f"{hey}")
if message.reply_to_message:
getme = await bot.get_me()
bot_id = getme.id
if message.reply_to_message.from_user.id == bot_id:
await bot.send_chat_action(message.chat.id, "typing")
K = []
is_chat = chatai.find({"word": message.text})
for x in is_chat:
K.append(x['text'])
hey = random.choice(K)
is_text = chatai.find_one({"text": hey})
Yo = is_text['check']
if Yo == "sticker":
await message.reply_sticker(f"{hey}")
if not Yo == "sticker":
await message.reply_text(f"{hey}")
@bot.on_message(
(
filters.sticker
| filters.text
)
& filters.private
& ~filters.bot,
)
async def vickprivatesticker(client: Client, message: Message):
chatdb = MongoClient(MONGO_URL)
chatai = chatdb["Word"]["WordDb"]
if not message.reply_to_message:
await bot.send_chat_action(message.chat.id, "typing")
K = []
is_chat = chatai.find({"word": message.sticker.file_unique_id})
for x in is_chat:
K.append(x['text'])
hey = random.choice(K)
is_text = chatai.find_one({"text": hey})
Yo = is_text['check']
if Yo == "text":
await message.reply_text(f"{hey}")
if not Yo == "text":
await message.reply_sticker(f"{hey}")
if message.reply_to_message:
getme = await bot.get_me()
bot_id = getme.id
if message.reply_to_message.from_user.id == bot_id:
await bot.send_chat_action(message.chat.id, "typing")
K = []
is_chat = chatai.find({"word": message.sticker.file_unique_id})
for x in is_chat:
K.append(x['text'])
hey = random.choice(K)
is_text = chatai.find_one({"text": hey})
Yo = is_text['check']
if Yo == "text":
await message.reply_text(f"{hey}")
if not Yo == "text":
await message.reply_sticker(f"{hey}")
print(f"{BOT_NAME} ɪs ᴀʟɪᴠᴇ! ɴᴏᴡ ғᴜᴄᴋ ᴏғғ! ᴀɴᴅ ɢᴏ ᴛᴏ @Wᴇ_ʀғʀɪᴇɴᴅs ʙɪᴛᴄʜ!!")
bot.run()