inlinefuncs.py 9.2 KB

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