Co-authored-by: Aditya <xditya@ultroid.tech> Co-authored-by: Danish <danish@ultroid.tech> Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com> Co-authored-by: TechiError <error@notavailable.live> Co-authored-by: Avish Kumar <85635883+aviskumar@users.noreply.github.com> Co-authored-by: Vɪɴᴀʏᴀᴋ Pᴀɴᴅᴇʏ <87496159+harpia-vieillot@users.noreply.github.com> Co-authored-by: Shrimadhav U K <6317196+spechide@users.noreply.github.com> Co-authored-by: Dark <darkbeamer.official@gmail.com> Co-authored-by: Muhamad Risman Aziz <62795826+mrismanaziz@users.noreply.github.com> Co-authored-by: Ashik Muhammed <84127769+MR-JINN-OF-TG@users.noreply.github.com> Co-authored-by: MMETMA <79155572+MMETMA@users.noreply.github.com> Co-authored-by: amirmehdinzri <94852182+amirmehdinzri@users.noreply.github.com>
100 lines
2.9 KiB
Python
100 lines
2.9 KiB
Python
# Ultroid - UserBot
|
|
# Copyright (C) 2021-2022 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/>.
|
|
"""
|
|
✘ Commands Available -
|
|
|
|
• `{i}addai <reply to user/give username/userid>`
|
|
Add a AI ChatBot to reply to that user.
|
|
|
|
• `{i}remai <reply to user/give username/userid>`
|
|
Remove the AI ChatBot.
|
|
|
|
• `{i}repai <reply to user/give a message>`
|
|
Reply to the user with a message by an AI.
|
|
|
|
• `{i}listai`
|
|
List the currently AI added users.
|
|
"""
|
|
|
|
from pyUltroid.functions.tools import get_chatbot_reply
|
|
|
|
from . import 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 += "• {}\n".format(user)
|
|
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(temp[1])
|
|
except BaseException:
|
|
if event.is_private:
|
|
user_ = event.chat
|
|
else:
|
|
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", str(key))
|
|
await event.eor(f"**ChatBot:**\n{type_}ed {inline_mention(user_)}")
|