Files
Ultroid-fork/plugins/chat_bot.py
1Danish-00 386eff647c v0.0.9 18/07/2021
Co-authored-by: New-dev0 <New-dev0@users.noreply.github.com>
Co-authored-by: Aditya <me@xditya.me>
Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com>
Co-authored-by: sppidy <sppidy@users.noreply.github.com>
Co-authored-by: Arnab Paryali <Arnabxd@users.noreply.github.com>
Co-authored-by: divkix <divkix@users.noreply.github.com>
Co-authored-by: hellboi_atul <hellboi-atul@users.noreply.github.com>
Co-authored-by: Programming Error <error@notavailable.live>
2021-07-18 17:47:15 +05:30

89 lines
2.5 KiB
Python

# Ultroid - UserBot
# Copyright (C) 2020 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.all import get_chatbot_reply
from pyUltroid.functions.chatBot_db import *
@ultroid_cmd(pattern="repai")
async def im_lonely_chat_with_me(event):
if event.reply_to_msg_id:
message = (await event.get_reply_message()).message
else:
try:
message = event.text.split(" ", 1)[1]
except IndexError:
return await eod(
event, "Give a message or Reply to a User's Message.", time=10
)
reply_ = get_chatbot_reply(event, message=message)
await eor(event, 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):
users = get_all_added()
if udB.get("CHATBOT_USERS") is None:
return await eod(event, "`No user has AI added.`")
msg = ""
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 eor(event, msg, link_preview=False)
async def chat_bot_fn(event, type_):
if event.reply_to_msg_id:
user = (await event.get_reply_message()).sender
else:
temp = event.text.split(" ", 1)
try:
usr = temp[1]
except IndexError:
return await eod(
event,
"Reply to a user or give me his id/username to add an AI ChatBot!",
)
user = await event.client.get_entity(usr)
if type_ == "add":
add_chatbot(user.id)
if type_ == "remov":
rem_chatbot(user.id)
await eor(
event, f"**ChatBot:**\n{type_}ed [{user.first_name}](tg://user?id={user.id})`"
)