forked from TeamUltroid/Ultroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatbot.py
89 lines (74 loc) · 2.63 KB
/
chatbot.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
# Ultroid - UserBot
# Copyright (C) 2021-2023 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
from . import get_help
__doc__ = get_help("help_chatbot")
from pyUltroid.fns.tools import get_chatbot_reply
from . import LOGS, eod, get_string, inline_mention, udB, ultroid_cmd
@ultroid_cmd(pattern="repai")
async def im_lonely_chat_with_me(event):
if event.reply_to:
message = (await event.get_reply_message()).message
else:
try:
message = event.text.split(" ", 1)[1]
except IndexError:
return await eod(event, get_string("tban_1"), time=10)
reply_ = await get_chatbot_reply(message=message)
await event.eor(reply_)
@ultroid_cmd(pattern="addai")
async def add_chatBot(event):
await chat_bot_fn(event, type_="add")
@ultroid_cmd(pattern="remai")
async def rem_chatBot(event):
await chat_bot_fn(event, type_="remov")
@ultroid_cmd(pattern="listai")
async def lister(event):
key = udB.get_key("CHATBOT_USERS") or {}
users = key.get(event.chat_id, [])
if not users:
return await event.eor(get_string("chab_2"), time=5)
msg = "**Total List Of AI Enabled Users In This Chat :**\n\n"
for i in users:
try:
user = await event.client.get_entity(int(i))
user = inline_mention(user)
except BaseException:
user = f"`{i}`"
msg += f"• {user}\n"
await event.eor(msg, link_preview=False)
async def chat_bot_fn(event, type_):
if event.reply_to:
user_ = (await event.get_reply_message()).sender
else:
temp = event.text.split(maxsplit=1)
try:
user_ = await event.client.get_entity(await event.client.parse_id(temp[1]))
except BaseException as er:
LOGS.exception(er)
user_ = event.chat if event.is_private else None
if not user_:
return await eod(
event,
get_string("chab_1"),
)
key = udB.get_key("CHATBOT_USERS") or {}
chat = event.chat_id
user = user_.id
if type_ == "add":
if key.get(chat):
if user not in key[chat]:
key[chat].append(user)
else:
key.update({chat: [user]})
elif type_ == "remov":
if key.get(chat):
if user in key[chat]:
key[chat].remove(user)
if chat in key and not key[chat]:
del key[chat]
udB.set_key("CHATBOT_USERS", key)
await event.eor(f"**ChatBot:**\n{type_}ed {inline_mention(user_)}")