inline.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. # flake8: noqa F405
  2. """
  3. MIT License
  4. Copyright (c) 2024 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 pyrogram import filters
  23. from wbb import BOT_USERNAME, app
  24. from wbb.utils.inlinefuncs import *
  25. __MODULE__ = "Inline"
  26. __HELP__ = f"""
  27. Send /inline for help related to inline.
  28. **Example Usage:**
  29. `@{BOT_USERNAME} google github`
  30. """
  31. @app.on_message(filters.command("inline"))
  32. async def inline(_, message):
  33. buttons = InlineKeyboard(row_width=4)
  34. buttons.add(
  35. *[
  36. (InlineKeyboardButton(text=i, switch_inline_query_current_chat=i))
  37. for i in keywords_list
  38. ]
  39. )
  40. text = "**Here are the commands available for inline**"
  41. await message.reply_text(text=text, reply_markup=buttons)
  42. @app.on_inline_query()
  43. async def inline_query_handler(client, query):
  44. try:
  45. text = query.query.strip().lower()
  46. answers = []
  47. if text.strip() == "":
  48. answerss = await inline_help_func(__HELP__)
  49. await client.answer_inline_query(
  50. query.id, results=answerss, cache_time=10
  51. )
  52. elif text.split()[0] == "alive":
  53. answerss = await alive_function(answers)
  54. await client.answer_inline_query(
  55. query.id, results=answerss, cache_time=10
  56. )
  57. elif text.split()[0] == "tr":
  58. if len(text.split()) < 3:
  59. return await client.answer_inline_query(
  60. query.id,
  61. results=answers,
  62. switch_pm_text="Translator | tr [LANG] [TEXT]",
  63. switch_pm_parameter="inline",
  64. )
  65. lang = text.split()[1]
  66. tex = text.split(None, 2)[2].strip()
  67. answerss = await translate_func(answers, lang, tex)
  68. await client.answer_inline_query(
  69. query.id,
  70. results=answerss,
  71. )
  72. elif text.split()[0] == "ud":
  73. if len(text.split()) < 2:
  74. return await client.answer_inline_query(
  75. query.id,
  76. results=answers,
  77. switch_pm_text="Urban Dictionary | ud [QUERY]",
  78. switch_pm_parameter="inline",
  79. )
  80. tex = text.split(None, 1)[1].strip()
  81. answerss = await urban_func(answers, tex)
  82. await client.answer_inline_query(
  83. query.id,
  84. results=answerss,
  85. )
  86. elif text.split()[0] == "google":
  87. if len(text.split()) < 2:
  88. return await client.answer_inline_query(
  89. query.id,
  90. results=answers,
  91. switch_pm_text="Google Search | google [QUERY]",
  92. switch_pm_parameter="inline",
  93. )
  94. tex = text.split(None, 1)[1].strip()
  95. answerss = await google_search_func(answers, tex)
  96. await client.answer_inline_query(
  97. query.id,
  98. results=answerss,
  99. )
  100. elif text.split()[0] == "wall":
  101. if len(text.split()) < 2:
  102. return await client.answer_inline_query(
  103. query.id,
  104. results=answers,
  105. is_gallery=True,
  106. switch_pm_text="Wallpapers Search | wall [QUERY]",
  107. switch_pm_parameter="inline",
  108. )
  109. tex = text.split(None, 1)[1].strip()
  110. answerss = await wall_func(answers, tex)
  111. await client.answer_inline_query(
  112. query.id, results=answerss, cache_time=2
  113. )
  114. elif text.split()[0] == "torrent":
  115. if len(text.split()) < 2:
  116. return await client.answer_inline_query(
  117. query.id,
  118. results=answers,
  119. switch_pm_text="Torrent Search | torrent [QUERY]",
  120. switch_pm_parameter="inline",
  121. )
  122. tex = text.split(None, 1)[1].strip()
  123. answerss = await torrent_func(answers, tex)
  124. await client.answer_inline_query(
  125. query.id,
  126. results=answerss,
  127. )
  128. elif text.split()[0] == "yt":
  129. if len(text.split()) < 2:
  130. return await client.answer_inline_query(
  131. query.id,
  132. results=answers,
  133. switch_pm_text="YouTube Search | yt [QUERY]",
  134. switch_pm_parameter="inline",
  135. )
  136. tex = text.split(None, 1)[1].strip()
  137. answerss = await youtube_func(answers, tex)
  138. await client.answer_inline_query(query.id, results=answerss)
  139. elif text.split()[0] == "lyrics":
  140. if len(text.split()) < 2:
  141. return await client.answer_inline_query(
  142. query.id,
  143. results=answers,
  144. switch_pm_text="Lyrics Search | lyrics [QUERY]",
  145. switch_pm_parameter="inline",
  146. )
  147. tex = text.split(None, 1)[1].strip()
  148. answerss = await lyrics_func(answers, tex)
  149. await client.answer_inline_query(query.id, results=answerss)
  150. elif text.split()[0] == "search":
  151. if len(text.split()) < 2:
  152. return await client.answer_inline_query(
  153. query.id,
  154. results=answers,
  155. switch_pm_text="Global Message Search. | search [QUERY]",
  156. switch_pm_parameter="inline",
  157. )
  158. user_id = query.from_user.id
  159. tex = text.split(None, 1)[1].strip()
  160. answerss = await tg_search_func(answers, tex, user_id)
  161. await client.answer_inline_query(
  162. query.id, results=answerss, cache_time=2
  163. )
  164. elif text.split()[0] == "music":
  165. if len(text.split()) < 2:
  166. return await client.answer_inline_query(
  167. query.id,
  168. results=answers,
  169. switch_pm_text="Music Search | music [QUERY]",
  170. switch_pm_parameter="inline",
  171. )
  172. tex = text.split(None, 1)[1].strip()
  173. answerss = await music_inline_func(answers, tex)
  174. await client.answer_inline_query(
  175. query.id, results=answerss, cache_time=2
  176. )
  177. elif text.split()[0] == "wiki":
  178. if len(text.split()) < 2:
  179. return await client.answer_inline_query(
  180. query.id,
  181. results=answers,
  182. switch_pm_text="Wikipedia | wiki [QUERY]",
  183. switch_pm_parameter="inline",
  184. )
  185. tex = text.split(None, 1)[1].strip()
  186. answerss = await wiki_func(answers, tex)
  187. await client.answer_inline_query(
  188. query.id, results=answerss, cache_time=2
  189. )
  190. elif text.split()[0] == "speedtest":
  191. answerss = await speedtest_init(query)
  192. return await client.answer_inline_query(
  193. query.id, results=answerss, cache_time=2
  194. )
  195. elif text.split()[0] == "pmpermit":
  196. user_id = query.from_user.id
  197. victim = text.split()[1]
  198. answerss = await pmpermit_func(answers, user_id, victim)
  199. await client.answer_inline_query(
  200. query.id, results=answerss, cache_time=2
  201. )
  202. elif text.split()[0] == "ping":
  203. answerss = await ping_func(answers)
  204. await client.answer_inline_query(
  205. query.id, results=answerss, cache_time=2
  206. )
  207. elif text.split()[0] == "ytmusic":
  208. if len(text.split()) < 2:
  209. return await client.answer_inline_query(
  210. query.id,
  211. results=answers,
  212. switch_pm_text="YT Music | ytmusic [url]",
  213. switch_pm_parameter="inline",
  214. )
  215. tex = query.query.split(None, 1)[1].strip()
  216. answerss = await yt_music_func(answers, tex)
  217. await client.answer_inline_query(
  218. query.id, results=answerss, cache_time=2
  219. )
  220. elif text.split()[0] == "info":
  221. if len(text.split()) < 2:
  222. return await client.answer_inline_query(
  223. query.id,
  224. results=answers,
  225. switch_pm_text="User Info | info [USERNAME|ID]",
  226. switch_pm_parameter="inline",
  227. )
  228. tex = text.split()[1].strip()
  229. answerss = await info_inline_func(answers, tex)
  230. await client.answer_inline_query(
  231. query.id, results=answerss, cache_time=2
  232. )
  233. elif text.split()[0] == "tmdb":
  234. if len(text.split()) < 2:
  235. answerss = await tmdb_func(answers, "")
  236. return await client.answer_inline_query(
  237. query.id,
  238. results=answerss,
  239. switch_pm_text="TMDB Search | tmdb [QUERY]",
  240. switch_pm_parameter="inline",
  241. )
  242. tex = text.split()[1].strip()
  243. answerss = await tmdb_func(answers, tex)
  244. await client.answer_inline_query(
  245. query.id, results=answerss, cache_time=2
  246. )
  247. elif text.split()[0] == "image":
  248. if len(text.split()) < 2:
  249. return await client.answer_inline_query(
  250. query.id,
  251. results=answers,
  252. is_gallery=True,
  253. switch_pm_text="Image Search | image [QUERY]",
  254. switch_pm_parameter="inline",
  255. )
  256. tex = text.split(None, 1)[1].strip()
  257. answerss = await image_func(answers, tex)
  258. await client.answer_inline_query(
  259. query.id, results=answerss, cache_time=3600
  260. )
  261. elif text.split()[0] == "exec":
  262. await execute_code(query)
  263. elif text.strip() == "tasks":
  264. user_id = query.from_user.id
  265. answerss = await task_inline_func(user_id)
  266. await client.answer_inline_query(
  267. query.id, results=answerss, cache_time=1
  268. )
  269. except Exception as e:
  270. e = traceback.format_exc()
  271. print(e, " InLine")