inline.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. # flake8: noqa F405
  2. """
  3. MIT License
  4. Copyright (c) 2021 TheHamkerCat
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in all
  12. copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. SOFTWARE.
  20. """
  21. import traceback
  22. from wbb import app
  23. from wbb.utils.inlinefuncs import *
  24. __MODULE__ = "Inline"
  25. __HELP__ = """See inline for help related to inline"""
  26. @app.on_inline_query()
  27. async def inline_query_handler(client, query):
  28. try:
  29. text = query.query.strip().lower()
  30. answers = []
  31. if text.strip() == "":
  32. answerss = await inline_help_func(__HELP__)
  33. await client.answer_inline_query(query.id, results=answerss, cache_time=10)
  34. return
  35. elif text.split()[0] == "alive":
  36. answerss = await alive_function(answers)
  37. await client.answer_inline_query(query.id, results=answerss, cache_time=10)
  38. elif text.split()[0] == "tr":
  39. if len(text.split()) < 3:
  40. await client.answer_inline_query(
  41. query.id,
  42. results=answers,
  43. switch_pm_text="Translator | tr [LANG] [TEXT]",
  44. switch_pm_parameter="inline",
  45. )
  46. return
  47. lang = text.split()[1]
  48. tex = text.split(None, 2)[2].strip()
  49. answerss = await translate_func(answers, lang, tex)
  50. await client.answer_inline_query(
  51. query.id,
  52. results=answerss,
  53. )
  54. elif text.split()[0] == "ud":
  55. if len(text.split()) < 2:
  56. await client.answer_inline_query(
  57. query.id,
  58. results=answers,
  59. switch_pm_text="Urban Dictionary | ud [QUERY]",
  60. switch_pm_parameter="inline",
  61. )
  62. return
  63. tex = text.split(None, 1)[1].strip()
  64. answerss = await urban_func(answers, tex)
  65. await client.answer_inline_query(
  66. query.id,
  67. results=answerss,
  68. )
  69. elif text.split()[0] == "google":
  70. if len(text.split()) < 2:
  71. await client.answer_inline_query(
  72. query.id,
  73. results=answers,
  74. switch_pm_text="Google Search | google [QUERY]",
  75. switch_pm_parameter="inline",
  76. )
  77. return
  78. tex = text.split(None, 1)[1].strip()
  79. answerss = await google_search_func(answers, tex)
  80. await client.answer_inline_query(
  81. query.id,
  82. results=answerss,
  83. )
  84. elif text.split()[0] == "bitly":
  85. if len(text.split()) < 2:
  86. await client.answer_inline_query(
  87. query.id,
  88. results=answers,
  89. switch_pm_text="Link Shortener | bitly [LINK]",
  90. switch_pm_parameter="inline",
  91. )
  92. return
  93. tex = text.split(None, 1)[1].strip()
  94. answerss = await shortify(tex)
  95. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  96. elif text.split()[0] == "wall":
  97. if len(text.split()) < 2:
  98. await client.answer_inline_query(
  99. query.id,
  100. results=answers,
  101. is_gallery=True,
  102. switch_pm_text="Wallpapers Search | wall [QUERY]",
  103. switch_pm_parameter="inline",
  104. )
  105. return
  106. tex = text.split(None, 1)[1].strip()
  107. answerss = await wall_func(answers, tex)
  108. await client.answer_inline_query(query.id, results=answerss)
  109. elif text.split()[0] == "saavn":
  110. if len(text.split()) < 2:
  111. await client.answer_inline_query(
  112. query.id,
  113. results=answers,
  114. switch_pm_text="JioSaavn Search | saavn [QUERY]",
  115. switch_pm_parameter="inline",
  116. )
  117. return
  118. tex = text.split(None, 1)[1].strip()
  119. answerss = await saavn_func(answers, tex)
  120. await client.answer_inline_query(query.id, results=answerss)
  121. elif text.split()[0] == "deezer":
  122. if len(text.split()) < 2:
  123. await client.answer_inline_query(
  124. query.id,
  125. results=answers,
  126. switch_pm_text="Deezer Search | deezer [QUERY]",
  127. switch_pm_parameter="inline",
  128. )
  129. return
  130. tex = text.split(None, 1)[1].strip()
  131. answerss = await deezer_func(answers, tex)
  132. await client.answer_inline_query(query.id, results=answerss)
  133. elif text.split()[0] == "torrent":
  134. if len(text.split()) < 2:
  135. await client.answer_inline_query(
  136. query.id,
  137. results=answers,
  138. switch_pm_text="Torrent Search | torrent [QUERY]",
  139. switch_pm_parameter="inline",
  140. )
  141. return
  142. tex = text.split(None, 1)[1].strip()
  143. answerss = await torrent_func(answers, tex)
  144. await client.answer_inline_query(
  145. query.id,
  146. results=answerss,
  147. )
  148. elif text.split()[0] == "yt":
  149. if len(text.split()) < 2:
  150. await client.answer_inline_query(
  151. query.id,
  152. results=answers,
  153. switch_pm_text="YouTube Search | yt [QUERY]",
  154. switch_pm_parameter="inline",
  155. )
  156. return
  157. tex = text.split(None, 1)[1].strip()
  158. answerss = await youtube_func(answers, tex)
  159. await client.answer_inline_query(query.id, results=answerss)
  160. elif text.split()[0] == "lyrics":
  161. if len(text.split()) < 2:
  162. await client.answer_inline_query(
  163. query.id,
  164. results=answers,
  165. switch_pm_text="Lyrics Search | lyrics [QUERY]",
  166. switch_pm_parameter="inline",
  167. )
  168. return
  169. tex = text.split(None, 1)[1].strip()
  170. answerss = await lyrics_func(answers, tex)
  171. await client.answer_inline_query(query.id, results=answerss)
  172. elif text.split()[0] == "gh_user":
  173. if len(text.split()) < 2:
  174. await client.answer_inline_query(
  175. query.id,
  176. results=answers,
  177. switch_pm_text="Github User | gh_user [USERNAME/LINK]",
  178. switch_pm_parameter="inline",
  179. )
  180. return
  181. tex = text.split(None, 1)[1].strip()
  182. answerss = await github_user_func(answers, tex)
  183. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  184. elif text.split()[0] == "gh_repo":
  185. if len(text.split()) < 2:
  186. await client.answer_inline_query(
  187. query.id,
  188. results=answers,
  189. switch_pm_text="Github Repo Search | [LINK]",
  190. switch_pm_parameter="inline",
  191. )
  192. return
  193. tex = text.split(None, 1)[1].strip()
  194. answerss = await github_repo_func(answers, tex)
  195. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  196. elif text.split()[0] == "search":
  197. if len(text.split()) < 2:
  198. await client.answer_inline_query(
  199. query.id,
  200. results=answers,
  201. switch_pm_text="Global Message Search. | search [QUERY]",
  202. switch_pm_parameter="inline",
  203. )
  204. return
  205. user_id = query.from_user.id
  206. tex = text.split(None, 1)[1].strip()
  207. answerss = await tg_search_func(answers, tex, user_id)
  208. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  209. elif text.split()[0] == "music":
  210. if len(text.split()) < 2:
  211. await client.answer_inline_query(
  212. query.id,
  213. results=answers,
  214. switch_pm_text="Music Search | music [QUERY]",
  215. switch_pm_parameter="inline",
  216. )
  217. return
  218. tex = text.split(None, 1)[1].strip()
  219. answerss = await music_inline_func(answers, tex)
  220. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  221. elif text.split()[0] == "wiki":
  222. if len(text.split()) < 2:
  223. await client.answer_inline_query(
  224. query.id,
  225. results=answers,
  226. switch_pm_text="Wikipedia | wiki [QUERY]",
  227. switch_pm_parameter="inline",
  228. )
  229. return
  230. tex = text.split(None, 1)[1].strip()
  231. answerss = await wiki_func(answers, tex)
  232. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  233. elif text.split()[0] == "speedtest":
  234. answerss = await speedtest_init(query)
  235. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  236. return
  237. elif text.split()[0] == "paste":
  238. if len(text.split()) < 2:
  239. await client.answer_inline_query(
  240. query.id,
  241. results=answers,
  242. switch_pm_text="Pastebin | paste [TG_MESSAGE_LINK]",
  243. switch_pm_parameter="inline",
  244. )
  245. return
  246. link = text.strip().split()[1]
  247. answerss = await pastebin_func(answers, link)
  248. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  249. return
  250. elif text.split()[0] == "carbon":
  251. if len(text.split()) < 2:
  252. await client.answer_inline_query(
  253. query.id,
  254. results=answers,
  255. switch_pm_text="Carbon | carbon [TG_MESSAGE_LINK]",
  256. switch_pm_parameter="inline",
  257. )
  258. return
  259. link = text.split()[1]
  260. answerss = await carbon_inline_func(answers, link)
  261. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  262. return
  263. elif text.split()[0] == "pmpermit":
  264. user_id = query.from_user.id
  265. victim = text.split()[1]
  266. answerss = await pmpermit_func(answers, user_id, victim)
  267. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  268. return
  269. elif text.split()[0] == "ping":
  270. answerss = await ping_func(answers)
  271. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  272. return
  273. elif text.split()[0] == "nsfw_scan":
  274. if len(text.split()) < 2:
  275. await client.answer_inline_query(
  276. query.id,
  277. results=answers,
  278. switch_pm_text="NSFW Scan | nsfw_scan [url]",
  279. switch_pm_parameter="inline",
  280. )
  281. return
  282. tex = text.split(None, 1)[1].strip()
  283. answerss = await nsfw_scan_func(answers, tex)
  284. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  285. elif text.split()[0] == "ytmusic":
  286. if len(text.split()) < 2:
  287. await client.answer_inline_query(
  288. query.id,
  289. results=answers,
  290. switch_pm_text="YT Music | ytmusic [url]",
  291. switch_pm_parameter="inline",
  292. )
  293. return
  294. tex = query.query.split(None, 1)[1].strip()
  295. user_id = query.from_user.id
  296. answerss = await yt_music_func(answers, tex, user_id)
  297. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  298. elif text.split()[0] == "info":
  299. if len(text.split()) < 2:
  300. await client.answer_inline_query(
  301. query.id,
  302. results=answers,
  303. switch_pm_text="User Info | info [USERNAME|ID]",
  304. switch_pm_parameter="inline",
  305. )
  306. return
  307. tex = text.split()[1].strip()
  308. answerss = await user_info_inline_func(answers, tex)
  309. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  310. elif text.split()[0] == "chat_info":
  311. if len(text.split()) < 2:
  312. await client.answer_inline_query(
  313. query.id,
  314. results=answers,
  315. switch_pm_text="Chat Info | chat_info [USERNAME|ID]",
  316. switch_pm_parameter="inline",
  317. )
  318. return
  319. tex = text.split()[1].strip()
  320. answerss = await chat_info_inline_func(answers, tex)
  321. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  322. elif text.split()[0] == "tmdb":
  323. if len(text.split()) < 2:
  324. answerss = await tmdb_func(answers, "")
  325. await client.answer_inline_query(
  326. query.id,
  327. results=answerss,
  328. switch_pm_text="TMDB Search | tmdb [QUERY]",
  329. switch_pm_parameter="inline",
  330. )
  331. return
  332. tex = text.split()[1].strip()
  333. answerss = await tmdb_func(answers, tex)
  334. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  335. except Exception as e:
  336. e = traceback.format_exc()
  337. print(e, " InLine")
  338. return