Explorar el Código

Added python-arq

TheHamkerCat hace 5 años
padre
commit
f994cf657a
Se han modificado 8 ficheros con 49 adiciones y 50 borrados
  1. 1 0
      requirements.txt
  2. 1 1
      sample_config.py
  3. 3 1
      wbb/__init__.py
  4. 5 4
      wbb/modules/chatbot.py
  5. 13 19
      wbb/modules/images.py
  6. 9 9
      wbb/modules/music.py
  7. 7 6
      wbb/modules/reddit.py
  8. 10 10
      wbb/modules/search.py

+ 1 - 0
requirements.txt

@@ -1,3 +1,4 @@
+python-arq
 TgCrypto
 aiohttp
 aiofiles

+ 1 - 1
sample_config.py

@@ -16,4 +16,4 @@ fernet_encryption_key = "iKMq0WZMnJKjMQxZWKtv-cplMuF_LoyshXj0XbTGGWM="
 captcha_delay_in_seconds = 300
 
 # Leave This As It Is
-ARQ_API_BASE_URL = "https://thearq.tech/"
+ARQ_API_BASE_URL = "https://thearq.tech"

+ 3 - 1
wbb/__init__.py

@@ -3,8 +3,9 @@ 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, LUNA_API)
+        ARQ_API_BASE_URL as ARQ_API)
 from pyrogram import Client
+from Python_ARQ import ARQ
 import time
 import logging
 
@@ -41,3 +42,4 @@ MOD_NOLOAD = []
 bot_start_time = time.time()
 
 app = Client("wbb", bot_token=bot_token, api_id=api_id, api_hash=api_hash)
+arq = ARQ(ARQ_API)

+ 5 - 4
wbb/modules/chatbot.py

@@ -1,4 +1,4 @@
-from wbb import app, ARQ
+from wbb import app, arq 
 from wbb.utils.fetch import fetch
 from wbb.utils.errors import capture_err
 from wbb.utils.botinfo import BOT_ID
@@ -10,7 +10,6 @@ __HELP__ = "/chatbot [ON|OFF] To Enable Or Disable ChatBot In Your Chat."
 
 active_chats = []
 
-
 # Enabled | Disable Chatbot
 
 
@@ -46,6 +45,8 @@ async def chatbot_status(_, message):
         await message.reply_text("/chatbot [ON|OFF]")
 
 
+
+
 @app.on_message(filters.text & filters.reply & ~filters.bot)
 @capture_err
 async def chatbot_talk(_, message):
@@ -54,7 +55,7 @@ async def chatbot_talk(_, message):
     if message.reply_to_message.from_user.id != BOT_ID:
         return
     query = message.text
-    response = await fetch(f"{ARQ}luna?query={query}")
-    response = response['response']
+    luna = await arq.luna(query)
+    response = luna.response
     await app.send_chat_action(message.chat.id, "typing")
     await message.reply_text(response)

+ 13 - 19
wbb/modules/images.py

@@ -3,7 +3,7 @@ import json
 import asyncio
 from random import randint
 from pyrogram import filters
-from wbb import app, ARQ
+from wbb import app, arq
 from wbb.utils.errors import capture_err
 from wbb.utils.fetch import fetch
 
@@ -38,22 +38,16 @@ async def wall(_, message):
     initial_term = message.text.split(None, 1)[1]
     m = await message.reply_text("Searching!")
     term = initial_term.replace(' ', '%20')
-    json_rep = await fetch(f"{ARQ}wall?query={term}")
-    if not json_rep.get("success"):
-        await m.edit("Something happened! Shit.")
+    wallpapers = await arq.wall(term)
+    if not wallpapers:
+        await m.edit("Found literally nothing!,"
+                     + "You should work on your English.")
+        return
+    if len(wallpapers) > 10:
+        selection = 10
     else:
-        wallpapers = json_rep.get("wallpapers")
-        if not wallpapers:
-            await m.edit("Found literally nothing!,"
-                         + "You should work on your English.")
-            return
-        if len(wallpapers) > 10:
-            selection = 10
-        else:
-            selection = len(wallpapers)
-        index = randint(0, selection - 1)
-        wallpaper = wallpapers[index]
-        wallpaper = wallpaper.get("url_image")
-        wallpaper = wallpaper.replace("\\", "")
-        await message.reply_document(wallpaper)
-        await m.delete()
+        selection = len(wallpapers)
+    index = randint(0, selection - 1)
+    wallpaper = wallpapers[index].url_image
+    await message.reply_document(wallpaper)
+    await m.delete()

+ 9 - 9
wbb/modules/music.py

@@ -7,7 +7,7 @@ import aiofiles
 import os
 from random import randint
 from pyrogram import filters
-from wbb import app, SUDOERS, ARQ
+from wbb import app, SUDOERS, arq 
 from wbb.utils.fetch import fetch
 from wbb.utils.errors import capture_err
 
@@ -95,10 +95,10 @@ async def jssong(_, message):
     query = text.replace(" ", "%20")
     m = await message.reply_text("Searching...")
     try:
-        r = await fetch(f"{ARQ}saavn?query={query}")
-        sname = r[0]['song']
-        slink = r[0]['media_url']
-        ssingers = r[0]['singers']
+        songs = await arq.saavn(query)
+        sname = songs[0].song
+        slink = songs[0].media_url
+        ssingers = songs[0].singers
     except Exception as e:
         await m.edit(str(e))
         return
@@ -124,10 +124,10 @@ async def jssong(_, message):
     query = text.replace(" ", "%20")
     m = await message.reply_text("Searching...")
     try:
-        r = await fetch(f"{ARQ}deezer?query={query}&count=1")
-        title = r[0]['title']
-        url = r[0]['url']
-        artist = r[0]['artist']
+        songs = await arq.deezer(query, 1)
+        title = songs[0].title
+        url = songs[0].url
+        artist = songs[0].artist
     except Exception as e:
         await m.edit(str(e))
         return

+ 7 - 6
wbb/modules/reddit.py

@@ -1,11 +1,12 @@
 from pyrogram import filters
-from wbb import app, ARQ
+from wbb import app, arq
 from wbb.utils.errors import capture_err
 from wbb.utils.fetch import fetch
 
 __MODULE__ = "Reddit"
 __HELP__ = "/reddit [query] - results something from reddit"
 
+
 @app.on_message(filters.command("reddit") & ~filters.edited)
 @capture_err
 async def reddit(_, message):
@@ -14,11 +15,11 @@ async def reddit(_, message):
         return
     subreddit = message.text.split(None, 1)[1]
     try:
-        res = await fetch(f"{ARQ}reddit?query={subreddit}")
-        sreddit = res["subreddit"]
-        title = res["title"]
-        image = res["url"]
-        link = res["postLink"]
+        reddit = await arq.reddit(subreddit)
+        sreddit = reddit.subreddit
+        title = reddit.title
+        image = reddit.url
+        link = reddit.postLink
         caption = f"""**Title:** `{title}`
 **Subreddit:** {sreddit}
 **PostLink:** {link}"""

+ 10 - 10
wbb/modules/search.py

@@ -1,6 +1,6 @@
 from search_engine_parser import GoogleSearch
 from pyrogram import filters
-from wbb import app, ARQ
+from wbb import app, arq
 from wbb.utils.errors import capture_err
 from wbb.utils.fetch import fetch
 
@@ -22,10 +22,10 @@ async def urbandict(_, message):
         return
     text = message.text.split(None, 1)[1]
     try:
-        results = await fetch(f"{ARQ}ud?query={text}")
-        reply_text = f"""**Definition:** __{results["list"][0]["definition"]}__
+        results = await arq.urbandict(text, 1)
+        reply_text = f"""**Definition:** __{results[0].definition}__
 
-**Example:** __{results["list"][0]["example"]}__"""
+**Example:** __{results[0].example}__"""
     except IndexError:
         reply_text = ("Sorry could not find any matching results!")
     ignore_chars = "[]"
@@ -131,15 +131,15 @@ async def ytsearch(_, message):
             return
         query = message.text.split(None, 1)[1]
         m = await message.reply_text("Searching....")
-        results = await fetch(f"{ARQ}youtube?query={query}&count=3")
+        results = await arq.youtube(query, 3)
         i = 0
         text = ""
         while i < 3:
-            text += f"Title - {results[i]['title']}\n"
-            text += f"Duration - {results[i]['duration']}\n"
-            text += f"Views - {results[i]['views']}\n"
-            text += f"Channel - {results[i]['channel']}\n"
-            text += f"https://youtube.com{results[i]['url_suffix']}\n\n"
+            text += f"Title - {results[i].title}\n"
+            text += f"Duration - {results[i].duration}\n"
+            text += f"Views - {results[i].views}\n"
+            text += f"Channel - {results[i].channel}\n"
+            text += f"https://youtube.com{results[i].url_suffix}\n\n"
             i += 1
         await m.edit(text, disable_web_page_preview=True)
     except Exception as e: