-
Notifications
You must be signed in to change notification settings - Fork 1
/
assistantdatabase.py
108 lines (90 loc) · 2.93 KB
/
assistantdatabase.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
import random
from AnonX import userbot
from AnonX.core.mongo import mongodb
db = mongodb.assistants
assistantdict = {}
async def get_client(assistant: int):
if int(assistant) == 1:
return userbot.one
elif int(assistant) == 2:
return userbot.two
elif int(assistant) == 3:
return userbot.three
elif int(assistant) == 4:
return userbot.four
elif int(assistant) == 5:
return userbot.five
async def set_assistant(chat_id):
from AnonX.core.userbot import assistants
ran_assistant = random.choice(assistants)
assistantdict[chat_id] = ran_assistant
await db.update_one(
{"chat_id": chat_id},
{"$set": {"assistant": ran_assistant}},
upsert=True,
)
userbot = await get_client(ran_assistant)
return userbot
async def get_assistant(chat_id: int) -> str:
from AnonX.core.userbot import assistants
assistant = assistantdict.get(chat_id)
if not assistant:
dbassistant = await db.find_one({"chat_id": chat_id})
if not dbassistant:
userbot = await set_assistant(chat_id)
return userbot
else:
got_assis = dbassistant["assistant"]
if got_assis in assistants:
assistantdict[chat_id] = got_assis
userbot = await get_client(got_assis)
return userbot
else:
userbot = await set_assistant(chat_id)
return userbot
else:
if assistant in assistants:
userbot = await get_client(assistant)
return userbot
else:
userbot = await set_assistant(chat_id)
return userbot
async def set_calls_assistant(chat_id):
from AnonX.core.userbot import assistants
ran_assistant = random.choice(assistants)
assistantdict[chat_id] = ran_assistant
await db.update_one(
{"chat_id": chat_id},
{"$set": {"assistant": ran_assistant}},
upsert=True,
)
return ran_assistant
async def group_assistant(self, chat_id: int) -> int:
from AnonX.core.userbot import assistants
assistant = assistantdict.get(chat_id)
if not assistant:
dbassistant = await db.find_one({"chat_id": chat_id})
if not dbassistant:
assis = await set_calls_assistant(chat_id)
else:
assis = dbassistant["assistant"]
if assis in assistants:
assistantdict[chat_id] = assis
assis = assis
else:
assis = await set_calls_assistant(chat_id)
else:
if assistant in assistants:
assis = assistant
else:
assis = await set_calls_assistant(chat_id)
if int(assis) == 1:
return self.one
elif int(assis) == 2:
return self.two
elif int(assis) == 3:
return self.three
elif int(assis) == 4:
return self.four
elif int(assis) == 5:
return self.five