inlinefuncs.py 23 KB

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