inlinefuncs.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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
  22. from datetime import datetime
  23. import calendar
  24. import aiohttp
  25. import json
  26. import sys
  27. import asyncio
  28. async def inline_help_func(__HELP__):
  29. buttons = InlineKeyboard(row_width=2)
  30. buttons.add(
  31. InlineKeyboardButton(
  32. 'Get More Help.',
  33. url=f"t.me/{BOT_USERNAME}?start=start"
  34. ),
  35. InlineKeyboardButton(
  36. "Go Inline!",
  37. switch_inline_query_current_chat=""
  38. )
  39. )
  40. answerss = [
  41. InlineQueryResultArticle(
  42. title="Inline Commands",
  43. description="Help Related To Inline Usage.",
  44. input_message_content=InputTextMessageContent(__HELP__),
  45. thumb_url="https://hamker.me/cy00x5x.png",
  46. reply_markup=buttons
  47. )
  48. ]
  49. answerss = await alive_function(answerss)
  50. return answerss
  51. async def alive_function(answers):
  52. buttons = InlineKeyboard(row_width=2)
  53. bot_state = 'Dead' if not await app.get_me() else 'Alive'
  54. ubot_state = 'Dead' if not await app2.get_me() else 'Alive'
  55. buttons.add(
  56. InlineKeyboardButton(
  57. 'Stats',
  58. callback_data='stats_callback'
  59. ),
  60. InlineKeyboardButton(
  61. "Go Inline!",
  62. switch_inline_query_current_chat=""
  63. )
  64. )
  65. msg = f"""
  66. **[William✨](https://github.com/thehamkercat/WilliamButcherBot):**
  67. **MainBot:** `{bot_state}`
  68. **UserBot:** `{ubot_state}`
  69. **Python:** `{pyver.split()[0]}`
  70. **Pyrogram:** `{pyrover}`
  71. **MongoDB:** `{mongover}`
  72. **Platform:** `{sys.platform}`
  73. **Profiles:** [BOT](t.me/{BOT_USERNAME}) | [UBOT](t.me/{USERBOT_USERNAME})
  74. """
  75. answers.append(
  76. InlineQueryResultArticle(
  77. title='Alive',
  78. description="Check Bot's Stats",
  79. thumb_url="https://static2.aniimg.com/upload/20170515/414/c/d/7/cd7EEF.jpg",
  80. input_message_content=InputTextMessageContent(
  81. msg,
  82. disable_web_page_preview=True
  83. ),
  84. reply_markup=buttons,
  85. )
  86. )
  87. return answers
  88. async def translate_func(answers, lang, tex):
  89. i = Translator().translate(tex, dest=lang)
  90. msg = f"""
  91. __**Translated to {lang}**__
  92. **INPUT:**
  93. {tex}
  94. **OUTPUT:**
  95. {i.text}"""
  96. answers.append(
  97. InlineQueryResultArticle(
  98. title=f'Translated to {lang}',
  99. description=i.text,
  100. input_message_content=InputTextMessageContent(msg)
  101. )
  102. )
  103. return answers
  104. async def urban_func(answers, text):
  105. results = await arq.urbandict(text)
  106. for i in results:
  107. msg = f"""
  108. **Query:** {text}
  109. **Definition:** __{results[i].definition}__
  110. **Example:** __{results[i].example}__"""
  111. answers.append(
  112. InlineQueryResultArticle(
  113. title=results[i].word,
  114. description=results[i].definition,
  115. input_message_content=InputTextMessageContent(msg)
  116. ))
  117. return answers
  118. async def google_search_func(answers, text):
  119. gresults = await GoogleSearch().async_search(text)
  120. for i in gresults:
  121. try:
  122. msg = f"""
  123. [{i['titles']}]({i['links']})
  124. {i['descriptions']}"""
  125. answers.append(
  126. InlineQueryResultArticle(
  127. title=i['titles'],
  128. description=i['descriptions'],
  129. input_message_content=InputTextMessageContent(
  130. msg,
  131. disable_web_page_preview=True
  132. )
  133. ))
  134. except KeyError:
  135. pass
  136. return answers
  137. async def wall_func(answers, text):
  138. results = await arq.wall(text)
  139. for i in results:
  140. try:
  141. answers.append(
  142. InlineQueryResultPhoto(
  143. photo_url=results[i].url_image,
  144. thumb_url=results[i].url_thumb,
  145. caption=f"[Source]({results[i].url_image})"
  146. ))
  147. except KeyError:
  148. pass
  149. return answers
  150. async def saavn_func(answers, text):
  151. buttons_list = []
  152. results = await arq.saavn(text)
  153. for i in results:
  154. buttons = InlineKeyboard(row_width=1)
  155. buttons.add(
  156. InlineKeyboardButton(
  157. 'Download | Play',
  158. url=results[i].media_url
  159. )
  160. )
  161. buttons_list.append(buttons)
  162. duration = await time_convert(results[i].duration)
  163. caption = f"""
  164. **Title:** {results[i].song}
  165. **Album:** {results[i].album}
  166. **Duration:** {duration}
  167. **Release:** {results[i].year}
  168. **Singers:** {results[i].singers}"""
  169. description = f"{results[i].album} | {duration} " \
  170. + f"| {results[i].singers} ({results[i].year})"
  171. try:
  172. answers.append(
  173. InlineQueryResultArticle(
  174. title=results[i].song,
  175. input_message_content=InputTextMessageContent(
  176. caption,
  177. disable_web_page_preview=True
  178. ),
  179. description=description,
  180. thumb_url=results[i].image,
  181. reply_markup=buttons_list[i]
  182. ))
  183. except (KeyError, ValueError):
  184. pass
  185. return answers
  186. async def deezer_func(answers, text):
  187. buttons_list = []
  188. results = await arq.deezer(text, 5)
  189. for i in results:
  190. buttons = InlineKeyboard(row_width=1)
  191. buttons.add(
  192. InlineKeyboardButton(
  193. 'Download | Play',
  194. url=results[i].url
  195. )
  196. )
  197. buttons_list.append(buttons)
  198. duration = await time_convert(results[i].duration)
  199. caption = f"""
  200. **Title:** {results[i].title}
  201. **Artist:** {results[i].artist}
  202. **Duration:** {duration}
  203. **Source:** [Deezer]({results[i].source})"""
  204. description = f"{results[i].artist} | {duration}"
  205. try:
  206. answers.append(
  207. InlineQueryResultArticle(
  208. title=results[i].title,
  209. thumb_url=results[i].thumbnail,
  210. description=description,
  211. input_message_content=InputTextMessageContent(
  212. caption,
  213. disable_web_page_preview=True
  214. ),
  215. reply_markup=buttons_list[i]
  216. ))
  217. except (KeyError, ValueError):
  218. pass
  219. return answers
  220. async def webss(url):
  221. start_time = time()
  222. if "." not in url:
  223. return
  224. screenshot = await fetch(f"https://patheticprogrammers.cf/ss?site={url}")
  225. end_time = time()
  226. try:
  227. m = await app.send_photo(LOG_GROUP_ID, photo=screenshot['url'])
  228. except TypeError:
  229. return
  230. await m.delete()
  231. a = []
  232. pic = InlineQueryResultPhoto(
  233. photo_url=screenshot['url'],
  234. caption=(f"`{url}`\n__Took {round(end_time - start_time)} Seconds.__")
  235. )
  236. a.append(pic)
  237. return a
  238. # Used my api key here, don't fuck with it
  239. async def shortify(url):
  240. if "." not in url:
  241. return
  242. header = {
  243. "Authorization": "Bearer ad39983fa42d0b19e4534f33671629a4940298dc",
  244. 'Content-Type': 'application/json'
  245. }
  246. payload = {
  247. "long_url": f"{url}"
  248. }
  249. payload = json.dumps(payload)
  250. async with aiohttp.ClientSession() as session:
  251. async with session.post("https://api-ssl.bitly.com/v4/shorten", headers=header, data=payload) as resp:
  252. data = await resp.json()
  253. msg = f"**Original Url:** {url}\n**Shortened Url:** {data['link']}"
  254. a = []
  255. b = InlineQueryResultArticle(
  256. title="Link Shortened!",
  257. description=data['link'],
  258. input_message_content=InputTextMessageContent(
  259. msg, disable_web_page_preview=True)
  260. )
  261. a.append(b)
  262. return a
  263. async def torrent_func(answers, text):
  264. results = await arq.torrent(text)
  265. limit = 0
  266. for i in results:
  267. if limit > 48:
  268. break
  269. title = results[i].name
  270. size = results[i].size
  271. seeds = results[i].seeds
  272. leechs = results[i].leechs
  273. upload_date = results[i].uploaded + " Ago"
  274. magnet = results[i].magnet
  275. caption = f"""
  276. **Title:** __{title}__
  277. **Size:** __{size}__
  278. **Seeds:** __{seeds}__
  279. **Leechs:** __{leechs}__
  280. **Uploaded:** __{upload_date}__
  281. **Magnet:** __{magnet}__"""
  282. description = f"{size} | {upload_date} | Seeds: {seeds}"
  283. try:
  284. answers.append(
  285. InlineQueryResultArticle(
  286. title=title,
  287. description=description,
  288. input_message_content=InputTextMessageContent(
  289. caption,
  290. disable_web_page_preview=True
  291. )
  292. )
  293. )
  294. limit += 1
  295. except (KeyError, ValueError):
  296. pass
  297. return answers
  298. async def youtube_func(answers, text):
  299. buttons_list = []
  300. results = await arq.youtube(text)
  301. for i in results:
  302. buttons = InlineKeyboard(row_width=1)
  303. video_url = f"https://youtube.com{results[i].url_suffix}"
  304. buttons.add(
  305. InlineKeyboardButton(
  306. 'Watch',
  307. url=video_url
  308. )
  309. )
  310. buttons_list.append(buttons)
  311. caption = f"""
  312. **Title:** {results[i].title}
  313. **Views:** {results[i].views}
  314. **Channel:** {results[i].channel}
  315. **Duration:** {results[i].duration}
  316. **Uploaded:** {results[i].publish_time}
  317. **Description:** {results[i].long_desc}"""
  318. description = f"{results[i].views} | {results[i].channel} | " \
  319. + f"{results[i].duration} | {results[i].publish_time}"
  320. try:
  321. answers.append(
  322. InlineQueryResultArticle(
  323. title=results[i].title,
  324. thumb_url=results[i].thumbnails[0],
  325. description=description,
  326. input_message_content=InputTextMessageContent(
  327. caption,
  328. disable_web_page_preview=True
  329. ),
  330. reply_markup=buttons_list[i]
  331. ))
  332. except (KeyError, ValueError):
  333. pass
  334. return answers
  335. async def lyrics_func(answers, text):
  336. song = await arq.lyrics(text)
  337. lyrics = song.lyrics
  338. song = lyrics.splitlines()
  339. song_name = song[0]
  340. artist = song[1]
  341. if len(lyrics) > 4095:
  342. lyrics = await paste(lyrics)
  343. lyrics = f"**LYRICS_TOO_LONG:** [URL]({lyrics})"
  344. msg = f"__{lyrics}__"
  345. answers.append(
  346. InlineQueryResultArticle(
  347. title=song_name,
  348. description=artist,
  349. input_message_content=InputTextMessageContent(msg)
  350. ))
  351. return answers
  352. async def paste_func(answers, text):
  353. start_time = time()
  354. url = await paste(text)
  355. msg = f"__**{url}**__"
  356. end_time = time()
  357. answers.append(
  358. InlineQueryResultArticle(
  359. title=f"Pasted In {round(end_time - start_time)} Seconds.",
  360. description=url,
  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 calendar_func(answers):
  466. year, month = str(datetime.now())[0:7].split("-")
  467. calendarr = calendar.month(int(year), int(month))
  468. msg = f"`{calendarr}`"
  469. answers.append(
  470. InlineQueryResultArticle(
  471. title=f"Calendar For {month}/{year}",
  472. input_message_content=InputTextMessageContent(msg)
  473. ))
  474. return answers