| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090 |
- """
- MIT License
- Copyright (c) 2021 TheHamkerCat
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- """
- import asyncio
- import json
- import os
- import sys
- from random import randint
- from sys import version as pyver
- from time import ctime, time
- import aiofiles
- from motor import version as mongover
- from pykeyboard import InlineKeyboard
- from pyrogram import __version__ as pyrover
- from pyrogram import filters
- from pyrogram.raw.functions import Ping
- from pyrogram.types import (InlineKeyboardButton, InlineQueryResultArticle,
- InlineQueryResultPhoto, InputTextMessageContent)
- from search_engine_parser import GoogleSearch
- from wbb import (BOT_USERNAME, MESSAGE_DUMP_CHAT, SUDOERS, USERBOT_ID,
- USERBOT_NAME, USERBOT_USERNAME, app, app2, arq, aiohttpsession)
- from wbb.core.types import InlineQueryResultCachedDocument, InlineQueryResultAudio
- from wbb.modules.info import get_chat_info, get_user_info
- from wbb.modules.music import download_youtube_audio
- from wbb.modules.paste import isPreviewUp
- from wbb.utils.fetch import fetch
- from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
- from wbb.utils.functions import make_carbon, test_speedtest
- from wbb.utils.pastebin import paste
- keywords_list = [
- "alive",
- "ping",
- "tr",
- "ud",
- "google",
- "bitly",
- "wall",
- "yt",
- "torrent",
- "lyrics",
- "wiki",
- "speedtest",
- "music",
- "saavn",
- "deezer",
- "gh_repo",
- "gh_user",
- "search",
- "paste",
- "nsfw_scan",
- "ytmusic",
- "carbon",
- "info",
- "chat_info",
- "tmdb",
- "pypi",
- ]
- async def inline_help_func(__HELP__):
- buttons = InlineKeyboard(row_width=4)
- buttons.add(
- *[
- (InlineKeyboardButton(text=i, switch_inline_query_current_chat=i))
- for i in keywords_list
- ]
- )
- answerss = [
- InlineQueryResultArticle(
- title="Inline Commands",
- description="Help Related To Inline Usage.",
- input_message_content=InputTextMessageContent(
- "Click A Button To Get Started."
- ),
- thumb_url="https://hamker.me/cy00x5x.png",
- reply_markup=buttons,
- ),
- InlineQueryResultArticle(
- title="Github Repo",
- description="Get Github Respository Of Bot.",
- input_message_content=InputTextMessageContent(
- "https://github.com/thehamkercat/WilliamButcherBot"
- ),
- thumb_url="https://hamker.me/gjc9fo3.png",
- ),
- ]
- answerss = await alive_function(answerss)
- return answerss
- async def alive_function(answers):
- buttons = InlineKeyboard(row_width=2)
- bot_state = "Dead" if not await app.get_me() else "Alive"
- ubot_state = "Dead" if not await app2.get_me() else "Alive"
- buttons.add(
- InlineKeyboardButton("Stats", callback_data="stats_callback"),
- InlineKeyboardButton(
- "Go Inline!", switch_inline_query_current_chat=""
- ),
- )
- msg = f"""
- **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
- **MainBot:** `{bot_state}`
- **UserBot:** `{ubot_state}`
- **Python:** `{pyver.split()[0]}`
- **Pyrogram:** `{pyrover}`
- **MongoDB:** `{mongover}`
- **Platform:** `{sys.platform}`
- **Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/{USERBOT_USERNAME})
- """
- answers.append(
- InlineQueryResultArticle(
- title="Alive",
- description="Check Bot's Stats",
- thumb_url="https://static2.aniimg.com/upload/20170515/414/c/d/7/cd7EEF.jpg",
- input_message_content=InputTextMessageContent(
- msg, disable_web_page_preview=True
- ),
- reply_markup=buttons,
- )
- )
- return answers
- async def translate_func(answers, lang, tex):
- result = await arq.translate(tex, lang)
- if not result.ok:
- answers.append(
- InlineQueryResultArticle(
- title="Error",
- description=result.result,
- input_message_content=InputTextMessageContent(result.result),
- )
- )
- return answers
- result = result.result
- msg = f"""
- __**Translated from {result.src} to {result.dest}**__
- **INPUT:**
- {tex}
- **OUTPUT:**
- {result.translatedText}"""
- answers.extend(
- [
- InlineQueryResultArticle(
- title=f"Translated from {result.src} to {result.dest}.",
- description=result.translatedText,
- input_message_content=InputTextMessageContent(msg),
- ),
- InlineQueryResultArticle(
- title=result.translatedText,
- input_message_content=InputTextMessageContent(
- result.translatedText
- ),
- ),
- ]
- )
- return answers
- async def urban_func(answers, text):
- results = await arq.urbandict(text)
- if not results.ok:
- answers.append(
- InlineQueryResultArticle(
- title="Error",
- description=results.result,
- input_message_content=InputTextMessageContent(results.result),
- )
- )
- return answers
- results = results.result[0:48]
- for i in results:
- msg = f"""
- **Query:** {text}
- **Definition:** __{i.definition}__
- **Example:** __{i.example}__"""
- answers.append(
- InlineQueryResultArticle(
- title=i.word,
- description=i.definition,
- input_message_content=InputTextMessageContent(msg),
- )
- )
- return answers
- async def google_search_func(answers, text):
- gresults = await GoogleSearch().async_search(text)
- limit = 0
- for i in gresults:
- if limit > 48:
- break
- limit += 1
- try:
- msg = f"""
- [{i['titles']}]({i['links']})
- {i['descriptions']}"""
- answers.append(
- InlineQueryResultArticle(
- title=i["titles"],
- description=i["descriptions"],
- input_message_content=InputTextMessageContent(
- msg, disable_web_page_preview=True
- ),
- )
- )
- except KeyError:
- pass
- return answers
- async def wall_func(answers, text):
- results = await arq.wall(text)
- if not results.ok:
- answers.append(
- InlineQueryResultArticle(
- title="Error",
- description=results.result,
- input_message_content=InputTextMessageContent(results.result),
- )
- )
- return answers
- results = results.result[0:48]
- for i in results:
- answers.append(
- InlineQueryResultPhoto(
- photo_url=i.url_image,
- thumb_url=i.url_thumb,
- caption=f"[Source]({i.url_image})",
- )
- )
- return answers
- async def saavn_func(answers, text):
- buttons_list = []
- results = await arq.saavn(text)
- if not results.ok:
- answers.append(
- InlineQueryResultArticle(
- title="Error",
- description=results.result,
- input_message_content=InputTextMessageContent(results.result),
- )
- )
- return answers
- results = results.result
- for count, i in enumerate(results):
- buttons = InlineKeyboard(row_width=1)
- buttons.add(InlineKeyboardButton("Download | Play", url=i.media_url))
- buttons_list.append(buttons)
- duration = await time_convert(i.duration)
- caption = f"""
- **Title:** {i.song}
- **Album:** {i.album}
- **Duration:** {duration}
- **Release:** {i.year}
- **Singers:** {i.singers}"""
- description = f"{i.album} | {duration} " + f"| {i.singers} ({i.year})"
- answers.append(
- InlineQueryResultArticle(
- title=i.song,
- input_message_content=InputTextMessageContent(
- caption, disable_web_page_preview=True
- ),
- description=description,
- thumb_url=i.image,
- reply_markup=buttons_list[count],
- )
- )
- return answers
- async def deezer_func(answers, text):
- buttons_list = []
- results = await arq.deezer(text, 5)
- if not results.ok:
- answers.append(
- InlineQueryResultArticle(
- title="Error",
- description=results.result,
- input_message_content=InputTextMessageContent(results.result),
- )
- )
- return answers
- results = results.result
- for count, i in enumerate(results):
- buttons = InlineKeyboard(row_width=1)
- buttons.add(InlineKeyboardButton("Download | Play", url=i.url))
- buttons_list.append(buttons)
- duration = await time_convert(i.duration)
- caption = f"""
- **Title:** {i.title}
- **Artist:** {i.artist}
- **Duration:** {duration}
- **Source:** [Deezer]({i.source})"""
- description = f"{i.artist} | {duration}"
- answers.append(
- InlineQueryResultArticle(
- title=i.title,
- thumb_url=i.thumbnail,
- description=description,
- input_message_content=InputTextMessageContent(
- caption, disable_web_page_preview=True
- ),
- reply_markup=buttons_list[count],
- )
- )
- return answers
- # Used my api key here, don't fuck with it
- async def shortify(url):
- if "." not in url:
- return
- header = {
- "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
- "Content-Type": "application/json",
- }
- payload = {"long_url": f"{url}"}
- payload = json.dumps(payload)
- async with aiohttpsession.post(
- "https://api-ssl.bitly.com/v4/shorten",
- headers=header,
- data=payload,
- ) as resp:
- data = await resp.json()
- msg = data["link"]
- a = []
- b = InlineQueryResultArticle(
- title="Link Shortened!",
- description=data["link"],
- input_message_content=InputTextMessageContent(
- msg, disable_web_page_preview=True
- ),
- )
- a.append(b)
- return a
- async def torrent_func(answers, text):
- results = await arq.torrent(text)
- if not results.ok:
- answers.append(
- InlineQueryResultArticle(
- title="Error",
- description=results.result,
- input_message_content=InputTextMessageContent(results.result),
- )
- )
- return answers
- results = results.result[0:48]
- for i in results:
- title = i.name
- size = i.size
- seeds = i.seeds
- leechs = i.leechs
- upload_date = i.uploaded
- magnet = i.magnet
- caption = f"""
- **Title:** __{title}__
- **Size:** __{size}__
- **Seeds:** __{seeds}__
- **Leechs:** __{leechs}__
- **Uploaded:** __{upload_date}__
- **Magnet:** `{magnet}`"""
- description = f"{size} | {upload_date} | Seeds: {seeds}"
- answers.append(
- InlineQueryResultArticle(
- title=title,
- description=description,
- input_message_content=InputTextMessageContent(
- caption, disable_web_page_preview=True
- ),
- )
- )
- pass
- return answers
- async def youtube_func(answers, text):
- results = await arq.youtube(text)
- if not results.ok:
- answers.append(
- InlineQueryResultArticle(
- title="Error",
- description=results.result,
- input_message_content=InputTextMessageContent(results.result),
- )
- )
- return answers
- results = results.result[0:48]
- for i in results:
- buttons = InlineKeyboard(row_width=1)
- video_url = f"https://youtube.com{i.url_suffix}"
- buttons.add(InlineKeyboardButton("Watch", url=video_url))
- caption = f"""
- **Title:** {i.title}
- **Views:** {i.views}
- **Channel:** {i.channel}
- **Duration:** {i.duration}
- **Uploaded:** {i.publish_time}
- **Description:** {i.long_desc}"""
- description = (
- f"{i.views} | {i.channel} | {i.duration} | {i.publish_time}"
- )
- answers.append(
- InlineQueryResultArticle(
- title=i.title,
- thumb_url=i.thumbnails[0],
- description=description,
- input_message_content=InputTextMessageContent(
- caption, disable_web_page_preview=True
- ),
- reply_markup=buttons,
- )
- )
- return answers
- async def lyrics_func(answers, text):
- song = await arq.lyrics(text)
- if not song.ok:
- answers.append(
- InlineQueryResultArticle(
- title="Error",
- description=song.result,
- input_message_content=InputTextMessageContent(song.result),
- )
- )
- return answers
- lyrics = song.result
- song = lyrics.splitlines()
- song_name = song[0]
- artist = song[1]
- if len(lyrics) > 4095:
- lyrics = await paste(lyrics)
- lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
- msg = f"__{lyrics}__"
- answers.append(
- InlineQueryResultArticle(
- title=song_name,
- description=artist,
- input_message_content=InputTextMessageContent(msg),
- )
- )
- return answers
- async def github_user_func(answers, text):
- URL = f"https://api.github.com/users/{text}"
- result = await fetch(URL)
- buttons = InlineKeyboard(row_width=1)
- buttons.add(
- InlineKeyboardButton(
- text="Open On Github", url=f"https://github.com/{text}"
- )
- )
- caption = f"""
- **Info Of {result['name']}**
- **Username:** `{text}`
- **Bio:** `{result['bio']}`
- **Profile Link:** [Here]({result['html_url']})
- **Company:** `{result['company']}`
- **Created On:** `{result['created_at']}`
- **Repositories:** `{result['public_repos']}`
- **Blog:** `{result['blog']}`
- **Location:** `{result['location']}`
- **Followers:** `{result['followers']}`
- **Following:** `{result['following']}`"""
- answers.append(
- InlineQueryResultPhoto(
- photo_url=result["avatar_url"],
- caption=caption,
- reply_markup=buttons,
- )
- )
- return answers
- async def github_repo_func(answers, text):
- text = text.replace("https://github.com/", "")
- text = text.replace("http://github.com/", "")
- if text[-1] == "/":
- text = text[0:-1]
- URL = f"https://api.github.com/repos/{text}"
- URL2 = f"https://api.github.com/repos/{text}/contributors"
- results = await asyncio.gather(fetch(URL), fetch(URL2))
- r = results[0]
- r1 = results[1]
- commits = 0
- for developer in r1:
- commits += developer["contributions"]
- buttons = InlineKeyboard(row_width=1)
- buttons.add(
- InlineKeyboardButton(
- "Open On Github", url=f"https://github.com/{text}"
- )
- )
- caption = f"""
- **Info Of {r['full_name']}**
- **Stars:** `{r['stargazers_count']}`
- **Watchers:** `{r['watchers_count']}`
- **Forks:** `{r['forks_count']}`
- **Commits:** `{commits}`
- **Is Fork:** `{r['fork']}`
- **Language:** `{r['language']}`
- **Contributors:** `{len(r1)}`
- **License:** `{r['license']['name'] if r['license'] else None}`
- **Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
- **Created On:** `{r['created_at']}`
- **Homepage:** {r['homepage']}
- **Description:** __{r['description']}__"""
- answers.append(
- InlineQueryResultArticle(
- title="Found Repo",
- description=text,
- reply_markup=buttons,
- input_message_content=InputTextMessageContent(
- caption, disable_web_page_preview=True
- ),
- )
- )
- return answers
- async def tg_search_func(answers, text, user_id):
- if user_id not in SUDOERS:
- msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
- answers.append(
- InlineQueryResultArticle(
- title="ERROR",
- description="THIS FEATURE IS ONLY FOR SUDO USERS",
- input_message_content=InputTextMessageContent(msg),
- )
- )
- return answers
- if str(text)[-1] != ":":
- msg = "**ERROR**\n__Put A ':' After The Text To Search__"
- answers.append(
- InlineQueryResultArticle(
- title="ERROR",
- description="Put A ':' After The Text To Search",
- input_message_content=InputTextMessageContent(msg),
- )
- )
- return answers
- text = text[0:-1]
- async for message in app2.search_global(text, limit=49):
- buttons = InlineKeyboard(row_width=2)
- buttons.add(
- InlineKeyboardButton(
- text="Origin",
- url=message.link if message.link else "https://t.me/telegram",
- ),
- InlineKeyboardButton(
- text="Search again", switch_inline_query_current_chat="search"
- ),
- )
- name = (
- message.from_user.first_name
- if message.from_user.first_name
- else "NO NAME"
- )
- caption = f"""
- **Query:** {text}
- **Name:** {str(name)} [`{message.from_user.id}`]
- **Chat:** {str(message.chat.title)} [`{message.chat.id}`]
- **Date:** {ctime(message.date)}
- **Text:** >>
- {message.text.markdown if message.text else message.caption if message.caption else '[NO_TEXT]'}
- """
- result = InlineQueryResultArticle(
- title=name,
- description=message.text if message.text else "[NO_TEXT]",
- reply_markup=buttons,
- input_message_content=InputTextMessageContent(
- caption, disable_web_page_preview=True
- ),
- )
- answers.append(result)
- return answers
- async def music_inline_func(answers, query):
- chat_id = -1001445180719
- group_invite = "https://t.me/joinchat/vSDE2DuGK4Y4Nzll"
- try:
- messages = [
- m
- async for m in app2.search_messages(
- chat_id, query, filter="audio", limit=199
- )
- ]
- except Exception as e:
- print(e)
- msg = f"You Need To Join Here With Your Bot And Userbot To Get Cached Music.\n{group_invite}"
- answers.append(
- InlineQueryResultArticle(
- title="ERROR",
- description="Click Here To Know More.",
- input_message_content=InputTextMessageContent(
- msg, disable_web_page_preview=True
- ),
- )
- )
- return answers
- messages_ids_and_duration = []
- for f_ in messages:
- messages_ids_and_duration.append(
- {
- "message_id": f_.message_id,
- "duration": f_.audio.duration if f_.audio.duration else 0,
- }
- )
- messages = list(
- {v["duration"]: v for v in messages_ids_and_duration}.values()
- )
- messages_ids = []
- for ff_ in messages:
- messages_ids.append(ff_["message_id"])
- messages = await app.get_messages(chat_id, messages_ids[0:48])
- for message_ in messages:
- answers.append(
- InlineQueryResultCachedDocument(
- file_id=message_.audio.file_id, title=message_.audio.title
- )
- )
- return answers
- async def wiki_func(answers, text):
- data = await arq.wiki(text)
- if not data.ok:
- answers.append(
- InlineQueryResultArticle(
- title="Error",
- description=data.result,
- input_message_content=InputTextMessageContent(data.result),
- )
- )
- return answers
- data = data.result
- msg = f"""
- **QUERY:**
- {data.title}
- **ANSWER:**
- __{data.answer}__"""
- answers.append(
- InlineQueryResultArticle(
- title=data.title,
- description=data.answer,
- input_message_content=InputTextMessageContent(msg),
- )
- )
- return answers
- async def speedtest_init(query):
- answers = []
- user_id = query.from_user.id
- if user_id not in SUDOERS:
- msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
- answers.append(
- InlineQueryResultArticle(
- title="ERROR",
- description="THIS FEATURE IS ONLY FOR SUDO USERS",
- input_message_content=InputTextMessageContent(msg),
- )
- )
- return answers
- msg = "**Click The Button Below To Perform A Speedtest**"
- button = InlineKeyboard(row_width=1)
- button.add(
- InlineKeyboardButton(text="Test", callback_data="test_speedtest")
- )
- answers.append(
- InlineQueryResultArticle(
- title="Click Here",
- input_message_content=InputTextMessageContent(msg),
- reply_markup=button,
- )
- )
- return answers
- """ callback query for the function above """
- @app.on_callback_query(filters.regex("test_speedtest"))
- async def test_speedtest_cq(_, cq):
- if cq.from_user.id not in SUDOERS:
- await cq.answer("This Isn't For You!")
- return
- inline_message_id = cq.inline_message_id
- await app.edit_inline_text(inline_message_id, "**Testing**")
- loop = asyncio.get_running_loop()
- download, upload, info = await loop.run_in_executor(None, test_speedtest)
- msg = f"""
- **Download:** `{download}`
- **Upload:** `{upload}`
- **Latency:** `{info['latency']} ms`
- **Country:** `{info['country']} [{info['cc']}]`
- **Latitude:** `{info['lat']}`
- **Longitude:** `{info['lon']}`
- """
- await app.edit_inline_text(inline_message_id, msg)
- async def pastebin_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)
- link = await paste(content)
- preview = link + "/preview.png"
- if not await isPreviewUp(preview):
- return []
- await app.send_photo(MESSAGE_DUMP_CHAT, preview) # To Pre-cache the media
- buttons = InlineKeyboard(row_width=1)
- buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
- answers.append(
- InlineQueryResultPhoto(photo_url=preview, reply_markup=buttons)
- )
- return answers
- async def pmpermit_func(answers, user_id, victim):
- if user_id != USERBOT_ID:
- return
- caption = f"Hi, I'm {USERBOT_NAME}, What are you here for?, You'll be blocked if you send more than 5 messages."
- buttons = InlineKeyboard(row_width=2)
- buttons.add(
- InlineKeyboardButton(
- text="To Scam You", callback_data="pmpermit to_scam_you a"
- ),
- InlineKeyboardButton(
- text="For promotion", callback_data="pmpermit to_scam_you a"
- ),
- InlineKeyboardButton(
- text="Approve me", callback_data="pmpermit approve_me a"
- ),
- InlineKeyboardButton(
- text="Approve", callback_data=f"pmpermit approve {victim}"
- ),
- )
- answers.append(
- InlineQueryResultArticle(
- title="do_not_click_here",
- reply_markup=buttons,
- input_message_content=InputTextMessageContent(caption),
- )
- )
- return answers
- async def ping_func(answers):
- t1 = time()
- ping = Ping(ping_id=randint(696969, 6969696))
- await app.send(ping)
- t2 = time()
- ping = f"{str(round((t2 - t1), 6) * 100)} ms"
- answers.append(
- InlineQueryResultArticle(
- title=ping,
- input_message_content=InputTextMessageContent(f"__**{ping}**__"),
- )
- )
- return answers
- async def nsfw_scan_func(answers, url: str):
- t1 = time()
- data = await arq.nsfw_scan(url)
- if not data.ok:
- answers.append(
- InlineQueryResultArticle(
- title="Error",
- description=data.result,
- input_message_content=InputTextMessageContent(data.result),
- )
- )
- return answers
- t2 = time()
- tt = round(t2 - t1, 4)
- data = data.result
- content = f"""
- **Scanned [Image]({url}) In {tt} Seconds.**
- **Drawings:** `{data.drawings} %`
- **Neutral:** `{data.neutral} %`
- **Hentai:** `{data.hentai} %`
- **Porn:** `{data.porn} %`
- **Sexy:** `{data.sexy} %`
- """
- answers.append(
- InlineQueryResultArticle(
- title="Scanned",
- description=f"Took {tt} Seconds.",
- input_message_content=InputTextMessageContent(content),
- )
- )
- return answers
- async def yt_music_func(answers, url):
- if "http" not in url:
- url = (await arq.youtube(url)).result[0]
- url = f"https://youtube.com{url.url_suffix}"
- loop = asyncio.get_running_loop()
- music = await loop.run_in_executor(None, download_youtube_audio, url)
- if not music:
- msg = "**ERROR**\n__MUSIC TOO LONG__"
- answers.append(
- InlineQueryResultArticle(
- title="ERROR",
- description="MUSIC TOO LONG",
- input_message_content=InputTextMessageContent(msg),
- )
- )
- return answers
- (
- title,
- performer,
- duration,
- audio,
- thumbnail,
- ) = music
- m = await app.send_audio(
- MESSAGE_DUMP_CHAT,
- audio,
- title=title,
- duration=duration,
- performer=performer,
- thumb=thumbnail,
- )
- os.remove(audio)
- os.remove(thumbnail)
- answers.append(
- InlineQueryResultCachedDocument(title=title, file_id=m.audio.file_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)
- # To Pre-cache the media
- carbon = await app.send_document(MESSAGE_DUMP_CHAT, image)
- 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
- async def user_info_inline_func(answers, user):
- caption, photo_id = await get_user_info(user)
- answers.append(
- InlineQueryResultArticle(
- title="Found User.",
- input_message_content=InputTextMessageContent(
- caption, disable_web_page_preview=True
- ),
- )
- )
- return answers
- async def chat_info_inline_func(answers, chat):
- caption, photo_id = await get_chat_info(chat)
- answers.append(
- InlineQueryResultArticle(
- title="Found Chat.",
- input_message_content=InputTextMessageContent(
- caption, disable_web_page_preview=True
- ),
- )
- )
- return answers
- async def tmdb_func(answers, query):
- response = await arq.tmdb(query)
- if not response.ok:
- answers.append(
- InlineQueryResultArticle(
- title="Error",
- description=response.result,
- input_message_content=InputTextMessageContent(response.result),
- )
- )
- return answers
- results = response.result[0:48]
- for result in results:
- if not result.poster and not result.backdrop:
- continue
- if not result.genre:
- genre = None
- else:
- genre = " | ".join(result.genre)
- description = result.overview[0:900] if result.overview else "None"
- caption = f"""
- **{result.title}**
- **Type:** {result.type}
- **Rating:** {result.rating}
- **Genre:** {genre}
- **Release Date:** {result.releaseDate}
- **Description:** __{description}__
- """
- buttons = InlineKeyboard(row_width=1)
- buttons.add(
- InlineKeyboardButton(
- "Search Again", switch_inline_query_current_chat="tmdb"
- )
- )
- answers.append(
- InlineQueryResultPhoto(
- photo_url=result.backdrop
- if result.backdrop
- else result.poster,
- caption=caption,
- title=result.title,
- description=f"{genre} • {result.releaseDate} • {result.rating} • {description}",
- reply_markup=buttons,
- )
- )
- return answers
- async def pypiSearchFunc(answers: list, query: str) -> list:
- result = await arq.pypi(query)
- if not result.ok:
- answers.append(
- InlineQueryResultArticle(
- title="No Such Package",
- description=result.result,
- input_message_content=InputTextMessageContent(result.result),
- )
- )
- return answers
- result = result.result
- pURLS = [
- f"**{key}**: {value}" for key, value in result.projectURLS.items()
- ]
- pURLS = ("\n" + "\n".join(pURLS)) if pURLS else None
- caption = f"""
- **Name:** {result.name}
- **Version:** {result.version}
- **License:** {result.license}
- **Description:** {result.description}
- **Size:** {result.size}
- **Last Update:** {result.uploadTime}
- **Author:** {result.author}
- **Author's Email:** {result.authorEmail}
- **Requirements:** {(f'`{" | ".join(result.requirements)}`') if result.requirements else None}
- **Minimum Python Version:** {result.minPyVersion}
- **Homepage:** {result.homepage}
- **Bug Tracker:** {result.bugTrackURL}
- **Docs Url:** {result.docsURL}
- **Pypi Url:** {result.pypiURL}
- **Releases:** {result.releaseURL}
- **Project Urls:** ->{pURLS}
- """
- button = InlineKeyboard(row_width=2)
- button.add(
- InlineKeyboardButton(text="Open Page", url=result.pypiURL),
- InlineKeyboardButton(
- text="Search Again", switch_inline_query_current_chat="pypi"
- ),
- )
- answers.append(
- InlineQueryResultArticle(
- title=f"{result.name} | {result.version}",
- description=result.description,
- input_message_content=InputTextMessageContent(
- caption, disable_web_page_preview=True
- ),
- reply_markup=button,
- )
- )
- return answers
- async def randomAudioFunc(answers: list, query: str) -> list:
- url = f"https://www.zedge.net/api-zedge-web/browse/search?query={query}&contentType=ringtones"
- async with aiohttpsession.get(url) as resp:
- data = await resp.json()
- items = data['items']
- answers = [
- InlineQueryResultAudio(
- audio_url=audio['audioUrl'],
- thumb_url="https://tweety.drk1.workers.dev/0:/image_2021-05-22_20-56-47.png",
- title=audio['title'],
- mime_type="audio/mp3"
- ) for audio in items
- ]
- return answers
|