inlinefuncs.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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 json
  22. import sys
  23. import asyncio
  24. from pyrogram.types import (
  25. InlineQueryResultArticle,
  26. InputTextMessageContent,
  27. InlineKeyboardButton,
  28. InlineQueryResultPhoto,
  29. )
  30. from pyrogram.raw.functions import Ping
  31. from googletrans import Translator
  32. from search_engine_parser import GoogleSearch
  33. from pykeyboard import InlineKeyboard
  34. from sys import version as pyver
  35. from motor import version as mongover
  36. from pyrogram import __version__ as pyrover, filters
  37. from time import time, ctime
  38. from random import randint
  39. from wbb.utils.fetch import fetch
  40. from wbb.modules.userbot import eval_executer_func
  41. from wbb.utils.functions import test_speedtest, get_http_status_code
  42. from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
  43. from wbb.utils.pastebin import paste
  44. from wbb.core.types import InlineQueryResultCachedDocument
  45. from wbb import (
  46. arq, app, app2, USERBOT_USERNAME,
  47. BOT_USERNAME, USERBOT_ID,
  48. SUDOERS, USERBOT_NAME
  49. )
  50. async def inline_help_func(__HELP__):
  51. buttons = InlineKeyboard(row_width=2)
  52. buttons.add(
  53. InlineKeyboardButton(
  54. 'Get More Help.',
  55. url=f"t.me/{BOT_USERNAME}?start=start"
  56. ),
  57. InlineKeyboardButton(
  58. "Go Inline!",
  59. switch_inline_query_current_chat=""
  60. )
  61. )
  62. answerss = [
  63. InlineQueryResultArticle(
  64. title="Inline Commands",
  65. description="Help Related To Inline Usage.",
  66. input_message_content=InputTextMessageContent(__HELP__),
  67. thumb_url="https://hamker.me/cy00x5x.png",
  68. reply_markup=buttons
  69. )
  70. ]
  71. answerss = await alive_function(answerss)
  72. return answerss
  73. async def alive_function(answers):
  74. buttons = InlineKeyboard(row_width=2)
  75. bot_state = 'Dead' if not await app.get_me() else 'Alive'
  76. ubot_state = 'Dead' if not await app2.get_me() else 'Alive'
  77. buttons.add(
  78. InlineKeyboardButton(
  79. 'Stats',
  80. callback_data='stats_callback'
  81. ),
  82. InlineKeyboardButton(
  83. "Go Inline!",
  84. switch_inline_query_current_chat=""
  85. )
  86. )
  87. msg = f"""
  88. **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
  89. **MainBot:** `{bot_state}`
  90. **UserBot:** `{ubot_state}`
  91. **Python:** `{pyver.split()[0]}`
  92. **Pyrogram:** `{pyrover}`
  93. **MongoDB:** `{mongover}`
  94. **Platform:** `{sys.platform}`
  95. **Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/{USERBOT_USERNAME})
  96. """
  97. answers.append(
  98. InlineQueryResultArticle(
  99. title='Alive',
  100. description="Check Bot's Stats",
  101. thumb_url="https://static2.aniimg.com/upload/20170515/414/c/d/7/cd7EEF.jpg",
  102. input_message_content=InputTextMessageContent(
  103. msg,
  104. disable_web_page_preview=True
  105. ),
  106. reply_markup=buttons,
  107. )
  108. )
  109. return answers
  110. async def translate_func(answers, lang, tex):
  111. i = Translator().translate(tex, dest=lang)
  112. msg = f"""
  113. __**Translated to {lang}**__
  114. **INPUT:**
  115. {tex}
  116. **OUTPUT:**
  117. {i.text}"""
  118. answers.append(
  119. InlineQueryResultArticle(
  120. title=f'Translated to {lang}',
  121. description=i.text,
  122. input_message_content=InputTextMessageContent(msg)
  123. )
  124. )
  125. return answers
  126. async def urban_func(answers, text):
  127. results = await arq.urbandict(text)
  128. limit = 0
  129. for i in results:
  130. if limit > 48:
  131. break
  132. limit += 1
  133. try:
  134. msg = f"""
  135. **Query:** {text}
  136. **Definition:** __{results[i].definition}__
  137. **Example:** __{results[i].example}__"""
  138. answers.append(
  139. InlineQueryResultArticle(
  140. title=results[i].word,
  141. description=results[i].definition,
  142. input_message_content=InputTextMessageContent(msg)
  143. ))
  144. except KeyError:
  145. pass
  146. return answers
  147. async def google_search_func(answers, text):
  148. gresults = await GoogleSearch().async_search(text)
  149. limit = 0
  150. for i in gresults:
  151. if limit > 48:
  152. break
  153. limit += 1
  154. try:
  155. msg = f"""
  156. [{i['titles']}]({i['links']})
  157. {i['descriptions']}"""
  158. answers.append(
  159. InlineQueryResultArticle(
  160. title=i['titles'],
  161. description=i['descriptions'],
  162. input_message_content=InputTextMessageContent(
  163. msg,
  164. disable_web_page_preview=True
  165. )
  166. ))
  167. except KeyError:
  168. pass
  169. return answers
  170. async def wall_func(answers, text):
  171. results = await arq.wall(text)
  172. limit = 0
  173. for i in results:
  174. if limit > 48:
  175. break
  176. limit += 1
  177. try:
  178. answers.append(
  179. InlineQueryResultPhoto(
  180. photo_url=results[i].url_image,
  181. thumb_url=results[i].url_thumb,
  182. caption=f"[Source]({results[i].url_image})"
  183. ))
  184. except KeyError:
  185. pass
  186. return answers
  187. async def saavn_func(answers, text):
  188. buttons_list = []
  189. results = await arq.saavn(text)
  190. for i in results:
  191. buttons = InlineKeyboard(row_width=1)
  192. buttons.add(
  193. InlineKeyboardButton(
  194. 'Download | Play',
  195. url=results[i].media_url
  196. )
  197. )
  198. buttons_list.append(buttons)
  199. duration = await time_convert(results[i].duration)
  200. caption = f"""
  201. **Title:** {results[i].song}
  202. **Album:** {results[i].album}
  203. **Duration:** {duration}
  204. **Release:** {results[i].year}
  205. **Singers:** {results[i].singers}"""
  206. description = f"{results[i].album} | {duration} " \
  207. + f"| {results[i].singers} ({results[i].year})"
  208. try:
  209. answers.append(
  210. InlineQueryResultArticle(
  211. title=results[i].song,
  212. input_message_content=InputTextMessageContent(
  213. caption,
  214. disable_web_page_preview=True
  215. ),
  216. description=description,
  217. thumb_url=results[i].image,
  218. reply_markup=buttons_list[i]
  219. ))
  220. except (KeyError, ValueError):
  221. pass
  222. return answers
  223. async def deezer_func(answers, text):
  224. buttons_list = []
  225. results = await arq.deezer(text, 5)
  226. for i in results:
  227. buttons = InlineKeyboard(row_width=1)
  228. buttons.add(
  229. InlineKeyboardButton(
  230. 'Download | Play',
  231. url=results[i].url
  232. )
  233. )
  234. buttons_list.append(buttons)
  235. duration = await time_convert(results[i].duration)
  236. caption = f"""
  237. **Title:** {results[i].title}
  238. **Artist:** {results[i].artist}
  239. **Duration:** {duration}
  240. **Source:** [Deezer]({results[i].source})"""
  241. description = f"{results[i].artist} | {duration}"
  242. try:
  243. answers.append(
  244. InlineQueryResultArticle(
  245. title=results[i].title,
  246. thumb_url=results[i].thumbnail,
  247. description=description,
  248. input_message_content=InputTextMessageContent(
  249. caption,
  250. disable_web_page_preview=True
  251. ),
  252. reply_markup=buttons_list[i]
  253. ))
  254. except (KeyError, ValueError):
  255. pass
  256. return answers
  257. # Used my api key here, don't fuck with it
  258. async def shortify(url):
  259. if "." not in url:
  260. return
  261. header = {
  262. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  263. 'Content-Type': 'application/json'
  264. }
  265. payload = {
  266. "long_url": f"{url}"
  267. }
  268. payload = json.dumps(payload)
  269. async with aiohttp.ClientSession() as session:
  270. async with session.post("https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload) as resp:
  271. data = await resp.json()
  272. msg = f"**Original Url:** {url}\n**Shortened Url:** {data['link']}"
  273. a = []
  274. b = InlineQueryResultArticle(
  275. title="Link Shortened!",
  276. description=data['link'],
  277. input_message_content=InputTextMessageContent(
  278. msg, disable_web_page_preview=True)
  279. )
  280. a.append(b)
  281. return a
  282. async def torrent_func(answers, text):
  283. results = await arq.torrent(text)
  284. limit = 0
  285. for i in results:
  286. if limit > 48:
  287. break
  288. title = results[i].name
  289. size = results[i].size
  290. seeds = results[i].seeds
  291. leechs = results[i].leechs
  292. upload_date = results[i].uploaded + " Ago"
  293. magnet = results[i].magnet
  294. caption = f"""
  295. **Title:** __{title}__
  296. **Size:** __{size}__
  297. **Seeds:** __{seeds}__
  298. **Leechs:** __{leechs}__
  299. **Uploaded:** __{upload_date}__
  300. **Magnet:** `{magnet}`"""
  301. description = f"{size} | {upload_date} | Seeds: {seeds}"
  302. try:
  303. answers.append(
  304. InlineQueryResultArticle(
  305. title=title,
  306. description=description,
  307. input_message_content=InputTextMessageContent(
  308. caption,
  309. disable_web_page_preview=True
  310. )
  311. )
  312. )
  313. limit += 1
  314. except (KeyError, ValueError):
  315. pass
  316. return answers
  317. async def youtube_func(answers, text):
  318. results = await arq.youtube(text)
  319. limit = 0
  320. for i in results:
  321. if limit > 48:
  322. break
  323. limit += 1
  324. buttons = InlineKeyboard(row_width=1)
  325. video_url = f"https://youtube.com{results[i].url_suffix}"
  326. buttons.add(
  327. InlineKeyboardButton(
  328. 'Watch',
  329. url=video_url
  330. )
  331. )
  332. caption = f"""
  333. **Title:** {results[i].title}
  334. **Views:** {results[i].views}
  335. **Channel:** {results[i].channel}
  336. **Duration:** {results[i].duration}
  337. **Uploaded:** {results[i].publish_time}
  338. **Description:** {results[i].long_desc}"""
  339. description = f"{results[i].views} | {results[i].channel} | " \
  340. + f"{results[i].duration} | {results[i].publish_time}"
  341. try:
  342. answers.append(
  343. InlineQueryResultArticle(
  344. title=results[i].title,
  345. thumb_url=results[i].thumbnails[0],
  346. description=description,
  347. input_message_content=InputTextMessageContent(
  348. caption,
  349. disable_web_page_preview=True
  350. ),
  351. reply_markup=buttons
  352. ))
  353. except (KeyError, ValueError):
  354. pass
  355. return answers
  356. async def lyrics_func(answers, text):
  357. song = await arq.lyrics(text)
  358. lyrics = song.lyrics
  359. song = lyrics.splitlines()
  360. song_name = song[0]
  361. artist = song[1]
  362. if len(lyrics) > 4095:
  363. lyrics = await paste(lyrics)
  364. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  365. msg = f"__{lyrics}__"
  366. answers.append(
  367. InlineQueryResultArticle(
  368. title=song_name,
  369. description=artist,
  370. input_message_content=InputTextMessageContent(msg)
  371. ))
  372. return answers
  373. async def eval_func(answers, text, user_id):
  374. if user_id not in SUDOERS:
  375. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  376. answers.append(
  377. InlineQueryResultArticle(
  378. title="ERROR",
  379. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  380. input_message_content=InputTextMessageContent(msg)
  381. ))
  382. return answers
  383. if str(text)[-1] != ":":
  384. msg = "**ERROR**\n__Put A ':' After The Code To Execute It__"
  385. answers.append(
  386. InlineQueryResultArticle(
  387. title="ERROR",
  388. description="Put A ':' After The Code To Execute It",
  389. input_message_content=InputTextMessageContent(msg)
  390. ))
  391. return answers
  392. text = text[0:-1]
  393. result = await eval_executer_func(text)
  394. res = result[0]
  395. output = result[1]
  396. time_taken = result[2]
  397. msg = f"{res}"
  398. button = InlineKeyboard(row_width=1)
  399. button.add(
  400. InlineKeyboardButton(
  401. text=f"{time_taken} Seconds",
  402. callback_data="ok_lol"
  403. )
  404. )
  405. answers.append(
  406. InlineQueryResultArticle(
  407. title=f"Took {time_taken} Seconds.",
  408. description=output,
  409. reply_markup=button,
  410. input_message_content=InputTextMessageContent(msg)
  411. ))
  412. return answers
  413. async def github_user_func(answers, text):
  414. URL = f"https://api.github.com/users/{text}"
  415. result = await fetch(URL)
  416. buttons = InlineKeyboard(row_width=1)
  417. buttons.add(InlineKeyboardButton(
  418. text="Open On Github",
  419. url=f"https://github.com/{text}"
  420. ))
  421. caption = f"""
  422. **Info Of {result['name']}**
  423. **Username:** `{text}`
  424. **Bio:** `{result['bio']}`
  425. **Profile Link:** [Here]({result['html_url']})
  426. **Company:** `{result['company']}`
  427. **Created On:** `{result['created_at']}`
  428. **Repositories:** `{result['public_repos']}`
  429. **Blog:** `{result['blog']}`
  430. **Location:** `{result['location']}`
  431. **Followers:** `{result['followers']}`
  432. **Following:** `{result['following']}`"""
  433. answers.append(
  434. InlineQueryResultPhoto(
  435. photo_url=result['avatar_url'],
  436. caption=caption,
  437. reply_markup=buttons
  438. ))
  439. return answers
  440. async def github_repo_func(answers, text):
  441. url = 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. pastebin_cache = {}
  641. async def pastebin_func(answers, link):
  642. global pastebin_cache
  643. link = link.split("/")
  644. if link[3] == "c":
  645. chat, message_id = int("-100" + link[4]), int(link[5])
  646. else:
  647. chat, message_id = link[3], link[4]
  648. m = await app.get_messages(chat, message_ids=int(message_id))
  649. if not m.text:
  650. m = await app2.get_messages(chat, message_ids=int(message_id))
  651. if m.text not in pastebin_cache:
  652. link = await paste(m.text)
  653. preview = link + "/preview.png"
  654. pastebin_cache[m.text] = link
  655. status_code = await get_http_status_code(preview)
  656. i = 0
  657. while status_code != 200:
  658. if i == 5:
  659. break
  660. status_code = await get_http_status_code(preview)
  661. await asyncio.sleep(0.2)
  662. i += 1
  663. await app.send_photo(USERBOT_ID, preview) # To Pre-cache the media
  664. else:
  665. link = pastebin_cache[m.text]
  666. preview = link + "/preview.png"
  667. buttons = InlineKeyboard(row_width=1)
  668. buttons.add(InlineKeyboardButton(text="Paste Link", url=link))
  669. answers.append(
  670. InlineQueryResultPhoto(
  671. photo_url=preview,
  672. reply_markup=buttons
  673. )
  674. )
  675. return answers
  676. async def pmpermit_func(answers, user_id, victim):
  677. if user_id != USERBOT_ID:
  678. return
  679. caption = f"Hi, I'm {USERBOT_NAME}, What are you here for?, You'll be blocked if you send more than 5 messages."
  680. buttons = InlineKeyboard(row_width=3)
  681. buttons.add(
  682. InlineKeyboardButton(
  683. text="To Scam You",
  684. callback_data="pmpermit to_scam_you"
  685. ),
  686. InlineKeyboardButton(
  687. text="For promotion",
  688. callback_data="pmpermit to_scam_you"
  689. ),
  690. InlineKeyboardButton(
  691. text="ChitChats",
  692. callback_data="pmpermit chitchats"
  693. ),
  694. InlineKeyboardButton(
  695. text="Approve me",
  696. callback_data="pmpermit approve_me"
  697. ),
  698. InlineKeyboardButton(
  699. text="Approve",
  700. callback_data=f"pmpermit approve {victim}"
  701. )
  702. )
  703. answers.append(
  704. InlineQueryResultArticle(
  705. title="do_not_click_here",
  706. reply_markup=buttons,
  707. input_message_content=InputTextMessageContent(caption)
  708. )
  709. )
  710. return answers
  711. async def ping_func(answers):
  712. t1 = time()
  713. ping = Ping(ping_id=randint(696969, 6969696))
  714. await app.send(ping)
  715. t2 = time()
  716. ping = f"{str(round((t2 - t1), 2))} Seconds"
  717. answers.append(
  718. InlineQueryResultArticle(
  719. title=ping,
  720. input_message_content=InputTextMessageContent(f"__**{ping}**__")
  721. )
  722. )
  723. return answers