inlinefuncs.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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 time import time
  14. from wbb.modules.userbot import eval_executor_func
  15. from wbb.utils.fetch import fetch
  16. from wbb.utils.formatter import convert_seconds_to_minutes as time_convert
  17. from wbb.utils.pastebin import paste
  18. from pykeyboard import InlineKeyboard
  19. from sys import version as pyver
  20. import sys
  21. from motor import version as mongover
  22. from pyrogram import __version__ as pyrover
  23. import aiohttp
  24. import json
  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 paste_func(answers, text):
  351. start_time = time()
  352. url = await paste(text)
  353. msg = f"__**{url}**__"
  354. end_time = time()
  355. answers.append(
  356. InlineQueryResultArticle(
  357. title=f"Pasted In {round(end_time - start_time)} Seconds.",
  358. description=url,
  359. input_message_content=InputTextMessageContent(msg)
  360. ))
  361. return answers
  362. async def eval_func(answers, text, user_id):
  363. if user_id != USERBOT_ID:
  364. msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
  365. answers.append(
  366. InlineQueryResultArticle(
  367. title="ERROR",
  368. description="THIS FEATURE IS ONLY FOR SUDO USERS",
  369. input_message_content=InputTextMessageContent(msg)
  370. ))
  371. return answers
  372. if str(text)[-1] != ":":
  373. msg = "**ERROR**\n__Put A ':' After The Code To Execute It__"
  374. answers.append(
  375. InlineQueryResultArticle(
  376. title="ERROR",
  377. description="Put A ':' After The Code To Execute It",
  378. input_message_content=InputTextMessageContent(msg)
  379. ))
  380. return answers
  381. text = text[0:-1]
  382. start_time = time()
  383. result = await eval_executor_func(text)
  384. output = result[1]
  385. result = result[0]
  386. msg = f"{result}"
  387. end_time = time()
  388. answers.append(
  389. InlineQueryResultArticle(
  390. title=f"Took {round(end_time - start_time)} Seconds.",
  391. description=output,
  392. input_message_content=InputTextMessageContent(msg)
  393. ))
  394. return answers
  395. async def github_user_func(answers, text):
  396. URL = f"https://api.github.com/users/{text}"
  397. result = await fetch(URL)
  398. buttons = InlineKeyboard(row_width=1)
  399. buttons.add(InlineKeyboardButton(
  400. text="Open On Github",
  401. url=f"https://github.com/{text}"
  402. ))
  403. caption = f"""
  404. **Info Of {result['name']}**
  405. **Username:** `{text}`
  406. **Bio:** `{result['bio']}`
  407. **Profile Link:** [Here]({result['html_url']})
  408. **Company:** `{result['company']}`
  409. **Created On:** `{result['created_at']}`
  410. **Repositories:** `{result['public_repos']}`
  411. **Blog:** `{result['blog']}`
  412. **Location:** `{result['location']}`
  413. **Followers:** `{result['followers']}`
  414. **Following:** `{result['following']}`"""
  415. answers.append(
  416. InlineQueryResultPhoto(
  417. photo_url=result['avatar_url'],
  418. caption=caption,
  419. reply_markup=buttons
  420. ))
  421. return answers
  422. async def github_repo_func(answers, text):
  423. URL = f"https://api.github.com/repos/{text}"
  424. URL2 = f"https://api.github.com/repos/{text}/contributors"
  425. results = await asyncio.gather(fetch(URL), fetch(URL2))
  426. r = results[0]
  427. r1 = results[1]
  428. commits = 0
  429. for developer in r1:
  430. commits += developer['contributions']
  431. buttons = InlineKeyboard(row_width=1)
  432. buttons.add(
  433. InlineKeyboardButton(
  434. 'Open On Github',
  435. url=f"https://github.com/{text}"
  436. )
  437. )
  438. caption = f"""
  439. **Info Of {r['full_name']}**
  440. **Stars:** `{r['stargazers_count']}`
  441. **Watchers:** `{r['watchers_count']}`
  442. **Forks:** `{r['forks_count']}`
  443. **Commits:** `{commits}`
  444. **Is Fork:** `{r['fork']}`
  445. **Language:** `{r['language']}`
  446. **Contributors:** `{len(r1)}`
  447. **License:** `{r['license']['name']}`
  448. **Repo Owner:** [{r['owner']['login']}]({r['owner']['html_url']})
  449. **Created On:** `{r['created_at']}`
  450. **Homepage:** {r['homepage']}
  451. **Description:** __{r['description']}__"""
  452. answers.append(
  453. InlineQueryResultArticle(
  454. title="Found Repo",
  455. description=text,
  456. reply_markup=buttons,
  457. input_message_content=InputTextMessageContent(
  458. caption,
  459. disable_web_page_preview=True
  460. )
  461. ))
  462. return answers