inlinefuncs.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. for i in results:
  105. msg = f"""
  106. **Query:** {text}
  107. **Definition:** __{results[i].definition}__
  108. **Example:** __{results[i].example}__"""
  109. answers.append(
  110. InlineQueryResultArticle(
  111. title=results[i].word,
  112. description=results[i].definition,
  113. input_message_content=InputTextMessageContent(msg)
  114. ))
  115. return answers
  116. async def google_search_func(answers, text):
  117. gresults = await GoogleSearch().async_search(text)
  118. for i in gresults:
  119. try:
  120. msg = f"""
  121. [{i['titles']}]({i['links']})
  122. {i['descriptions']}"""
  123. answers.append(
  124. InlineQueryResultArticle(
  125. title=i['titles'],
  126. description=i['descriptions'],
  127. input_message_content=InputTextMessageContent(
  128. msg,
  129. disable_web_page_preview=True
  130. )
  131. ))
  132. except KeyError:
  133. pass
  134. return answers
  135. async def wall_func(answers, text):
  136. results = await arq.wall(text)
  137. for i in results:
  138. try:
  139. answers.append(
  140. InlineQueryResultPhoto(
  141. photo_url=results[i].url_image,
  142. thumb_url=results[i].url_thumb,
  143. caption=f"[Source]({results[i].url_image})"
  144. ))
  145. except KeyError:
  146. pass
  147. return answers
  148. async def saavn_func(answers, text):
  149. buttons_list = []
  150. results = await arq.saavn(text)
  151. for i in results:
  152. buttons = InlineKeyboard(row_width=1)
  153. buttons.add(
  154. InlineKeyboardButton(
  155. 'Download | Play',
  156. url=results[i].media_url
  157. )
  158. )
  159. buttons_list.append(buttons)
  160. duration = await time_convert(results[i].duration)
  161. caption = f"""
  162. **Title:** {results[i].song}
  163. **Album:** {results[i].album}
  164. **Duration:** {duration}
  165. **Release:** {results[i].year}
  166. **Singers:** {results[i].singers}"""
  167. description = f"{results[i].album} | {duration} " \
  168. + f"| {results[i].singers} ({results[i].year})"
  169. try:
  170. answers.append(
  171. InlineQueryResultArticle(
  172. title=results[i].song,
  173. input_message_content=InputTextMessageContent(
  174. caption,
  175. disable_web_page_preview=True
  176. ),
  177. description=description,
  178. thumb_url=results[i].image,
  179. reply_markup=buttons_list[i]
  180. ))
  181. except (KeyError, ValueError):
  182. pass
  183. return answers
  184. async def deezer_func(answers, text):
  185. buttons_list = []
  186. results = await arq.deezer(text, 5)
  187. for i in results:
  188. buttons = InlineKeyboard(row_width=1)
  189. buttons.add(
  190. InlineKeyboardButton(
  191. 'Download | Play',
  192. url=results[i].url
  193. )
  194. )
  195. buttons_list.append(buttons)
  196. duration = await time_convert(results[i].duration)
  197. caption = f"""
  198. **Title:** {results[i].title}
  199. **Artist:** {results[i].artist}
  200. **Duration:** {duration}
  201. **Source:** [Deezer]({results[i].source})"""
  202. description = f"{results[i].artist} | {duration}"
  203. try:
  204. answers.append(
  205. InlineQueryResultArticle(
  206. title=results[i].title,
  207. thumb_url=results[i].thumbnail,
  208. description=description,
  209. input_message_content=InputTextMessageContent(
  210. caption,
  211. disable_web_page_preview=True
  212. ),
  213. reply_markup=buttons_list[i]
  214. ))
  215. except (KeyError, ValueError):
  216. pass
  217. return answers
  218. async def webss(url):
  219. start_time = time()
  220. if "." not in url:
  221. return
  222. screenshot = await fetch(f"https://patheticprogrammers.cf/ss?site={url}")
  223. end_time = time()
  224. try:
  225. m = await app.send_photo(LOG_GROUP_ID, photo=screenshot['url'])
  226. except TypeError:
  227. return
  228. await m.delete()
  229. a = []
  230. pic = InlineQueryResultPhoto(
  231. photo_url=screenshot['url'],
  232. caption=(f"`{url}`\n__Took {round(end_time - start_time)} Seconds.__")
  233. )
  234. a.append(pic)
  235. return a
  236. # Used my api key here, don't fuck with it
  237. async def shortify(url):
  238. if "." not in url:
  239. return
  240. header = {
  241. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  242. 'Content-Type': 'application/json'
  243. }
  244. payload = {
  245. "long_url": f"{url}"
  246. }
  247. payload = json.dumps(payload)
  248. async with aiohttp.ClientSession() as session:
  249. async with session.post("https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload) as resp:
  250. data = await resp.json()
  251. msg = f"**Original Url:** {url}\n**Shortened Url:** {data['link']}"
  252. a = []
  253. b = InlineQueryResultArticle(
  254. title="Link Shortened!",
  255. description=data['link'],
  256. input_message_content=InputTextMessageContent(
  257. msg, disable_web_page_preview=True)
  258. )
  259. a.append(b)
  260. return a
  261. async def torrent_func(answers, text):
  262. results = await arq.torrent(text)
  263. limit = 0
  264. for i in results:
  265. if limit > 48:
  266. break
  267. title = results[i].name
  268. size = results[i].size
  269. seeds = results[i].seeds
  270. leechs = results[i].leechs
  271. upload_date = results[i].uploaded + " Ago"
  272. magnet = results[i].magnet
  273. caption = f"""
  274. **Title:** __{title}__
  275. **Size:** __{size}__
  276. **Seeds:** __{seeds}__
  277. **Leechs:** __{leechs}__
  278. **Uploaded:** __{upload_date}__
  279. **Magnet:** __{magnet}__"""
  280. description = f"{size} | {upload_date} | Seeds: {seeds}"
  281. try:
  282. answers.append(
  283. InlineQueryResultArticle(
  284. title=title,
  285. description=description,
  286. input_message_content=InputTextMessageContent(
  287. caption,
  288. disable_web_page_preview=True
  289. )
  290. )
  291. )
  292. limit += 1
  293. except (KeyError, ValueError):
  294. pass
  295. return answers
  296. async def youtube_func(answers, text):
  297. buttons_list = []
  298. results = await arq.youtube(text)
  299. for i in results:
  300. buttons = InlineKeyboard(row_width=1)
  301. video_url = f"https://youtube.com{results[i].url_suffix}"
  302. buttons.add(
  303. InlineKeyboardButton(
  304. 'Watch',
  305. url=video_url
  306. )
  307. )
  308. buttons_list.append(buttons)
  309. caption = f"""
  310. **Title:** {results[i].title}
  311. **Views:** {results[i].views}
  312. **Channel:** {results[i].channel}
  313. **Duration:** {results[i].duration}
  314. **Uploaded:** {results[i].publish_time}
  315. **Description:** {results[i].long_desc}"""
  316. description = f"{results[i].views} | {results[i].channel} | " \
  317. + f"{results[i].duration} | {results[i].publish_time}"
  318. try:
  319. answers.append(
  320. InlineQueryResultArticle(
  321. title=results[i].title,
  322. thumb_url=results[i].thumbnails[0],
  323. description=description,
  324. input_message_content=InputTextMessageContent(
  325. caption,
  326. disable_web_page_preview=True
  327. ),
  328. reply_markup=buttons_list[i]
  329. ))
  330. except (KeyError, ValueError):
  331. pass
  332. return answers
  333. async def lyrics_func(answers, text):
  334. song = await arq.lyrics(text)
  335. lyrics = song.lyrics
  336. song = lyrics.splitlines()
  337. song_name = song[0]
  338. artist = song[1]
  339. if len(lyrics) > 4095:
  340. lyrics = await paste(lyrics)
  341. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  342. msg = f"__{lyrics}__"
  343. answers.append(
  344. InlineQueryResultArticle(
  345. title=song_name,
  346. description=artist,
  347. input_message_content=InputTextMessageContent(msg)
  348. ))
  349. return answers
  350. async def eval_func(answers, text, user_id):
  351. if user_id != USERBOT_ID:
  352. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  353. answers.append(
  354. InlineQueryResultArticle(
  355. title="ERROR",
  356. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  357. input_message_content=InputTextMessageContent(msg)
  358. ))
  359. return answers
  360. if str(text)[-1] != ":":
  361. msg = "**ERROR**\n__Put A ':' After The Code To Execute It__"
  362. answers.append(
  363. InlineQueryResultArticle(
  364. title="ERROR",
  365. description="Put A ':' After The Code To Execute It",
  366. input_message_content=InputTextMessageContent(msg)
  367. ))
  368. return answers
  369. text = text[0:-1]
  370. start_time = time()
  371. result = await eval_executor_func(text)
  372. output = result[1]
  373. result = result[0]
  374. msg = f"{result}"
  375. end_time = time()
  376. answers.append(
  377. InlineQueryResultArticle(
  378. title=f"Took {round(end_time - start_time)} Seconds.",
  379. description=output,
  380. input_message_content=InputTextMessageContent(msg)
  381. ))
  382. return answers
  383. async def github_user_func(answers, text):
  384. URL = f"https://api.github.com/users/{text}"
  385. result = await fetch(URL)
  386. buttons = InlineKeyboard(row_width=1)
  387. buttons.add(InlineKeyboardButton(
  388. text="Open On Github",
  389. url=f"https://github.com/{text}"
  390. ))
  391. caption = f"""
  392. **Info Of {result['name']}**
  393. **Username:** `{text}`
  394. **Bio:** `{result['bio']}`
  395. **Profile Link:** [Here]({result['html_url']})
  396. **Company:** `{result['company']}`
  397. **Created On:** `{result['created_at']}`
  398. **Repositories:** `{result['public_repos']}`
  399. **Blog:** `{result['blog']}`
  400. **Location:** `{result['location']}`
  401. **Followers:** `{result['followers']}`
  402. **Following:** `{result['following']}`"""
  403. answers.append(
  404. InlineQueryResultPhoto(
  405. photo_url=result['avatar_url'],
  406. caption=caption,
  407. reply_markup=buttons
  408. ))
  409. return answers
  410. async def github_repo_func(answers, text):
  411. URL = f"https://api.github.com/repos/{text}"
  412. URL2 = f"https://api.github.com/repos/{text}/contributors"
  413. results = await asyncio.gather(fetch(URL), fetch(URL2))
  414. r = results[0]
  415. r1 = results[1]
  416. commits = 0
  417. for developer in r1:
  418. commits += developer['contributions']
  419. buttons = InlineKeyboard(row_width=1)
  420. buttons.add(
  421. InlineKeyboardButton(
  422. 'Open On Github',
  423. url=f"https://github.com/{text}"
  424. )
  425. )
  426. caption = f"""
  427. **Info Of {r['full_name']}**
  428. **Stars:** `{r['stargazers_count']}`
  429. **Watchers:** `{r['watchers_count']}`
  430. **Forks:** `{r['forks_count']}`
  431. **Commits:** `{commits}`
  432. **Is Fork:** `{r['fork']}`
  433. **Language:** `{r['language']}`
  434. **Contributors:** `{len(r1)}`
  435. **License:** `{r['license']['name']}`
  436. **Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
  437. **Created On:** `{r['created_at']}`
  438. **Homepage:** {r['homepage']}
  439. **Description:** __{r['description']}__"""
  440. answers.append(
  441. InlineQueryResultArticle(
  442. title="Found Repo",
  443. description=text,
  444. reply_markup=buttons,
  445. input_message_content=InputTextMessageContent(
  446. caption,
  447. disable_web_page_preview=True
  448. )
  449. ))
  450. return answers
  451. async def tg_search_func(answers, text, user_id):
  452. if user_id != USERBOT_ID:
  453. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  454. answers.append(
  455. InlineQueryResultArticle(
  456. title="ERROR",
  457. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  458. input_message_content=InputTextMessageContent(msg)
  459. ))
  460. return answers
  461. if str(text)[-1] != ":":
  462. msg = "**ERROR**\n__Put A ':' After The Text To Search__"
  463. answers.append(
  464. InlineQueryResultArticle(
  465. title="ERROR",
  466. description="Put A ':' After The Text To Search",
  467. input_message_content=InputTextMessageContent(msg)
  468. ))
  469. return answers
  470. text = text[0:-1]
  471. async for message in app2.search_global(text, limit=49):
  472. buttons = InlineKeyboard(row_width=2)
  473. buttons.add(
  474. InlineKeyboardButton(
  475. text="Origin",
  476. url=message.link if message.link else "https://t.me/telegram"
  477. ),
  478. InlineKeyboardButton(
  479. text="Search again",
  480. switch_inline_query_current_chat="search"
  481. )
  482. )
  483. caption = f"""
  484. **Query:** {text}
  485. **Name:** {message.from_user.mention} [`{message.from_user.id}`]
  486. **Chat:** {message.chat.title} [`{message.chat.id}`]
  487. **Date:** {ctime(message.date)}
  488. **Text:** >>
  489. {message.text.markdown if message.text else message.caption if message.caption else "[NO_TEXT]"}
  490. """
  491. result = InlineQueryResultArticle(
  492. title=message.from_user.first_name,
  493. description=message.text if message.text else "[NO_TEXT]",
  494. reply_markup=buttons,
  495. input_message_content=InputTextMessageContent(
  496. caption,
  497. disable_web_page_preview=True
  498. )
  499. )
  500. answers.append(result)
  501. return answers