TheHamkerCat пре 5 година
родитељ
комит
7c8debd70c
3 измењених фајлова са 62 додато и 1 уклоњено
  1. 1 0
      sample_config.py
  2. 1 1
      wbb/__init__.py
  3. 60 0
      wbb/modules/chatbot.py

+ 1 - 0
sample_config.py

@@ -17,3 +17,4 @@ captcha_delay_in_seconds = 300
 
 # Leave This As It Is
 ARQ_API_BASE_URL = "https://thearq.tech/"
+LUNA_API = "https://lunabot.tech/?query="

+ 1 - 1
wbb/__init__.py

@@ -3,7 +3,7 @@ from config import (
         sudo_users_id as SUDO_USER_ID, log_group_id as LOG_GROUP_ID,
         fernet_encryption_key as FERNET_ENCRYPTION_KEY,
         captcha_delay_in_seconds as WELCOME_DELAY_KICK_SEC,
-        ARQ_API_BASE_URL as ARQ)
+        ARQ_API_BASE_URL as ARQ, LUNA_API)
 from pyrogram import Client
 import time
 import logging

+ 60 - 0
wbb/modules/chatbot.py

@@ -0,0 +1,60 @@
+from wbb import app, LUNA_API
+from wbb.utils.fetch import fetch
+from wbb.utils.errors import capture_err
+from wbb.utils.botinfo import BOT_ID
+from pyrogram import filters
+
+
+__MODULE__ = "ChatBot"
+__HELP__ = "/chatbot [ON|OFF] To Enable Or Disable ChatBot In Your Chat."
+
+active_chats = []
+
+
+# Enabled | Disable Chatbot
+
+
+@app.on_message(filters.command("chatbot"))
+@capture_err
+async def chatbot_status(_, message):
+    global active_chats
+    if len(message.command) != 2:
+        await message.reply_text("/chatbot [ON|OFF]")
+        return
+    status = message.text.split(None, 1)[1]
+    chat_id = message.chat.id
+    
+    if status == "ON" or status == "on" or status == "On":
+        if chat_id not in active_chats:
+            active_chats.append(chat_id)
+            text = "Chatbot Enabled Reply To Any Message" \
+                   + "Of Mine To Get A Reply"
+            await message.reply_text(text)
+            return
+        await message.reply_text("ChatBot Is Already Enabled.")
+        return
+
+    elif status == "OFF" or status == "off" or status == "Off":
+        if chat_id in active_chats:
+            active_chats.remove(chat_id)
+            await message.reply_text("Chatbot Disabled!")
+            return
+        await message.reply_text("ChatBot Is Already Disabled.")
+        return
+    
+    else:
+        await message.reply_text("/chatbot [ON|OFF]")
+
+
+@app.on_message(filters.chat(active_chats) & filters.text
+        & filters.reply
+        & ~filters.bot)
+@capture_err
+async def chatbot_talk(_, message):
+    if message.reply_to_message.from_user.id != BOT_ID:
+        return
+    query = message.text
+    response = await fetch(f"{LUNA_API}{query}")
+    response = response['response']
+    await app.send_chat_action(message.chat.id, "typing")
+    await message.reply_text(response)