Sfoglia il codice sorgente

Added carbon and fixed shit

TheHamkerCat 5 anni fa
parent
commit
844959ee85

+ 1 - 0
requirements.txt

@@ -1,4 +1,5 @@
 ffmpeg-python
+carbonnow
 aiohttp
 aiofiles
 cryptography

+ 11 - 20
wbb/modules/anime.py

@@ -1,20 +1,12 @@
 # Part of Pull Req #2 by @MaskedVirus | github.com/swatv3nub
 
-import os
-import html
-import math
 import time
 import requests
-import json
-import asyncio
-import tempfile
-from decimal import Decimal
 from datetime import timedelta
-from urllib.parse import quote as urlencode
 from pyrogram import filters
 from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
 
-from wbb import app, telegraph, session
+from wbb import app, telegraph
 from wbb.core.decorators.errors import capture_err
 
 __MODULE__ = "Anime"
@@ -196,12 +188,10 @@ url = 'https://graphql.anilist.co'
 @app.on_message(filters.command("anime"))
 @capture_err
 async def anime_search(_, message):
-    search = message.text.split(' ', 1)
-    if len(search) == 1:
+    if len(message.command) < 2:
         await message.delete()
         return
-    else:
-        search = search[1]
+    search = message.text.split(None, 1)[1]
     variables = {'search': search}
     json = requests.post(url, json={'query': anime_query, 'variables': variables}).json()[
         'data'].get('Media', None)
@@ -247,11 +237,10 @@ async def anime_search(_, message):
 @app.on_message(filters.command("manga"))
 @capture_err
 async def manga_search(_, message):
-    search = message.text.split(' ', 1)
-    if len(search) == 1:
+    if len(message.command) < 2:
         await message.delete()
         return
-    search = search[1]
+    search = message.text.split(None, 1)[1]
     variables = {'search': search}
     json = requests.post(url, json={'query': manga_query, 'variables': variables}).json()[
         'data'].get('Media', None)
@@ -291,11 +280,10 @@ async def manga_search(_, message):
 @app.on_message(filters.command("char"))
 @capture_err
 async def character_search(_, message):
-    search = message.text.split(' ', 1)
-    if len(search) == 1:
+    if len(message.command) < 2:
         await message.delete()
         return
-    search = search[1]
+    search = message.text.split(None, 1)[1]
     variables = {'query': search}
     json = requests.post(url, json={'query': character_query, 'variables': variables}).json()[
         'data'].get('Character', None)
@@ -315,7 +303,10 @@ async def character_search(_, message):
 @app.on_message(filters.command("nhentai"))
 @capture_err
 async def nhentai(_, message):
-    query = message.text.split(" ")[1]
+    if len(message.command) < 2:
+        await message.delete()
+        return
+    query = message.text.split(None, 1)[1]
     title, tags, artist, total_pages, post_url, cover_image = nhentai_data(query)
     await message.reply_text(
         f"<code>{title}</code>\n\n<b>Tags:</b>\n{tags}\n<b>Artists:</b>\n{artist}\n<b>Pages:</b>\n{total_pages}",

+ 25 - 0
wbb/modules/carbon.py

@@ -0,0 +1,25 @@
+from wbb import app
+from wbb.utils.functions import make_carbon
+from pyrogram import filters
+from wbb.core.decorators.errors import capture_err
+import os
+
+
+__MODULE__ = "Carbon"
+__HELP__ = "/carbon - Make Carbon Of Code."
+
+
+@app.on_message(filters.command("carbon"))
+async def carbon_func(_, message):
+    if not message.reply_to_message:
+        await message.reply_text("Reply to a text message to make carbon.")
+        return
+    if not message.reply_to_message.text:
+        await message.reply_text("Reply to a text message to make carbon.")
+        return
+    m = await message.reply_text("Preparing Carbon")
+    carbon = await make_carbon(message.reply_to_message.text)
+    await m.edit("Uploading")
+    await app.send_photo(message.chat.id, carbon)
+    await m.delete()
+    os.remove(carbon)

+ 30 - 3
wbb/modules/inline.py

@@ -324,15 +324,42 @@ async def inline_query_handler(client, query):
             )
             return
 
-        elif re.search(r'^https?://t.me/', text.strip()):
-            answerss = await pastebin_func(answers, text.strip())
+        elif text.split()[0] == "paste":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Pastebin | paste [TG_MESSAGE_LINK]',
+                    switch_pm_parameter='inline',
+                )
+                return
+            link = text.strip().split()[1]
+            answerss = await pastebin_func(answers, link)
+            await client.answer_inline_query(
+                query.id,
+                results=answerss,
+                cache_time=2
+            )
+            return
+
+        elif text.split()[0] == "carbon":
+            if len(text.split()) < 2:
+                await client.answer_inline_query(
+                    query.id,
+                    results=answers,
+                    switch_pm_text='Carbon | carbon [TG_MESSAGE_LINK]',
+                    switch_pm_parameter='inline',
+                )
+                return
+            link = text.strip().split()[1]
+            answerss = await carbon_inline_func(answers, link)
             await client.answer_inline_query(
                 query.id,
                 results=answerss,
                 cache_time=2
             )
             return
-        
+
         elif text.split()[0] == "pmpermit":
             user_id = query.from_user.id
             victim = text.split()[1]

+ 5 - 1
wbb/modules/misc.py

@@ -68,8 +68,12 @@ async def runs(_, message):
     await message.reply_text((await random_line('wbb/utils/runs.txt')))
 
 
-@app.on_message(filters.command(["id"]))
+@app.on_message(filters.command("id"))
 async def getid(_, message):
+    if len(message.command) == 2:
+        id = (await app.get_users(message.text.split(None, 1)[1])).id
+        text = f"<b>ID:</b> {id}"
+        return
     text_unping = "<b>Chat ID:</b>"
     if message.chat.username:
         text_unping = (

+ 3 - 25
wbb/modules/sudoers.py

@@ -29,7 +29,7 @@ import psutil
 import asyncio
 from sys import version as pyver
 from wbb import (
-    app, SUDOERS, bot_start_time, BOT_ID, BOT_NAME, USERBOT_USERNAME, GBAN_LOG_GROUP_ID
+    app, SUDOERS, bot_start_time, BOT_ID, USERBOT_USERNAME, GBAN_LOG_GROUP_ID
 )
 from wbb.utils import formatter
 from wbb.core.decorators.errors import capture_err
@@ -48,7 +48,7 @@ __HELP__ = '''
 /gban - To Ban A User Globally.
 /broadcast - To Broadcast A Message To All Groups.
 /update - To Update And Restart The Bot
-/install - To Install A Module'''
+'''
 
 # Stats Module
 
@@ -270,26 +270,4 @@ async def broadcast_message(_, message):
 @app.on_message(filters.command("update") & filters.user(SUDOERS))
 async def update_restart(_, message):
     await message.reply_text(f'```{subprocess.check_output(["git", "pull"]).decode("UTF-8")}```')
-    os.execvp(f"python{str(pyver.split(' ')[0])[:3]}", [
-              f"python{str(pyver.split(' ')[0])[:3]}", "-m", "wbb"])
-
-# Install
-
-
-@app.on_message(filters.command("install") & filters.user(SUDOERS))
-async def install_module(_, message):
-    if not message.reply_to_message:
-        await message.reply_text("Reply To A .py File To Install It.")
-        return
-    if not message.reply_to_message.document:
-        await message.reply_text("Reply To A .py File To Install It.")
-        return
-    document = message.reply_to_message.document
-    if document.mime_type != "text/x-python":
-        await message.reply_text("INVALID_MIME_TYPE, Reply To A Correct .py File.")
-        return
-    m = await message.reply_text("**Installing Module**")
-    await message.reply_to_message.download(f"./wbb/modules/{document.file_name}")
-    await m.edit("**Restarting**")
-    os.execvp(f"python{str(pyver.split(' ')[0])[:3]}", [
-              f"python{str(pyver.split(' ')[0])[:3]}", "-m", "wbb"])
+    os.execvp("python3", ["python3", "-m", "wbb"])

+ 7 - 2
wbb/modules/telegraph.py

@@ -4,7 +4,7 @@
 
 import os
 from telegraph import upload_file
-from pyrogram import filters, Client
+from pyrogram import filters
 from wbb import app
 from wbb.core.decorators.errors import capture_err
 
@@ -19,6 +19,9 @@ Usage :
 @app.on_message(filters.command("tgphoto"))
 @capture_err
 async def tgphoto(client, message):
+    if not message.reply_to_message:
+        await message.reply_text("Reply to a photo.")
+        return
     if not message.reply_to_message.photo:
         await message.reply_text("Works only for Photos")
         return
@@ -35,10 +38,12 @@ async def tgphoto(client, message):
       os.remove(path)
    
    
-   
 @app.on_message(filters.command("tgvideo"))
 @capture_err
 async def tgvideo(client, message):
+    if not message.reply_to_message:
+        await message.reply_text("Reply to a Video.")
+        return
     if not message.reply_to_message.video:
         await message.reply_text("Works only for Videos")
         return

+ 7 - 0
wbb/utils/functions.py

@@ -24,9 +24,11 @@ SOFTWARE.
 from PIL import Image, ImageDraw, ImageFont, ImageFilter
 from random import randint
 from wbb.utils import aiodownloader
+from carbonnow import Carbon
 import speedtest
 import aiohttp
 
+
 """
 Just import 'downloader' anywhere and do downloader.download() to
 download file from a given url
@@ -112,3 +114,8 @@ async def get_http_status_code(url: str) -> int:
         async with session.head(url) as resp:
             return resp.status
 
+
+async def make_carbon(code):
+    carbon = Carbon(code=code)
+    image = await carbon.save(str(randint(1000, 10000)))
+    return image

+ 45 - 2
wbb/utils/inlinefuncs.py

@@ -45,7 +45,7 @@ from random import randint
 from wbb.utils.fetch import fetch
 from wbb.modules.userbot import eval_executer_func
 from wbb.modules.music import download_youtube_audio
-from wbb.utils.functions import test_speedtest, get_http_status_code
+from wbb.utils.functions import test_speedtest, get_http_status_code, make_carbon
 from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
 from wbb.utils.pastebin import paste
 from wbb.core.types import InlineQueryResultCachedDocument
@@ -842,7 +842,7 @@ async def yt_music_func(answers, url, user_id):
     title, performer, duration, audio, thumbnail = await download_youtube_audio(url)
     m = await app.send_audio(
             MESSAGE_DUMP_CHAT,
-            audio_file,
+            audio,
             title=title,
             duration=duration,
             performer=performer,
@@ -857,3 +857,46 @@ async def yt_music_func(answers, url, user_id):
         )
     )
     return answers
+
+
+async def carbon_inline_func(answers, link):
+    link = link.split("/")
+    if link[3] == "c":
+        chat, message_id = int("-100" + link[4]), int(link[5])
+    else:
+        chat, message_id = link[3], link[4]
+    m = await app.get_messages(chat, message_ids=int(message_id))
+    if not m.text and not m.document:
+        m = await app2.get_messages(chat, message_ids=int(message_id))
+    if m.text:
+        content = m.text
+    else:
+        if m.document.file_size > 1048576:
+            answers.append(
+                InlineQueryResultArticle(
+                    title="DOCUMENT TOO BIG",
+                    description="Maximum supported size is 1MB",
+                    input_message_content=InputTextMessageContent(
+                        "DOCUMENT TOO BIG")
+
+                )
+            )
+            return answers
+        doc = await m.download()
+        async with aiofiles.open(doc, mode="r") as f:
+            content = await f.read()
+        os.remove(doc)
+    image = await make_carbon(content)
+    link = await paste(content)
+    carbon = await app.send_document(MESSAGE_DUMP_CHAT, image)  # To Pre-cache the media
+    os.remove(image)
+    buttons = InlineKeyboard(row_width=1)
+    buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
+    answers.append(
+        InlineQueryResultCachedDocument(
+            file_id=carbon.document.file_id,
+            title="Carbon",
+            reply_markup=buttons
+        )
+    )
+    return answers