inline.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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(
  34. query.id, results=answerss, cache_time=10
  35. )
  36. return
  37. elif text.split()[0] == "alive":
  38. answerss = await alive_function(answers)
  39. await client.answer_inline_query(
  40. query.id, results=answerss, cache_time=10
  41. )
  42. elif text.split()[0] == "tr":
  43. if len(text.split()) < 3:
  44. await client.answer_inline_query(
  45. query.id,
  46. results=answers,
  47. switch_pm_text="Translator | tr [LANG] [TEXT]",
  48. switch_pm_parameter="inline",
  49. )
  50. return
  51. lang = text.split()[1]
  52. tex = text.split(None, 2)[2].strip()
  53. answerss = await translate_func(answers, lang, tex)
  54. await client.answer_inline_query(
  55. query.id,
  56. results=answerss,
  57. )
  58. elif text.split()[0] == "ud":
  59. if len(text.split()) < 2:
  60. await client.answer_inline_query(
  61. query.id,
  62. results=answers,
  63. switch_pm_text="Urban Dictionary | ud [QUERY]",
  64. switch_pm_parameter="inline",
  65. )
  66. return
  67. tex = text.split(None, 1)[1].strip()
  68. answerss = await urban_func(answers, tex)
  69. await client.answer_inline_query(
  70. query.id,
  71. results=answerss,
  72. )
  73. elif text.split()[0] == "google":
  74. if len(text.split()) < 2:
  75. await client.answer_inline_query(
  76. query.id,
  77. results=answers,
  78. switch_pm_text="Google Search | google [QUERY]",
  79. switch_pm_parameter="inline",
  80. )
  81. return
  82. tex = text.split(None, 1)[1].strip()
  83. answerss = await google_search_func(answers, tex)
  84. await client.answer_inline_query(
  85. query.id,
  86. results=answerss,
  87. )
  88. elif text.split()[0] == "bitly":
  89. if len(text.split()) < 2:
  90. await client.answer_inline_query(
  91. query.id,
  92. results=answers,
  93. switch_pm_text="Link Shortener | bitly [LINK]",
  94. switch_pm_parameter="inline",
  95. )
  96. return
  97. tex = text.split(None, 1)[1].strip()
  98. answerss = await shortify(tex)
  99. await client.answer_inline_query(
  100. query.id, results=answerss, cache_time=2
  101. )
  102. elif text.split()[0] == "wall":
  103. if len(text.split()) < 2:
  104. await client.answer_inline_query(
  105. query.id,
  106. results=answers,
  107. is_gallery=True,
  108. switch_pm_text="Wallpapers Search | wall [QUERY]",
  109. switch_pm_parameter="inline",
  110. )
  111. return
  112. tex = text.split(None, 1)[1].strip()
  113. answerss = await wall_func(answers, tex)
  114. await client.answer_inline_query(query.id, results=answerss)
  115. elif text.split()[0] == "saavn":
  116. if len(text.split()) < 2:
  117. await client.answer_inline_query(
  118. query.id,
  119. results=answers,
  120. switch_pm_text="JioSaavn Search | saavn [QUERY]",
  121. switch_pm_parameter="inline",
  122. )
  123. return
  124. tex = text.split(None, 1)[1].strip()
  125. answerss = await saavn_func(answers, tex)
  126. await client.answer_inline_query(query.id, results=answerss)
  127. elif text.split()[0] == "deezer":
  128. if len(text.split()) < 2:
  129. await client.answer_inline_query(
  130. query.id,
  131. results=answers,
  132. switch_pm_text="Deezer Search | deezer [QUERY]",
  133. switch_pm_parameter="inline",
  134. )
  135. return
  136. tex = text.split(None, 1)[1].strip()
  137. answerss = await deezer_func(answers, tex)
  138. await client.answer_inline_query(query.id, results=answerss)
  139. elif text.split()[0] == "torrent":
  140. if len(text.split()) < 2:
  141. await client.answer_inline_query(
  142. query.id,
  143. results=answers,
  144. switch_pm_text="Torrent Search | torrent [QUERY]",
  145. switch_pm_parameter="inline",
  146. )
  147. return
  148. tex = text.split(None, 1)[1].strip()
  149. answerss = await torrent_func(answers, tex)
  150. await client.answer_inline_query(
  151. query.id,
  152. results=answerss,
  153. )
  154. elif text.split()[0] == "yt":
  155. if len(text.split()) < 2:
  156. await client.answer_inline_query(
  157. query.id,
  158. results=answers,
  159. switch_pm_text="YouTube Search | yt [QUERY]",
  160. switch_pm_parameter="inline",
  161. )
  162. return
  163. tex = text.split(None, 1)[1].strip()
  164. answerss = await youtube_func(answers, tex)
  165. await client.answer_inline_query(query.id, results=answerss)
  166. elif text.split()[0] == "lyrics":
  167. if len(text.split()) < 2:
  168. await client.answer_inline_query(
  169. query.id,
  170. results=answers,
  171. switch_pm_text="Lyrics Search | lyrics [QUERY]",
  172. switch_pm_parameter="inline",
  173. )
  174. return
  175. tex = text.split(None, 1)[1].strip()
  176. answerss = await lyrics_func(answers, tex)
  177. await client.answer_inline_query(query.id, results=answerss)
  178. elif text.split()[0] == "gh_user":
  179. if len(text.split()) < 2:
  180. await client.answer_inline_query(
  181. query.id,
  182. results=answers,
  183. switch_pm_text="Github User | gh_user [USERNAME/LINK]",
  184. switch_pm_parameter="inline",
  185. )
  186. return
  187. tex = text.split(None, 1)[1].strip()
  188. answerss = await github_user_func(answers, tex)
  189. await client.answer_inline_query(
  190. query.id, results=answerss, cache_time=2
  191. )
  192. elif text.split()[0] == "gh_repo":
  193. if len(text.split()) < 2:
  194. await client.answer_inline_query(
  195. query.id,
  196. results=answers,
  197. switch_pm_text="Github Repo Search | [LINK]",
  198. switch_pm_parameter="inline",
  199. )
  200. return
  201. tex = text.split(None, 1)[1].strip()
  202. answerss = await github_repo_func(answers, tex)
  203. await client.answer_inline_query(
  204. query.id, results=answerss, cache_time=2
  205. )
  206. elif text.split()[0] == "search":
  207. if len(text.split()) < 2:
  208. await client.answer_inline_query(
  209. query.id,
  210. results=answers,
  211. switch_pm_text="Global Message Search. | search [QUERY]",
  212. switch_pm_parameter="inline",
  213. )
  214. return
  215. user_id = query.from_user.id
  216. tex = text.split(None, 1)[1].strip()
  217. answerss = await tg_search_func(answers, tex, user_id)
  218. await client.answer_inline_query(
  219. query.id, results=answerss, cache_time=2
  220. )
  221. elif text.split()[0] == "music":
  222. if len(text.split()) < 2:
  223. await client.answer_inline_query(
  224. query.id,
  225. results=answers,
  226. switch_pm_text="Music Search | music [QUERY]",
  227. switch_pm_parameter="inline",
  228. )
  229. return
  230. tex = text.split(None, 1)[1].strip()
  231. answerss = await music_inline_func(answers, tex)
  232. await client.answer_inline_query(
  233. query.id, results=answerss, cache_time=2
  234. )
  235. elif text.split()[0] == "wiki":
  236. if len(text.split()) < 2:
  237. await client.answer_inline_query(
  238. query.id,
  239. results=answers,
  240. switch_pm_text="Wikipedia | wiki [QUERY]",
  241. switch_pm_parameter="inline",
  242. )
  243. return
  244. tex = text.split(None, 1)[1].strip()
  245. answerss = await wiki_func(answers, tex)
  246. await client.answer_inline_query(
  247. query.id, results=answerss, cache_time=2
  248. )
  249. elif text.split()[0] == "speedtest":
  250. answerss = await speedtest_init(query)
  251. await client.answer_inline_query(
  252. query.id, results=answerss, cache_time=2
  253. )
  254. return
  255. elif text.split()[0] == "paste":
  256. if len(text.split()) < 2:
  257. await client.answer_inline_query(
  258. query.id,
  259. results=answers,
  260. switch_pm_text="Pastebin | paste [TG_MESSAGE_LINK]",
  261. switch_pm_parameter="inline",
  262. )
  263. return
  264. link = text.strip().split()[1]
  265. answerss = await pastebin_func(answers, link)
  266. await client.answer_inline_query(
  267. query.id, results=answerss, cache_time=2
  268. )
  269. return
  270. elif text.split()[0] == "carbon":
  271. if len(text.split()) < 2:
  272. await client.answer_inline_query(
  273. query.id,
  274. results=answers,
  275. switch_pm_text="Carbon | carbon [TG_MESSAGE_LINK]",
  276. switch_pm_parameter="inline",
  277. )
  278. return
  279. link = text.split()[1]
  280. answerss = await carbon_inline_func(answers, link)
  281. await client.answer_inline_query(
  282. query.id, results=answerss, cache_time=2
  283. )
  284. return
  285. elif text.split()[0] == "pmpermit":
  286. user_id = query.from_user.id
  287. victim = text.split()[1]
  288. answerss = await pmpermit_func(answers, user_id, victim)
  289. await client.answer_inline_query(
  290. query.id, results=answerss, cache_time=2
  291. )
  292. return
  293. elif text.split()[0] == "ping":
  294. answerss = await ping_func(answers)
  295. await client.answer_inline_query(
  296. query.id, results=answerss, cache_time=2
  297. )
  298. return
  299. elif text.split()[0] == "nsfw_scan":
  300. if len(text.split()) < 2:
  301. await client.answer_inline_query(
  302. query.id,
  303. results=answers,
  304. switch_pm_text="NSFW Scan | nsfw_scan [url]",
  305. switch_pm_parameter="inline",
  306. )
  307. return
  308. tex = text.split(None, 1)[1].strip()
  309. answerss = await nsfw_scan_func(answers, tex)
  310. await client.answer_inline_query(
  311. query.id, results=answerss, cache_time=2
  312. )
  313. elif text.split()[0] == "ytmusic":
  314. if len(text.split()) < 2:
  315. await client.answer_inline_query(
  316. query.id,
  317. results=answers,
  318. switch_pm_text="YT Music | ytmusic [url]",
  319. switch_pm_parameter="inline",
  320. )
  321. return
  322. tex = query.query.split(None, 1)[1].strip()
  323. answerss = await yt_music_func(answers, tex)
  324. await client.answer_inline_query(
  325. query.id, results=answerss, cache_time=2
  326. )
  327. elif text.split()[0] == "info":
  328. if len(text.split()) < 2:
  329. await client.answer_inline_query(
  330. query.id,
  331. results=answers,
  332. switch_pm_text="User Info | info [USERNAME|ID]",
  333. switch_pm_parameter="inline",
  334. )
  335. return
  336. tex = text.split()[1].strip()
  337. answerss = await user_info_inline_func(answers, tex)
  338. await client.answer_inline_query(
  339. query.id, results=answerss, cache_time=2
  340. )
  341. elif text.split()[0] == "chat_info":
  342. if len(text.split()) < 2:
  343. await client.answer_inline_query(
  344. query.id,
  345. results=answers,
  346. switch_pm_text="Chat Info | chat_info [USERNAME|ID]",
  347. switch_pm_parameter="inline",
  348. )
  349. return
  350. tex = text.split()[1].strip()
  351. answerss = await chat_info_inline_func(answers, tex)
  352. await client.answer_inline_query(
  353. query.id, results=answerss, cache_time=2
  354. )
  355. elif text.split()[0] == "tmdb":
  356. if len(text.split()) < 2:
  357. answerss = await tmdb_func(answers, "")
  358. await client.answer_inline_query(
  359. query.id,
  360. results=answerss,
  361. switch_pm_text="TMDB Search | tmdb [QUERY]",
  362. switch_pm_parameter="inline",
  363. )
  364. return
  365. tex = text.split()[1].strip()
  366. answerss = await tmdb_func(answers, tex)
  367. await client.answer_inline_query(
  368. query.id, results=answerss, cache_time=2
  369. )
  370. elif text.split()[0] == "pypi":
  371. if len(text.split()) < 2:
  372. await client.answer_inline_query(
  373. query.id,
  374. results=answers,
  375. switch_pm_text="Pypi Search | pypi [Package Name]",
  376. switch_pm_parameter="inline",
  377. )
  378. return
  379. tex = text.split()[1].strip()
  380. answerss = await pypiSearchFunc(answers, tex)
  381. await client.answer_inline_query(
  382. query.id, results=answerss, cache_time=2
  383. )
  384. except Exception as e:
  385. e = traceback.format_exc()
  386. print(e, " InLine")
  387. return