inlinefuncs.py 24 KB

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