inlinefuncs.py 13 KB

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