misc.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. """
  2. MIT License
  3. Copyright (c) 2024 TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. import re
  21. import secrets
  22. import string
  23. import subprocess
  24. from asyncio import Lock
  25. from re import findall
  26. from pyrogram import enums, filters
  27. from wbb import SUDOERS, USERBOT_PREFIX, app, app2, arq, eor
  28. from wbb.core.decorators.errors import capture_err
  29. from wbb.utils import random_line
  30. from wbb.utils.http import get
  31. from wbb.utils.json_prettify import json_prettify
  32. from wbb.utils.pastebin import paste
  33. __MODULE__ = "Misc"
  34. __HELP__ = """
  35. /asq
  36. Ask a question
  37. /commit
  38. Generate Funny Commit Messages
  39. /runs
  40. Idk Test Yourself
  41. /id
  42. Get Chat_ID or User_ID
  43. /random [Length]
  44. Generate Random Complex Passwords
  45. /cheat [Language] [Query]
  46. Get Programming Related Help
  47. /tr [LANGUAGE_CODE]
  48. Translate A Message
  49. Ex: /tr en
  50. /json [URL]
  51. Get parsed JSON response from a rest API.
  52. /arq
  53. Statistics Of ARQ API.
  54. /webss | .webss [URL] [FULL_SIZE?, use (y|yes|true) to get full size image. (optional)]
  55. Take A Screenshot Of A Webpage
  56. /reverse
  57. Reverse search an image.
  58. /carbon
  59. Make Carbon from code.
  60. /tts
  61. Convert Text To Speech.
  62. /autocorrect [Reply to a message]
  63. Autocorrects the text in replied message.
  64. /pdf [Reply to an image (as document) or a group of images.]
  65. Convert images to PDF, helpful for online classes.
  66. /markdownhelp
  67. Sends mark down and formatting help.
  68. /backup
  69. Backup database
  70. /ping
  71. Check ping of all 5 DCs.
  72. #RTFM - Tell noobs to read the manual
  73. """
  74. ASQ_LOCK = Lock()
  75. PING_LOCK = Lock()
  76. @app2.on_message(
  77. SUDOERS
  78. & filters.command("ping", prefixes=USERBOT_PREFIX)
  79. & ~filters.forwarded
  80. & ~filters.via_bot
  81. )
  82. @app.on_message(filters.command("ping"))
  83. async def ping_handler(_, message):
  84. m = await eor(message, text="Pinging datacenters...")
  85. async with PING_LOCK:
  86. ips = {
  87. "dc1": "149.154.175.53",
  88. "dc2": "149.154.167.51",
  89. "dc3": "149.154.175.100",
  90. "dc4": "149.154.167.91",
  91. "dc5": "91.108.56.130",
  92. }
  93. text = "**Pings:**\n"
  94. for dc, ip in ips.items():
  95. try:
  96. shell = subprocess.run(
  97. ["ping", "-c", "1", "-W", "2", ip],
  98. text=True,
  99. check=True,
  100. capture_output=True,
  101. )
  102. resp_time = findall(r"time=.+m?s", shell.stdout, re.MULTILINE)[
  103. 0
  104. ].replace("time=", "")
  105. text += f" **{dc.upper()}:** {resp_time} ✅\n"
  106. except Exception:
  107. # There's a cross emoji here, but it's invisible.
  108. text += f" **{dc.upper}:** ❌\n"
  109. await m.edit(text)
  110. @app.on_message(filters.command("asq"))
  111. async def asq(_, message):
  112. err = "Reply to text message or pass the question as argument"
  113. if message.reply_to_message:
  114. if not message.reply_to_message.text:
  115. return await message.reply(err)
  116. question = message.reply_to_message.text
  117. else:
  118. if len(message.command) < 2:
  119. return await message.reply(err)
  120. question = message.text.split(None, 1)[1]
  121. m = await message.reply("Thinking...")
  122. async with ASQ_LOCK:
  123. resp = await arq.asq(question)
  124. await m.edit(resp.result)
  125. @app.on_message(filters.command("commit"))
  126. async def commit(_, message):
  127. await message.reply_text(await get("http://whatthecommit.com/index.txt"))
  128. @app.on_message(filters.command("RTFM", "#"))
  129. async def rtfm(_, message):
  130. await message.delete()
  131. if not message.reply_to_message:
  132. return await message.reply_text("Reply To A Message lol")
  133. await message.reply_to_message.reply_text(
  134. "Are You Lost? READ THE FUCKING DOCS!"
  135. )
  136. @app.on_message(filters.command("runs"))
  137. async def runs(_, message):
  138. await message.reply_text((await random_line("wbb/utils/runs.txt")))
  139. @app2.on_message(
  140. filters.command("id", prefixes=USERBOT_PREFIX)
  141. & ~filters.forwarded
  142. & ~filters.via_bot
  143. & SUDOERS
  144. )
  145. @app.on_message(filters.command("id"))
  146. async def getid(client, message):
  147. chat = message.chat
  148. your_id = message.from_user.id
  149. message_id = message.id
  150. reply = message.reply_to_message
  151. text = f"**[Message ID:]({message.link})** `{message_id}`\n"
  152. text += f"**[Your ID:](tg://user?id={your_id})** `{your_id}`\n"
  153. if not message.command:
  154. message.command = message.text.split()
  155. if len(message.command) == 2:
  156. try:
  157. split = message.text.split(None, 1)[1].strip()
  158. user_id = (await client.get_users(split)).id
  159. text += f"**[User ID:](tg://user?id={user_id})** `{user_id}`\n"
  160. except Exception:
  161. return await eor(message, text="This user doesn't exist.")
  162. text += f"**[Chat ID:](https://t.me/{chat.username})** `{chat.id}`\n\n"
  163. if not getattr(reply, "empty", True):
  164. id_ = reply.from_user.id if reply.from_user else reply.sender_chat.id
  165. text += f"**[Replied Message ID:]({reply.link})** `{reply.id}`\n"
  166. text += f"**[Replied User ID:](tg://user?id={id_})** `{id_}`"
  167. await eor(
  168. message,
  169. text=text,
  170. disable_web_page_preview=True,
  171. parse_mode=enums.ParseMode.MARKDOWN,
  172. )
  173. # Random
  174. @app.on_message(filters.command("random"))
  175. @capture_err
  176. async def random(_, message):
  177. if len(message.command) != 2:
  178. return await message.reply_text(
  179. '"/random" Needs An Argurment.' " Ex: `/random 5`"
  180. )
  181. length = message.text.split(None, 1)[1]
  182. try:
  183. if 1 < int(length) < 1000:
  184. alphabet = string.ascii_letters + string.digits
  185. password = "".join(
  186. secrets.choice(alphabet) for i in range(int(length))
  187. )
  188. await message.reply_text(f"`{password}`")
  189. else:
  190. await message.reply_text("Specify A Length Between 1-1000")
  191. except ValueError:
  192. await message.reply_text(
  193. "Strings Won't Work!, Pass A Positive Integer Less Than 1000"
  194. )
  195. # Translate
  196. @app.on_message(filters.command("tr"))
  197. @capture_err
  198. async def tr(_, message):
  199. if len(message.command) != 2:
  200. return await message.reply_text("/tr [LANGUAGE_CODE]")
  201. lang = message.text.split(None, 1)[1]
  202. if not message.reply_to_message or not lang:
  203. return await message.reply_text(
  204. "Reply to a message with /tr [language code]"
  205. + "\nGet supported language list from here -"
  206. + " https://py-googletrans.readthedocs.io/en"
  207. + "/latest/#googletrans-languages"
  208. )
  209. reply = message.reply_to_message
  210. text = reply.text or reply.caption
  211. if not text:
  212. return await message.reply_text("Reply to a text to translate it")
  213. result = await arq.translate(text, lang)
  214. if not result.ok:
  215. return await message.reply_text(result.result)
  216. await message.reply_text(result.result.translatedText)
  217. @app.on_message(filters.command("json"))
  218. @capture_err
  219. async def json_fetch(_, message):
  220. if len(message.command) != 2:
  221. return await message.reply_text("/json [URL]")
  222. url = message.text.split(None, 1)[1]
  223. m = await message.reply_text("Fetching")
  224. try:
  225. data = await get(url)
  226. data = await json_prettify(data)
  227. if len(data) < 4090:
  228. await m.edit(data)
  229. else:
  230. link = await paste(data)
  231. await m.edit(
  232. f"[OUTPUT_TOO_LONG]({link})",
  233. disable_web_page_preview=True,
  234. )
  235. except Exception as e:
  236. await m.edit(str(e))
  237. @app.on_message(filters.command(["kickme", "banme"]))
  238. async def kickbanme(_, message):
  239. await message.reply_text(
  240. "Haha, it doesn't work that way, You're stuck with everyone here."
  241. )