inline.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. switch_pm_text="Wallpapers Search | wall [QUERY]",
  102. switch_pm_parameter="inline",
  103. )
  104. return
  105. tex = text.split(None, 1)[1].strip()
  106. answerss = await wall_func(answers, tex)
  107. await client.answer_inline_query(query.id, results=answerss)
  108. elif text.split()[0] == "saavn":
  109. if len(text.split()) < 2:
  110. await client.answer_inline_query(
  111. query.id,
  112. results=answers,
  113. switch_pm_text="JioSaavn Search | saavn [QUERY]",
  114. switch_pm_parameter="inline",
  115. )
  116. return
  117. tex = text.split(None, 1)[1].strip()
  118. answerss = await saavn_func(answers, tex)
  119. await client.answer_inline_query(query.id, results=answerss)
  120. elif text.split()[0] == "deezer":
  121. if len(text.split()) < 2:
  122. await client.answer_inline_query(
  123. query.id,
  124. results=answers,
  125. switch_pm_text="Deezer Search | deezer [QUERY]",
  126. switch_pm_parameter="inline",
  127. )
  128. return
  129. tex = text.split(None, 1)[1].strip()
  130. answerss = await deezer_func(answers, tex)
  131. await client.answer_inline_query(query.id, results=answerss)
  132. elif text.split()[0] == "torrent":
  133. if len(text.split()) < 2:
  134. await client.answer_inline_query(
  135. query.id,
  136. results=answers,
  137. switch_pm_text="Torrent Search | torrent [QUERY]",
  138. switch_pm_parameter="inline",
  139. )
  140. return
  141. tex = text.split(None, 1)[1].strip()
  142. answerss = await torrent_func(answers, tex)
  143. await client.answer_inline_query(
  144. query.id,
  145. results=answerss,
  146. )
  147. elif text.split()[0] == "yt":
  148. if len(text.split()) < 2:
  149. await client.answer_inline_query(
  150. query.id,
  151. results=answers,
  152. switch_pm_text="YouTube Search | yt [QUERY]",
  153. switch_pm_parameter="inline",
  154. )
  155. return
  156. tex = text.split(None, 1)[1].strip()
  157. answerss = await youtube_func(answers, tex)
  158. await client.answer_inline_query(query.id, results=answerss)
  159. elif text.split()[0] == "lyrics":
  160. if len(text.split()) < 2:
  161. await client.answer_inline_query(
  162. query.id,
  163. results=answers,
  164. switch_pm_text="Lyrics Search | lyrics [QUERY]",
  165. switch_pm_parameter="inline",
  166. )
  167. return
  168. tex = text.split(None, 1)[1].strip()
  169. answerss = await lyrics_func(answers, tex)
  170. await client.answer_inline_query(query.id, results=answerss)
  171. elif text.split()[0] == "gh_user":
  172. if len(text.split()) < 2:
  173. await client.answer_inline_query(
  174. query.id,
  175. results=answers,
  176. switch_pm_text="Github User | gh_user [USERNAME/LINK]",
  177. switch_pm_parameter="inline",
  178. )
  179. return
  180. tex = text.split(None, 1)[1].strip()
  181. answerss = await github_user_func(answers, tex)
  182. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  183. elif text.split()[0] == "gh_repo":
  184. if len(text.split()) < 2:
  185. await client.answer_inline_query(
  186. query.id,
  187. results=answers,
  188. switch_pm_text="Github Repo Search | [LINK]",
  189. switch_pm_parameter="inline",
  190. )
  191. return
  192. tex = text.split(None, 1)[1].strip()
  193. answerss = await github_repo_func(answers, tex)
  194. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  195. elif text.split()[0] == "search":
  196. if len(text.split()) < 2:
  197. await client.answer_inline_query(
  198. query.id,
  199. results=answers,
  200. switch_pm_text="Global Message Search. | search [QUERY]",
  201. switch_pm_parameter="inline",
  202. )
  203. return
  204. user_id = query.from_user.id
  205. tex = text.split(None, 1)[1].strip()
  206. answerss = await tg_search_func(answers, tex, user_id)
  207. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  208. elif text.split()[0] == "music":
  209. if len(text.split()) < 2:
  210. await client.answer_inline_query(
  211. query.id,
  212. results=answers,
  213. switch_pm_text="Music Search | music [QUERY]",
  214. switch_pm_parameter="inline",
  215. )
  216. return
  217. tex = text.split(None, 1)[1].strip()
  218. answerss = await music_inline_func(answers, tex)
  219. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  220. elif text.split()[0] == "wiki":
  221. if len(text.split()) < 2:
  222. await client.answer_inline_query(
  223. query.id,
  224. results=answers,
  225. switch_pm_text="Wikipedia | wiki [QUERY]",
  226. switch_pm_parameter="inline",
  227. )
  228. return
  229. tex = text.split(None, 1)[1].strip()
  230. answerss = await wiki_func(answers, tex)
  231. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  232. elif text.split()[0] == "speedtest":
  233. answerss = await speedtest_init(query)
  234. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  235. return
  236. elif text.split()[0] == "paste":
  237. if len(text.split()) < 2:
  238. await client.answer_inline_query(
  239. query.id,
  240. results=answers,
  241. switch_pm_text="Pastebin | paste [TG_MESSAGE_LINK]",
  242. switch_pm_parameter="inline",
  243. )
  244. return
  245. link = text.strip().split()[1]
  246. answerss = await pastebin_func(answers, link)
  247. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  248. return
  249. elif text.split()[0] == "carbon":
  250. if len(text.split()) < 2:
  251. await client.answer_inline_query(
  252. query.id,
  253. results=answers,
  254. switch_pm_text="Carbon | carbon [TG_MESSAGE_LINK]",
  255. switch_pm_parameter="inline",
  256. )
  257. return
  258. link = text.split()[1]
  259. answerss = await carbon_inline_func(answers, link)
  260. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  261. return
  262. elif text.split()[0] == "pmpermit":
  263. user_id = query.from_user.id
  264. victim = text.split()[1]
  265. answerss = await pmpermit_func(answers, user_id, victim)
  266. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  267. return
  268. elif text.split()[0] == "ping":
  269. answerss = await ping_func(answers)
  270. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  271. return
  272. elif text.split()[0] == "nsfw_scan":
  273. if len(text.split()) < 2:
  274. await client.answer_inline_query(
  275. query.id,
  276. results=answers,
  277. switch_pm_text="NSFW Scan | nsfw_scan [url]",
  278. switch_pm_parameter="inline",
  279. )
  280. return
  281. tex = text.split(None, 1)[1].strip()
  282. answerss = await nsfw_scan_func(answers, tex)
  283. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  284. elif text.split()[0] == "ytmusic":
  285. if len(text.split()) < 2:
  286. await client.answer_inline_query(
  287. query.id,
  288. results=answers,
  289. switch_pm_text="YT Music | ytmusic [url]",
  290. switch_pm_parameter="inline",
  291. )
  292. return
  293. tex = query.query.split(None, 1)[1].strip()
  294. user_id = query.from_user.id
  295. answerss = await yt_music_func(answers, tex, user_id)
  296. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  297. elif text.split()[0] == "info":
  298. if len(text.split()) < 2:
  299. await client.answer_inline_query(
  300. query.id,
  301. results=answers,
  302. switch_pm_text="User Info | info [USERNAME|ID]",
  303. switch_pm_parameter="inline",
  304. )
  305. return
  306. tex = text.split()[1].strip()
  307. answerss = await user_info_inline_func(answers, tex)
  308. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  309. elif text.split()[0] == "chat_info":
  310. if len(text.split()) < 2:
  311. await client.answer_inline_query(
  312. query.id,
  313. results=answers,
  314. switch_pm_text="Chat Info | chat_info [USERNAME|ID]",
  315. switch_pm_parameter="inline",
  316. )
  317. return
  318. tex = text.split()[1].strip()
  319. answerss = await chat_info_inline_func(answers, tex)
  320. await client.answer_inline_query(query.id, results=answerss, cache_time=2)
  321. except Exception as e:
  322. e = traceback.format_exc()
  323. print(e, " InLine")
  324. return