inlinefuncs.py 17 KB

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