Просмотр исходного кода

Committing in accordance with the prophecy.

TheHamkerCat 5 лет назад
Родитель
Сommit
475985fe7c
2 измененных файлов с 16 добавлено и 10 удалено
  1. 10 3
      wbb/modules/misc.py
  2. 6 7
      wbb/modules/music.py

+ 10 - 3
wbb/modules/misc.py

@@ -1,6 +1,7 @@
 import secrets
 import string
 import requests
+import aiohttp
 from pyrogram import filters
 from googletrans import Translator
 from cryptography.fernet import Fernet
@@ -125,6 +126,13 @@ async def decrypt(_, message):
     await message.reply_text(bytes_in_text)
 
 
+async def fetch_text(url):
+    async with aiohttp.ClientSession(headers={"user-agent":"curl"}) as session:
+        async with session.get(url) as resp:
+            data = await resp.text()
+    return data
+
+
 # Cheat.sh
 
 
@@ -140,7 +148,7 @@ async def cheat(_, message):
         ftext = text.split()
         language = ftext[0]
         query = ftext[1]
-        data = requests.get(f"http://cht.sh/{language}/{query}?QT").text
+        data = await fetch_text(f"http://cht.sh/{language}/{query}?QT")
         if not data:
             await m.edit("Found Literally Nothing!")
             return
@@ -160,8 +168,7 @@ async def weather(_, message):
         return
     city = message.text.split(None, 1)[1]
     m = await message.reply_text("Fetching Data")
-    r = requests.get(f"https://wttr.in/{city}?mnTC0")
-    data = r.text
+    data = await fetch_text(f"https://wttr.in/{city}?mnTC0")
     await m.edit(f"`{data}`")
 
 # Translate

+ 6 - 7
wbb/modules/music.py

@@ -54,7 +54,6 @@ async def music(_, message):
         return
         # info
     title = info_dict['title']
-    webpage_url = info_dict['webpage_url']
     performer = info_dict['uploader']
     duration = int(float(info_dict['duration']))
     await m.delete()
@@ -97,12 +96,12 @@ async def jssong(_, message):
     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']
     except Exception as e:
         await m.edit(str(e))
         return
-    sname = r[0]['song']
-    slink = r[0]['media_url']
-    ssingers = r[0]['singers']
     await m.edit("Downloading") 
     song = await download_song(slink)
     await m.edit("Uploading") 
@@ -126,12 +125,12 @@ async def jssong(_, message):
     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']
     except Exception as e:
         await m.edit(str(e))
         return
-    title = r[0]['title']
-    url = r[0]['url']
-    artist = r[0]['artist']
     await m.edit("Downloading") 
     song = await download_song(url)
     await m.edit("Uploading")