inlinefuncs.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. import aiohttp
  2. import json
  3. import sys
  4. import asyncio
  5. from pyrogram.types import (
  6. InlineQueryResultArticle,
  7. InputTextMessageContent,
  8. InlineKeyboardButton,
  9. InlineQueryResultPhoto
  10. )
  11. from googletrans import Translator
  12. from search_engine_parser import GoogleSearch
  13. from pykeyboard import InlineKeyboard
  14. from sys import version as pyver
  15. from motor import version as mongover
  16. from pyrogram import __version__ as pyrover
  17. from time import time, ctime
  18. from wbb.modules.userbot import eval_executor_func
  19. from wbb.utils.fetch import fetch
  20. from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
  21. from wbb.utils.pastebin import paste
  22. from wbb import (
  23. arq, app, app2, USERBOT_USERNAME,
  24. BOT_USERNAME, LOG_GROUP_ID, USERBOT_ID
  25. )
  26. from wbb.core.types.InlineQueryResult import InlineQueryResultAudio
  27. async def deezaudio_func(answers):
  28. msg = "a"
  29. answers.append(
  30. InlineQueryResultAudio(
  31. audio_url="https://masstamilan2019download.com/tamil/2019%20Tamil%20Mp3/Oh%20My%20Kadavule/Kadhaippoma-Masstamilan.In.mp3",
  32. title="a",
  33. description="desc",
  34. input_message_content=InputTextMessageContent(msg)
  35. )
  36. )
  37. return answers
  38. async def inline_help_func(__HELP__):
  39. buttons = InlineKeyboard(row_width=2)
  40. buttons.add(
  41. InlineKeyboardButton(
  42. 'Get More Help.',
  43. url=f"t.me/{BOT_USERNAME}?start=start"
  44. ),
  45. InlineKeyboardButton(
  46. "Go Inline!",
  47. switch_inline_query_current_chat=""
  48. )
  49. )
  50. answerss = [
  51. InlineQueryResultArticle(
  52. title="Inline Commands",
  53. description="Help Related To Inline Usage.",
  54. input_message_content=InputTextMessageContent(__HELP__),
  55. thumb_url="https://hamker.me/cy00x5x.png",
  56. reply_markup=buttons
  57. )
  58. ]
  59. answerss = await alive_function(answerss)
  60. return answerss
  61. async def alive_function(answers):
  62. buttons = InlineKeyboard(row_width=2)
  63. bot_state = 'Dead' if not await app.get_me() else 'Alive'
  64. ubot_state = 'Dead' if not await app2.get_me() else 'Alive'
  65. buttons.add(
  66. InlineKeyboardButton(
  67. 'Stats',
  68. callback_data='stats_callback'
  69. ),
  70. InlineKeyboardButton(
  71. "Go Inline!",
  72. switch_inline_query_current_chat=""
  73. )
  74. )
  75. msg = f"""
  76. **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
  77. **MainBot:** `{bot_state}`
  78. **UserBot:** `{ubot_state}`
  79. **Python:** `{pyver.split()[0]}`
  80. **Pyrogram:** `{pyrover}`
  81. **MongoDB:** `{mongover}`
  82. **Platform:** `{sys.platform}`
  83. **Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/{USERBOT_USERNAME})
  84. """
  85. answers.append(
  86. InlineQueryResultArticle(
  87. title='Alive',
  88. description="Check Bot's Stats",
  89. thumb_url="https://static2.aniimg.com/upload/20170515/414/c/d/7/cd7EEF.jpg",
  90. input_message_content=InputTextMessageContent(
  91. msg,
  92. disable_web_page_preview=True
  93. ),
  94. reply_markup=buttons,
  95. )
  96. )
  97. return answers
  98. async def translate_func(answers, lang, tex):
  99. i = Translator().translate(tex, dest=lang)
  100. msg = f"""
  101. __**Translated to {lang}**__
  102. **INPUT:**
  103. {tex}
  104. **OUTPUT:**
  105. {i.text}"""
  106. answers.append(
  107. InlineQueryResultArticle(
  108. title=f'Translated to {lang}',
  109. description=i.text,
  110. input_message_content=InputTextMessageContent(msg)
  111. )
  112. )
  113. return answers
  114. async def urban_func(answers, text):
  115. results = await arq.urbandict(text)
  116. limit = 0
  117. for i in results:
  118. if limit > 48:
  119. break
  120. limit += 1
  121. msg = f"""
  122. **Query:** {text}
  123. **Definition:** __{results[i].definition}__
  124. **Example:** __{results[i].example}__"""
  125. answers.append(
  126. InlineQueryResultArticle(
  127. title=results[i].word,
  128. description=results[i].definition,
  129. input_message_content=InputTextMessageContent(msg)
  130. ))
  131. return answers
  132. async def google_search_func(answers, text):
  133. gresults = await GoogleSearch().async_search(text)
  134. limit = 0
  135. for i in gresults:
  136. if limit > 48:
  137. break
  138. limit += 1
  139. try:
  140. msg = f"""
  141. [{i['titles']}]({i['links']})
  142. {i['descriptions']}"""
  143. answers.append(
  144. InlineQueryResultArticle(
  145. title=i['titles'],
  146. description=i['descriptions'],
  147. input_message_content=InputTextMessageContent(
  148. msg,
  149. disable_web_page_preview=True
  150. )
  151. ))
  152. except KeyError:
  153. pass
  154. return answers
  155. async def wall_func(answers, text):
  156. results = await arq.wall(text)
  157. limit = 0
  158. for i in results:
  159. if limit > 48:
  160. break
  161. limit += 1
  162. try:
  163. answers.append(
  164. InlineQueryResultPhoto(
  165. photo_url=results[i].url_image,
  166. thumb_url=results[i].url_thumb,
  167. caption=f"[Source]({results[i].url_image})"
  168. ))
  169. except KeyError:
  170. pass
  171. return answers
  172. async def saavn_func(answers, text):
  173. buttons_list = []
  174. results = await arq.saavn(text)
  175. for i in results:
  176. buttons = InlineKeyboard(row_width=1)
  177. buttons.add(
  178. InlineKeyboardButton(
  179. 'Download | Play',
  180. url=results[i].media_url
  181. )
  182. )
  183. buttons_list.append(buttons)
  184. duration = await time_convert(results[i].duration)
  185. caption = f"""
  186. **Title:** {results[i].song}
  187. **Album:** {results[i].album}
  188. **Duration:** {duration}
  189. **Release:** {results[i].year}
  190. **Singers:** {results[i].singers}"""
  191. description = f"{results[i].album} | {duration} " \
  192. + f"| {results[i].singers} ({results[i].year})"
  193. try:
  194. answers.append(
  195. InlineQueryResultArticle(
  196. title=results[i].song,
  197. input_message_content=InputTextMessageContent(
  198. caption,
  199. disable_web_page_preview=True
  200. ),
  201. description=description,
  202. thumb_url=results[i].image,
  203. reply_markup=buttons_list[i]
  204. ))
  205. except (KeyError, ValueError):
  206. pass
  207. return answers
  208. async def deezer_func(answers, text):
  209. buttons_list = []
  210. results = await arq.deezer(text, 5)
  211. for i in results:
  212. buttons = InlineKeyboard(row_width=1)
  213. buttons.add(
  214. InlineKeyboardButton(
  215. 'Download | Play',
  216. url=results[i].url
  217. )
  218. )
  219. buttons_list.append(buttons)
  220. duration = await time_convert(results[i].duration)
  221. caption = f"""
  222. **Title:** {results[i].title}
  223. **Artist:** {results[i].artist}
  224. **Duration:** {duration}
  225. **Source:** [Deezer]({results[i].source})"""
  226. description = f"{results[i].artist} | {duration}"
  227. try:
  228. answers.append(
  229. InlineQueryResultArticle(
  230. title=results[i].title,
  231. thumb_url=results[i].thumbnail,
  232. description=description,
  233. input_message_content=InputTextMessageContent(
  234. caption,
  235. disable_web_page_preview=True
  236. ),
  237. reply_markup=buttons_list[i]
  238. ))
  239. except (KeyError, ValueError):
  240. pass
  241. return answers
  242. async def webss(url):
  243. start_time = time()
  244. if "." not in url:
  245. return
  246. screenshot = await fetch(f"https://patheticprogrammers.cf/ss?site={url}")
  247. end_time = time()
  248. try:
  249. m = await app.send_photo(LOG_GROUP_ID, photo=screenshot['url'])
  250. except TypeError:
  251. return
  252. await m.delete()
  253. a = []
  254. pic = InlineQueryResultPhoto(
  255. photo_url=screenshot['url'],
  256. caption=(f"`{url}`\n__Took {round(end_time - start_time)} Seconds.__")
  257. )
  258. a.append(pic)
  259. return a
  260. # Used my api key here, don't fuck with it
  261. async def shortify(url):
  262. if "." not in url:
  263. return
  264. header = {
  265. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  266. 'Content-Type': 'application/json'
  267. }
  268. payload = {
  269. "long_url": f"{url}"
  270. }
  271. payload = json.dumps(payload)
  272. async with aiohttp.ClientSession() as session:
  273. async with session.post("https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload) as resp:
  274. data = await resp.json()
  275. msg = f"**Original Url:** {url}\n**Shortened Url:** {data['link']}"
  276. a = []
  277. b = InlineQueryResultArticle(
  278. title="Link Shortened!",
  279. description=data['link'],
  280. input_message_content=InputTextMessageContent(
  281. msg, disable_web_page_preview=True)
  282. )
  283. a.append(b)
  284. return a
  285. async def torrent_func(answers, text):
  286. results = await arq.torrent(text)
  287. limit = 0
  288. for i in results:
  289. if limit > 48:
  290. break
  291. title = results[i].name
  292. size = results[i].size
  293. seeds = results[i].seeds
  294. leechs = results[i].leechs
  295. upload_date = results[i].uploaded + " Ago"
  296. magnet = results[i].magnet
  297. caption = f"""
  298. **Title:** __{title}__
  299. **Size:** __{size}__
  300. **Seeds:** __{seeds}__
  301. **Leechs:** __{leechs}__
  302. **Uploaded:** __{upload_date}__
  303. **Magnet:** __{magnet}__"""
  304. description = f"{size} | {upload_date} | Seeds: {seeds}"
  305. try:
  306. answers.append(
  307. InlineQueryResultArticle(
  308. title=title,
  309. description=description,
  310. input_message_content=InputTextMessageContent(
  311. caption,
  312. disable_web_page_preview=True
  313. )
  314. )
  315. )
  316. limit += 1
  317. except (KeyError, ValueError):
  318. pass
  319. return answers
  320. async def youtube_func(answers, text):
  321. results = await arq.youtube(text)
  322. limit = 0
  323. for i in results:
  324. if limit > 48:
  325. break
  326. limit += 1
  327. buttons = InlineKeyboard(row_width=1)
  328. video_url = f"https://youtube.com{results[i].url_suffix}"
  329. buttons.add(
  330. InlineKeyboardButton(
  331. 'Watch',
  332. url=video_url
  333. )
  334. )
  335. caption = f"""
  336. **Title:** {results[i].title}
  337. **Views:** {results[i].views}
  338. **Channel:** {results[i].channel}
  339. **Duration:** {results[i].duration}
  340. **Uploaded:** {results[i].publish_time}
  341. **Description:** {results[i].long_desc}"""
  342. description = f"{results[i].views} | {results[i].channel} | " \
  343. + f"{results[i].duration} | {results[i].publish_time}"
  344. try:
  345. answers.append(
  346. InlineQueryResultArticle(
  347. title=results[i].title,
  348. thumb_url=results[i].thumbnails[0],
  349. description=description,
  350. input_message_content=InputTextMessageContent(
  351. caption,
  352. disable_web_page_preview=True
  353. ),
  354. reply_markup=buttons
  355. ))
  356. except (KeyError, ValueError):
  357. pass
  358. return answers
  359. async def lyrics_func(answers, text):
  360. song = await arq.lyrics(text)
  361. lyrics = song.lyrics
  362. song = lyrics.splitlines()
  363. song_name = song[0]
  364. artist = song[1]
  365. if len(lyrics) > 4095:
  366. lyrics = await paste(lyrics)
  367. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  368. msg = f"__{lyrics}__"
  369. answers.append(
  370. InlineQueryResultArticle(
  371. title=song_name,
  372. description=artist,
  373. input_message_content=InputTextMessageContent(msg)
  374. ))
  375. return answers
  376. async def eval_func(answers, text, user_id):
  377. if user_id != USERBOT_ID:
  378. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  379. answers.append(
  380. InlineQueryResultArticle(
  381. title="ERROR",
  382. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  383. input_message_content=InputTextMessageContent(msg)
  384. ))
  385. return answers
  386. if str(text)[-1] != ":":
  387. msg = "**ERROR**\n__Put A ':' After The Code To Execute It__"
  388. answers.append(
  389. InlineQueryResultArticle(
  390. title="ERROR",
  391. description="Put A ':' After The Code To Execute It",
  392. input_message_content=InputTextMessageContent(msg)
  393. ))
  394. return answers
  395. text = text[0:-1]
  396. start_time = time()
  397. result = await eval_executor_func(text)
  398. output = result[1]
  399. result = result[0]
  400. msg = f"{result}"
  401. end_time = time()
  402. answers.append(
  403. InlineQueryResultArticle(
  404. title=f"Took {round(end_time - start_time)} Seconds.",
  405. description=output,
  406. input_message_content=InputTextMessageContent(msg)
  407. ))
  408. return answers
  409. async def github_user_func(answers, text):
  410. URL = f"https://api.github.com/users/{text}"
  411. result = await fetch(URL)
  412. buttons = InlineKeyboard(row_width=1)
  413. buttons.add(InlineKeyboardButton(
  414. text="Open On Github",
  415. url=f"https://github.com/{text}"
  416. ))
  417. caption = f"""
  418. **Info Of {result['name']}**
  419. **Username:** `{text}`
  420. **Bio:** `{result['bio']}`
  421. **Profile Link:** [Here]({result['html_url']})
  422. **Company:** `{result['company']}`
  423. **Created On:** `{result['created_at']}`
  424. **Repositories:** `{result['public_repos']}`
  425. **Blog:** `{result['blog']}`
  426. **Location:** `{result['location']}`
  427. **Followers:** `{result['followers']}`
  428. **Following:** `{result['following']}`"""
  429. answers.append(
  430. InlineQueryResultPhoto(
  431. photo_url=result['avatar_url'],
  432. caption=caption,
  433. reply_markup=buttons
  434. ))
  435. return answers
  436. async def github_repo_func(answers, text):
  437. URL = f"https://api.github.com/repos/{text}"
  438. URL2 = f"https://api.github.com/repos/{text}/contributors"
  439. results = await asyncio.gather(fetch(URL), fetch(URL2))
  440. r = results[0]
  441. r1 = results[1]
  442. commits = 0
  443. for developer in r1:
  444. commits += developer['contributions']
  445. buttons = InlineKeyboard(row_width=1)
  446. buttons.add(
  447. InlineKeyboardButton(
  448. 'Open On Github',
  449. url=f"https://github.com/{text}"
  450. )
  451. )
  452. caption = f"""
  453. **Info Of {r['full_name']}**
  454. **Stars:** `{r['stargazers_count']}`
  455. **Watchers:** `{r['watchers_count']}`
  456. **Forks:** `{r['forks_count']}`
  457. **Commits:** `{commits}`
  458. **Is Fork:** `{r['fork']}`
  459. **Language:** `{r['language']}`
  460. **Contributors:** `{len(r1)}`
  461. **License:** `{r['license']['name']}`
  462. **Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
  463. **Created On:** `{r['created_at']}`
  464. **Homepage:** {r['homepage']}
  465. **Description:** __{r['description']}__"""
  466. answers.append(
  467. InlineQueryResultArticle(
  468. title="Found Repo",
  469. description=text,
  470. reply_markup=buttons,
  471. input_message_content=InputTextMessageContent(
  472. caption,
  473. disable_web_page_preview=True
  474. )
  475. ))
  476. return answers
  477. async def tg_search_func(answers, text, user_id):
  478. if user_id != USERBOT_ID:
  479. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  480. answers.append(
  481. InlineQueryResultArticle(
  482. title="ERROR",
  483. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  484. input_message_content=InputTextMessageContent(msg)
  485. ))
  486. return answers
  487. if str(text)[-1] != ":":
  488. msg = "**ERROR**\n__Put A ':' After The Text To Search__"
  489. answers.append(
  490. InlineQueryResultArticle(
  491. title="ERROR",
  492. description="Put A ':' After The Text To Search",
  493. input_message_content=InputTextMessageContent(msg)
  494. ))
  495. return answers
  496. text = text[0:-1]
  497. async for message in app2.search_global(text, limit=49):
  498. buttons = InlineKeyboard(row_width=2)
  499. buttons.add(
  500. InlineKeyboardButton(
  501. text="Origin",
  502. url=message.link if message.link else "https://t.me/telegram"
  503. ),
  504. InlineKeyboardButton(
  505. text="Search again",
  506. switch_inline_query_current_chat="search"
  507. )
  508. )
  509. name = message.from_user.first_name if message.from_user.first_name else "NO NAME"
  510. caption = f"""
  511. **Query:** {text}
  512. **Name:** {str(name)} [`{message.from_user.id}`]
  513. **Chat:** {str(message.chat.title)} [`{message.chat.id}`]
  514. **Date:** {ctime(message.date)}
  515. **Text:** >>
  516. {message.text.markdown if message.text else message.caption if message.caption else "[NO_TEXT]"}
  517. """
  518. result = InlineQueryResultArticle(
  519. title=name,
  520. description=message.text if message.text else "[NO_TEXT]",
  521. reply_markup=buttons,
  522. input_message_content=InputTextMessageContent(
  523. caption,
  524. disable_web_page_preview=True
  525. )
  526. )
  527. answers.append(result)
  528. return answers