inlinefuncs.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. """
  2. MIT License
  3. Copyright (c) 2021 TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. import aiohttp
  21. import aiofiles
  22. import json
  23. import sys
  24. import os
  25. import asyncio
  26. from pyrogram.types import (
  27. InlineQueryResultArticle,
  28. InputTextMessageContent,
  29. InlineKeyboardButton,
  30. InlineQueryResultPhoto,
  31. )
  32. from pyrogram.raw.functions import Ping
  33. from googletrans import Translator
  34. from search_engine_parser import GoogleSearch
  35. from pykeyboard import InlineKeyboard
  36. from sys import version as pyver
  37. from motor import version as mongover
  38. from pyrogram import __version__ as pyrover, filters
  39. from time import time, ctime
  40. from random import randint
  41. from wbb.utils.fetch import fetch
  42. from wbb.modules.userbot import eval_executer_func
  43. from wbb.utils.functions import test_speedtest, get_http_status_code
  44. from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
  45. from wbb.utils.pastebin import paste
  46. from wbb.core.types import InlineQueryResultCachedDocument
  47. from wbb import (
  48. arq, app, app2, USERBOT_USERNAME,
  49. BOT_USERNAME, USERBOT_ID,
  50. SUDOERS, USERBOT_NAME
  51. )
  52. async def inline_help_func(__HELP__):
  53. buttons = InlineKeyboard(row_width=3)
  54. keywords_list = [
  55. "alive", "ping", "tr", "ud", "google", "bitly",
  56. "wall", "yt", "torrent", "lyrics", "wiki",
  57. "speedtest", "eval", "music", "saavn", "deezer",
  58. "gh_repo", "gh_user", "search", "pastebin"
  59. ]
  60. buttons.add(*[(InlineKeyboardButton(
  61. text=i, switch_inline_query_current_chat=i)) for i in keywords_list])
  62. answerss = [
  63. InlineQueryResultArticle(
  64. title="Inline Commands",
  65. description="Help Related To Inline Usage.",
  66. input_message_content=InputTextMessageContent(
  67. "Click A Button To Get Started."),
  68. thumb_url="https://hamker.me/cy00x5x.png",
  69. reply_markup=buttons
  70. )
  71. ]
  72. answerss = await alive_function(answerss)
  73. return answerss
  74. async def alive_function(answers):
  75. buttons = InlineKeyboard(row_width=2)
  76. bot_state = 'Dead' if not await app.get_me() else 'Alive'
  77. ubot_state = 'Dead' if not await app2.get_me() else 'Alive'
  78. buttons.add(
  79. InlineKeyboardButton(
  80. 'Stats',
  81. callback_data='stats_callback'
  82. ),
  83. InlineKeyboardButton(
  84. "Go Inline!",
  85. switch_inline_query_current_chat=""
  86. )
  87. )
  88. msg = f"""
  89. **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
  90. **MainBot:** `{bot_state}`
  91. **UserBot:** `{ubot_state}`
  92. **Python:** `{pyver.split()[0]}`
  93. **Pyrogram:** `{pyrover}`
  94. **MongoDB:** `{mongover}`
  95. **Platform:** `{sys.platform}`
  96. **Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/{USERBOT_USERNAME})
  97. """
  98. answers.append(
  99. InlineQueryResultArticle(
  100. title='Alive',
  101. description="Check Bot's Stats",
  102. thumb_url="https://static2.aniimg.com/upload/20170515/414/c/d/7/cd7EEF.jpg",
  103. input_message_content=InputTextMessageContent(
  104. msg,
  105. disable_web_page_preview=True
  106. ),
  107. reply_markup=buttons,
  108. )
  109. )
  110. return answers
  111. async def translate_func(answers, lang, tex):
  112. i = Translator().translate(tex, dest=lang)
  113. msg = f"""
  114. __**Translated to {lang}**__
  115. **INPUT:**
  116. {tex}
  117. **OUTPUT:**
  118. {i.text}"""
  119. answers.append(
  120. InlineQueryResultArticle(
  121. title=f'Translated to {lang}',
  122. description=i.text,
  123. input_message_content=InputTextMessageContent(msg)
  124. )
  125. )
  126. return answers
  127. async def urban_func(answers, text):
  128. results = await arq.urbandict(text)
  129. limit = 0
  130. for i in results:
  131. if limit > 48:
  132. break
  133. limit += 1
  134. try:
  135. msg = f"""
  136. **Query:** {text}
  137. **Definition:** __{results[i].definition}__
  138. **Example:** __{results[i].example}__"""
  139. answers.append(
  140. InlineQueryResultArticle(
  141. title=results[i].word,
  142. description=results[i].definition,
  143. input_message_content=InputTextMessageContent(msg)
  144. ))
  145. except KeyError:
  146. pass
  147. return answers
  148. async def google_search_func(answers, text):
  149. gresults = await GoogleSearch().async_search(text)
  150. limit = 0
  151. for i in gresults:
  152. if limit > 48:
  153. break
  154. limit += 1
  155. try:
  156. msg = f"""
  157. [{i['titles']}]({i['links']})
  158. {i['descriptions']}"""
  159. answers.append(
  160. InlineQueryResultArticle(
  161. title=i['titles'],
  162. description=i['descriptions'],
  163. input_message_content=InputTextMessageContent(
  164. msg,
  165. disable_web_page_preview=True
  166. )
  167. ))
  168. except KeyError:
  169. pass
  170. return answers
  171. async def wall_func(answers, text):
  172. results = await arq.wall(text)
  173. limit = 0
  174. for i in results:
  175. if limit > 48:
  176. break
  177. limit += 1
  178. try:
  179. answers.append(
  180. InlineQueryResultPhoto(
  181. photo_url=results[i].url_image,
  182. thumb_url=results[i].url_thumb,
  183. caption=f"[Source]({results[i].url_image})"
  184. ))
  185. except KeyError:
  186. pass
  187. return answers
  188. async def saavn_func(answers, text):
  189. buttons_list = []
  190. results = await arq.saavn(text)
  191. for i in results:
  192. buttons = InlineKeyboard(row_width=1)
  193. buttons.add(
  194. InlineKeyboardButton(
  195. 'Download | Play',
  196. url=results[i].media_url
  197. )
  198. )
  199. buttons_list.append(buttons)
  200. duration = await time_convert(results[i].duration)
  201. caption = f"""
  202. **Title:** {results[i].song}
  203. **Album:** {results[i].album}
  204. **Duration:** {duration}
  205. **Release:** {results[i].year}
  206. **Singers:** {results[i].singers}"""
  207. description = f"{results[i].album} | {duration} " \
  208. + f"| {results[i].singers} ({results[i].year})"
  209. try:
  210. answers.append(
  211. InlineQueryResultArticle(
  212. title=results[i].song,
  213. input_message_content=InputTextMessageContent(
  214. caption,
  215. disable_web_page_preview=True
  216. ),
  217. description=description,
  218. thumb_url=results[i].image,
  219. reply_markup=buttons_list[i]
  220. ))
  221. except (KeyError, ValueError):
  222. pass
  223. return answers
  224. async def deezer_func(answers, text):
  225. buttons_list = []
  226. results = await arq.deezer(text, 5)
  227. for i in results:
  228. buttons = InlineKeyboard(row_width=1)
  229. buttons.add(
  230. InlineKeyboardButton(
  231. 'Download | Play',
  232. url=results[i].url
  233. )
  234. )
  235. buttons_list.append(buttons)
  236. duration = await time_convert(results[i].duration)
  237. caption = f"""
  238. **Title:** {results[i].title}
  239. **Artist:** {results[i].artist}
  240. **Duration:** {duration}
  241. **Source:** [Deezer]({results[i].source})"""
  242. description = f"{results[i].artist} | {duration}"
  243. try:
  244. answers.append(
  245. InlineQueryResultArticle(
  246. title=results[i].title,
  247. thumb_url=results[i].thumbnail,
  248. description=description,
  249. input_message_content=InputTextMessageContent(
  250. caption,
  251. disable_web_page_preview=True
  252. ),
  253. reply_markup=buttons_list[i]
  254. ))
  255. except (KeyError, ValueError):
  256. pass
  257. return answers
  258. # Used my api key here, don't fuck with it
  259. async def shortify(url):
  260. if "." not in url:
  261. return
  262. header = {
  263. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  264. 'Content-Type': 'application/json'
  265. }
  266. payload = {
  267. "long_url": f"{url}"
  268. }
  269. payload = json.dumps(payload)
  270. async with aiohttp.ClientSession() as session:
  271. async with session.post("https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload) as resp:
  272. data = await resp.json()
  273. msg = f"**Original Url:** {url}\n**Shortened Url:** {data['link']}"
  274. a = []
  275. b = InlineQueryResultArticle(
  276. title="Link Shortened!",
  277. description=data['link'],
  278. input_message_content=InputTextMessageContent(
  279. msg, disable_web_page_preview=True)
  280. )
  281. a.append(b)
  282. return a
  283. async def torrent_func(answers, text):
  284. results = await arq.torrent(text)
  285. limit = 0
  286. for i in results:
  287. if limit > 48:
  288. break
  289. title = results[i].name
  290. size = results[i].size
  291. seeds = results[i].seeds
  292. leechs = results[i].leechs
  293. upload_date = results[i].uploaded + " Ago"
  294. magnet = results[i].magnet
  295. caption = f"""
  296. **Title:** __{title}__
  297. **Size:** __{size}__
  298. **Seeds:** __{seeds}__
  299. **Leechs:** __{leechs}__
  300. **Uploaded:** __{upload_date}__
  301. **Magnet:** `{magnet}`"""
  302. description = f"{size} | {upload_date} | Seeds: {seeds}"
  303. try:
  304. answers.append(
  305. InlineQueryResultArticle(
  306. title=title,
  307. description=description,
  308. input_message_content=InputTextMessageContent(
  309. caption,
  310. disable_web_page_preview=True
  311. )
  312. )
  313. )
  314. limit += 1
  315. except (KeyError, ValueError):
  316. pass
  317. return answers
  318. async def youtube_func(answers, text):
  319. results = await arq.youtube(text)
  320. limit = 0
  321. for i in results:
  322. if limit > 48:
  323. break
  324. limit += 1
  325. buttons = InlineKeyboard(row_width=1)
  326. video_url = f"https://youtube.com{results[i].url_suffix}"
  327. buttons.add(
  328. InlineKeyboardButton(
  329. 'Watch',
  330. url=video_url
  331. )
  332. )
  333. caption = f"""
  334. **Title:** {results[i].title}
  335. **Views:** {results[i].views}
  336. **Channel:** {results[i].channel}
  337. **Duration:** {results[i].duration}
  338. **Uploaded:** {results[i].publish_time}
  339. **Description:** {results[i].long_desc}"""
  340. description = f"{results[i].views} | {results[i].channel} | " \
  341. + f"{results[i].duration} | {results[i].publish_time}"
  342. try:
  343. answers.append(
  344. InlineQueryResultArticle(
  345. title=results[i].title,
  346. thumb_url=results[i].thumbnails[0],
  347. description=description,
  348. input_message_content=InputTextMessageContent(
  349. caption,
  350. disable_web_page_preview=True
  351. ),
  352. reply_markup=buttons
  353. ))
  354. except (KeyError, ValueError):
  355. pass
  356. return answers
  357. async def lyrics_func(answers, text):
  358. song = await arq.lyrics(text)
  359. lyrics = song.lyrics
  360. song = lyrics.splitlines()
  361. song_name = song[0]
  362. artist = song[1]
  363. if len(lyrics) > 4095:
  364. lyrics = await paste(lyrics)
  365. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  366. msg = f"__{lyrics}__"
  367. answers.append(
  368. InlineQueryResultArticle(
  369. title=song_name,
  370. description=artist,
  371. input_message_content=InputTextMessageContent(msg)
  372. ))
  373. return answers
  374. async def eval_func(answers, text, user_id):
  375. if user_id not in SUDOERS:
  376. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  377. answers.append(
  378. InlineQueryResultArticle(
  379. title="ERROR",
  380. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  381. input_message_content=InputTextMessageContent(msg)
  382. ))
  383. return answers
  384. if str(text)[-1] != ":":
  385. msg = "**ERROR**\n__Put A ':' After The Code To Execute It__"
  386. answers.append(
  387. InlineQueryResultArticle(
  388. title="ERROR",
  389. description="Put A ':' After The Code To Execute It",
  390. input_message_content=InputTextMessageContent(msg)
  391. ))
  392. return answers
  393. text = text[0:-1]
  394. result = await eval_executer_func(text)
  395. res = result[0]
  396. output = result[1]
  397. time_taken = result[2]
  398. msg = f"{res}"
  399. button = InlineKeyboard(row_width=1)
  400. button.add(
  401. InlineKeyboardButton(
  402. text=f"{time_taken} Seconds",
  403. callback_data="ok_lol"
  404. )
  405. )
  406. answers.append(
  407. InlineQueryResultArticle(
  408. title=f"Took {time_taken} Seconds.",
  409. description=output,
  410. reply_markup=button,
  411. input_message_content=InputTextMessageContent(msg)
  412. ))
  413. return answers
  414. async def github_user_func(answers, text):
  415. URL = f"https://api.github.com/users/{text}"
  416. result = await fetch(URL)
  417. buttons = InlineKeyboard(row_width=1)
  418. buttons.add(InlineKeyboardButton(
  419. text="Open On Github",
  420. url=f"https://github.com/{text}"
  421. ))
  422. caption = f"""
  423. **Info Of {result['name']}**
  424. **Username:** `{text}`
  425. **Bio:** `{result['bio']}`
  426. **Profile Link:** [Here]({result['html_url']})
  427. **Company:** `{result['company']}`
  428. **Created On:** `{result['created_at']}`
  429. **Repositories:** `{result['public_repos']}`
  430. **Blog:** `{result['blog']}`
  431. **Location:** `{result['location']}`
  432. **Followers:** `{result['followers']}`
  433. **Following:** `{result['following']}`"""
  434. answers.append(
  435. InlineQueryResultPhoto(
  436. photo_url=result['avatar_url'],
  437. caption=caption,
  438. reply_markup=buttons
  439. ))
  440. return answers
  441. async def github_repo_func(answers, text):
  442. text = text.replace("https://github.com/", "")
  443. text = text.replace("http://github.com/", "")
  444. if text[-1] == "/":
  445. text = text[0:-1]
  446. URL = f"https://api.github.com/repos/{text}"
  447. URL2 = f"https://api.github.com/repos/{text}/contributors"
  448. results = await asyncio.gather(fetch(URL), fetch(URL2))
  449. r = results[0]
  450. r1 = results[1]
  451. commits = 0
  452. for developer in r1:
  453. commits += developer['contributions']
  454. buttons = InlineKeyboard(row_width=1)
  455. buttons.add(
  456. InlineKeyboardButton(
  457. 'Open On Github',
  458. url=f"https://github.com/{text}"
  459. )
  460. )
  461. caption = f"""
  462. **Info Of {r['full_name']}**
  463. **Stars:** `{r['stargazers_count']}`
  464. **Watchers:** `{r['watchers_count']}`
  465. **Forks:** `{r['forks_count']}`
  466. **Commits:** `{commits}`
  467. **Is Fork:** `{r['fork']}`
  468. **Language:** `{r['language']}`
  469. **Contributors:** `{len(r1)}`
  470. **License:** `{r['license']['name'] if r['license'] else None}`
  471. **Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
  472. **Created On:** `{r['created_at']}`
  473. **Homepage:** {r['homepage']}
  474. **Description:** __{r['description']}__"""
  475. answers.append(
  476. InlineQueryResultArticle(
  477. title="Found Repo",
  478. description=text,
  479. reply_markup=buttons,
  480. input_message_content=InputTextMessageContent(
  481. caption,
  482. disable_web_page_preview=True
  483. )
  484. ))
  485. return answers
  486. async def tg_search_func(answers, text, user_id):
  487. if user_id not in SUDOERS:
  488. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  489. answers.append(
  490. InlineQueryResultArticle(
  491. title="ERROR",
  492. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  493. input_message_content=InputTextMessageContent(msg)
  494. ))
  495. return answers
  496. if str(text)[-1] != ":":
  497. msg = "**ERROR**\n__Put A ':' After The Text To Search__"
  498. answers.append(
  499. InlineQueryResultArticle(
  500. title="ERROR",
  501. description="Put A ':' After The Text To Search",
  502. input_message_content=InputTextMessageContent(msg)
  503. ))
  504. return answers
  505. text = text[0:-1]
  506. async for message in app2.search_global(text, limit=49):
  507. buttons = InlineKeyboard(row_width=2)
  508. buttons.add(
  509. InlineKeyboardButton(
  510. text="Origin",
  511. url=message.link if message.link else "https://t.me/telegram"
  512. ),
  513. InlineKeyboardButton(
  514. text="Search again",
  515. switch_inline_query_current_chat="search"
  516. )
  517. )
  518. name = message.from_user.first_name if message.from_user.first_name else "NO NAME"
  519. caption = f"""
  520. **Query:** {text}
  521. **Name:** {str(name)} [`{message.from_user.id}`]
  522. **Chat:** {str(message.chat.title)} [`{message.chat.id}`]
  523. **Date:** {ctime(message.date)}
  524. **Text:** >>
  525. {message.text.markdown if message.text else message.caption if message.caption else '[NO_TEXT]'}
  526. """
  527. result = InlineQueryResultArticle(
  528. title=name,
  529. description=message.text if message.text else "[NO_TEXT]",
  530. reply_markup=buttons,
  531. input_message_content=InputTextMessageContent(
  532. caption,
  533. disable_web_page_preview=True
  534. )
  535. )
  536. answers.append(result)
  537. return answers
  538. async def music_inline_func(answers, query):
  539. chat_id = -1001445180719
  540. group_invite = "https://t.me/joinchat/vSDE2DuGK4Y4Nzll"
  541. try:
  542. messages = [m async for m in app2.search_messages(chat_id, query, filter="audio", limit=199)]
  543. except Exception as e:
  544. print(e)
  545. msg = f"You Need To Join Here With Your Bot And Userbot To Get Cached Music.\n{group_invite}"
  546. answers.append(
  547. InlineQueryResultArticle(
  548. title="ERROR",
  549. description="Click Here To Know More.",
  550. input_message_content=InputTextMessageContent(
  551. msg,
  552. disable_web_page_preview=True
  553. )
  554. )
  555. )
  556. return answers
  557. messages_ids_and_duration = []
  558. for f_ in messages:
  559. messages_ids_and_duration.append(
  560. {"message_id": f_.message_id,
  561. "duration": f_.audio.duration if f_.audio.duration else 0}
  562. )
  563. messages = list(
  564. {v["duration"]: v for v in messages_ids_and_duration}.values())
  565. messages_ids = []
  566. for ff_ in messages:
  567. messages_ids.append(ff_['message_id'])
  568. messages = await app.get_messages(chat_id, messages_ids[0:48])
  569. for message_ in messages:
  570. answers.append(
  571. InlineQueryResultCachedDocument(
  572. file_id=message_.audio.file_id,
  573. title=message_.audio.title
  574. )
  575. )
  576. return answers
  577. async def wiki_func(answers, text):
  578. data = await arq.wiki(text)
  579. msg = f"""
  580. **QUERY:**
  581. {data['title']}
  582. **ANSWER:**
  583. __{data['answer']}__"""
  584. answers.append(
  585. InlineQueryResultArticle(
  586. title=data['title'],
  587. description=data['answer'],
  588. input_message_content=InputTextMessageContent(msg)
  589. )
  590. )
  591. return answers
  592. async def speedtest_init(query):
  593. answers = []
  594. user_id = query.from_user.id
  595. if user_id not in SUDOERS:
  596. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  597. answers.append(
  598. InlineQueryResultArticle(
  599. title="ERROR",
  600. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  601. input_message_content=InputTextMessageContent(msg)
  602. ))
  603. return answers
  604. msg = "**Click The Button Below To Perform A Speedtest**"
  605. button = InlineKeyboard(row_width=1)
  606. button.add(InlineKeyboardButton(
  607. text="Test", callback_data="test_speedtest"))
  608. answers.append(
  609. InlineQueryResultArticle(
  610. title="Click Here",
  611. input_message_content=InputTextMessageContent(msg),
  612. reply_markup=button
  613. )
  614. )
  615. return answers
  616. """ callback query for the function above """
  617. @app.on_callback_query(filters.regex("test_speedtest"))
  618. async def test_speedtest_cq(_, cq):
  619. if cq.from_user.id not in SUDOERS:
  620. await cq.answer("This Isn't For You!")
  621. return
  622. inline_message_id = cq.inline_message_id
  623. await app.edit_inline_text(
  624. inline_message_id,
  625. "**Testing**"
  626. )
  627. download, upload, info = await test_speedtest()
  628. msg = f"""
  629. **Download:** `{download}`
  630. **Upload:** `{upload}`
  631. **Latency:** `{info['latency']} ms`
  632. **Country:** `{info['country']} [{info['cc']}]`
  633. **Latitude:** `{info['lat']}`
  634. **Longitude:** `{info['lon']}`
  635. """
  636. await app.edit_inline_text(
  637. inline_message_id,
  638. msg
  639. )
  640. async def pastebin_func(answers, link):
  641. link = link.split("/")
  642. if link[3] == "c":
  643. chat, message_id = int("-100" + link[4]), int(link[5])
  644. else:
  645. chat, message_id = link[3], link[4]
  646. m = await app.get_messages(chat, message_ids=int(message_id))
  647. if not m.text and not m.document:
  648. m = await app2.get_messages(chat, message_ids=int(message_id))
  649. if m.text:
  650. content = m.text
  651. else:
  652. if m.document.file_size > 1048576:
  653. answers.append(
  654. InlineQueryResultArticle(
  655. title="DOCUMENT TOO BIG",
  656. description="Maximum supported size is 1MB",
  657. input_message_content=InputTextMessageContent(
  658. "DOCUMENT TOO BIG")
  659. )
  660. )
  661. return answers
  662. doc = await m.download()
  663. async with aiofiles.open(doc, mode="r") as f:
  664. content = await f.read()
  665. os.remove(doc)
  666. link = await paste(content)
  667. preview = link + "/preview.png"
  668. status_code = await get_http_status_code(preview)
  669. i = 0
  670. while status_code != 200:
  671. if i == 5:
  672. break
  673. status_code = await get_http_status_code(preview)
  674. await asyncio.sleep(0.2)
  675. i += 1
  676. await app.send_photo(USERBOT_ID, preview) # To Pre-cache the media
  677. buttons = InlineKeyboard(row_width=1)
  678. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  679. answers.append(
  680. InlineQueryResultPhoto(
  681. photo_url=preview,
  682. reply_markup=buttons
  683. )
  684. )
  685. return answers
  686. async def pmpermit_func(answers, user_id, victim):
  687. if user_id != USERBOT_ID:
  688. return
  689. caption = f"Hi, I'm {USERBOT_NAME}, What are you here for?, You'll be blocked if you send more than 5 messages."
  690. buttons = InlineKeyboard(row_width=2)
  691. buttons.add(
  692. InlineKeyboardButton(
  693. text="To Scam You",
  694. callback_data="pmpermit to_scam_you a"
  695. ),
  696. InlineKeyboardButton(
  697. text="For promotion",
  698. callback_data="pmpermit to_scam_you a"
  699. ),
  700. InlineKeyboardButton(
  701. text="Approve me",
  702. callback_data="pmpermit approve_me a"
  703. ),
  704. InlineKeyboardButton(
  705. text="Approve",
  706. callback_data=f"pmpermit approve {victim}"
  707. )
  708. )
  709. answers.append(
  710. InlineQueryResultArticle(
  711. title="do_not_click_here",
  712. reply_markup=buttons,
  713. input_message_content=InputTextMessageContent(caption)
  714. )
  715. )
  716. return answers
  717. async def ping_func(answers):
  718. t1 = time()
  719. ping = Ping(ping_id=randint(696969, 6969696))
  720. await app.send(ping)
  721. t2 = time()
  722. ping = f"{str(round((t2 - t1), 2))} Seconds"
  723. answers.append(
  724. InlineQueryResultArticle(
  725. title=ping,
  726. input_message_content=InputTextMessageContent(
  727. f"__**{ping}**__")
  728. )
  729. )
  730. return answers