misc.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. __MODULE__ = "Misc"
  32. __HELP__ = """
  33. /asq
  34. Ask a question
  35. /commit
  36. Generate Funny Commit Messages
  37. /runs
  38. Idk Test Yourself
  39. /id
  40. Get Chat_ID or User_ID
  41. /random [Length]
  42. Generate Random Complex Passwords
  43. /cheat [Language] [Query]
  44. Get Programming Related Help
  45. /tr [LANGUAGE_CODE]
  46. Translate A Message
  47. Ex: /tr en
  48. /arq
  49. Statistics Of ARQ API.
  50. /webss | .webss [URL] [FULL_SIZE?, use (y|yes|true) to get full size image. (optional)]
  51. Take A Screenshot Of A Webpage
  52. /reverse
  53. Reverse search an image.
  54. /carbon
  55. Make Carbon from code.
  56. /tts
  57. Convert Text To Speech.
  58. /autocorrect [Reply to a message]
  59. Autocorrects the text in replied message.
  60. /pdf [Reply to an image (as document) or a group of images.]
  61. Convert images to PDF, helpful for online classes.
  62. /markdownhelp
  63. Sends mark down and formatting help.
  64. /backup
  65. Backup database
  66. /ping
  67. Check ping of all 5 DCs.
  68. #RTFM - Tell noobs to read the manual
  69. """
  70. ASQ_LOCK = Lock()
  71. PING_LOCK = Lock()
  72. @app2.on_message(
  73. SUDOERS
  74. & filters.command("ping", prefixes=USERBOT_PREFIX)
  75. & ~filters.forwarded
  76. & ~filters.via_bot
  77. )
  78. @app.on_message(filters.command("ping"))
  79. async def ping_handler(_, message):
  80. m = await eor(message, text="Pinging datacenters...")
  81. async with PING_LOCK:
  82. ips = {
  83. "dc1": "149.154.175.53",
  84. "dc2": "149.154.167.51",
  85. "dc3": "149.154.175.100",
  86. "dc4": "149.154.167.91",
  87. "dc5": "91.108.56.130",
  88. }
  89. text = "**Pings:**\n"
  90. for dc, ip in ips.items():
  91. try:
  92. shell = subprocess.run(
  93. ["ping", "-c", "1", "-W", "2", ip],
  94. text=True,
  95. check=True,
  96. capture_output=True,
  97. )
  98. resp_time = findall(r"time=.+m?s", shell.stdout, re.MULTILINE)[
  99. 0
  100. ].replace("time=", "")
  101. text += f" **{dc.upper()}:** {resp_time} ✅\n"
  102. except Exception:
  103. # There's a cross emoji here, but it's invisible.
  104. text += f" **{dc.upper}:** ❌\n"
  105. await m.edit(text)
  106. @app.on_message(filters.command("asq"))
  107. async def asq(_, message):
  108. err = "Reply to text message or pass the question as argument"
  109. if message.reply_to_message:
  110. if not message.reply_to_message.text:
  111. return await message.reply(err)
  112. question = message.reply_to_message.text
  113. else:
  114. if len(message.command) < 2:
  115. return await message.reply(err)
  116. question = message.text.split(None, 1)[1]
  117. m = await message.reply("Thinking...")
  118. async with ASQ_LOCK:
  119. resp = await arq.asq(question)
  120. await m.edit(resp.result)
  121. @app.on_message(filters.command("commit"))
  122. async def commit(_, message):
  123. await message.reply_text(await get("http://whatthecommit.com/index.txt"))
  124. @app.on_message(filters.command("RTFM", "#"))
  125. async def rtfm(_, message):
  126. await message.delete()
  127. if not message.reply_to_message:
  128. return await message.reply_text("Reply To A Message lol")
  129. await message.reply_to_message.reply_text("Are You Lost? READ THE FUCKING DOCS!")
  130. @app.on_message(filters.command("runs"))
  131. async def runs(_, message):
  132. await message.reply_text((await random_line("wbb/utils/runs.txt")))
  133. @app2.on_message(
  134. filters.command("id", prefixes=USERBOT_PREFIX)
  135. & ~filters.forwarded
  136. & ~filters.via_bot
  137. & SUDOERS
  138. )
  139. @app.on_message(filters.command("id"))
  140. async def getid(client, message):
  141. chat = message.chat
  142. your_id = message.from_user.id
  143. message_id = message.id
  144. reply = message.reply_to_message
  145. text = f"**[Message ID:]({message.link})** `{message_id}`\n"
  146. text += f"**[Your ID:](tg://user?id={your_id})** `{your_id}`\n"
  147. if not message.command:
  148. message.command = message.text.split()
  149. if len(message.command) == 2:
  150. try:
  151. split = message.text.split(None, 1)[1].strip()
  152. user_id = (await client.get_users(split)).id
  153. text += f"**[User ID:](tg://user?id={user_id})** `{user_id}`\n"
  154. except Exception:
  155. return await eor(message, text="This user doesn't exist.")
  156. text += f"**[Chat ID:](https://t.me/{chat.username})** `{chat.id}`\n\n"
  157. if not getattr(reply, "empty", True):
  158. id_ = reply.from_user.id if reply.from_user else reply.sender_chat.id
  159. text += f"**[Replied Message ID:]({reply.link})** `{reply.id}`\n"
  160. text += f"**[Replied User ID:](tg://user?id={id_})** `{id_}`"
  161. await eor(
  162. message,
  163. text=text,
  164. disable_web_page_preview=True,
  165. parse_mode=enums.ParseMode.MARKDOWN,
  166. )
  167. # Random
  168. @app.on_message(filters.command("random"))
  169. @capture_err
  170. async def random(_, message):
  171. if len(message.command) != 2:
  172. return await message.reply_text('"/random" Needs An Argurment. Ex: `/random 5`')
  173. length = message.text.split(None, 1)[1]
  174. try:
  175. if 1 < int(length) < 1000:
  176. alphabet = string.ascii_letters + string.digits
  177. password = "".join(secrets.choice(alphabet) for i in range(int(length)))
  178. await message.reply_text(f"`{password}`")
  179. else:
  180. await message.reply_text("Specify A Length Between 1-1000")
  181. except ValueError:
  182. await message.reply_text(
  183. "Strings Won't Work!, Pass A Positive Integer Less Than 1000"
  184. )
  185. # Translate
  186. @app.on_message(filters.command("tr"))
  187. @capture_err
  188. async def tr(_, message):
  189. if len(message.command) != 2:
  190. return await message.reply_text("/tr [LANGUAGE_CODE]")
  191. lang = message.text.split(None, 1)[1]
  192. if not message.reply_to_message or not lang:
  193. return await message.reply_text(
  194. "Reply to a message with /tr [language code]"
  195. + "\nGet supported language list from here -"
  196. + " https://py-googletrans.readthedocs.io/en"
  197. + "/latest/#googletrans-languages"
  198. )
  199. reply = message.reply_to_message
  200. text = reply.text or reply.caption
  201. if not text:
  202. return await message.reply_text("Reply to a text to translate it")
  203. result = await arq.translate(text, lang)
  204. if not result.ok:
  205. return await message.reply_text(result.result)
  206. await message.reply_text(result.result.translatedText)
  207. @app.on_message(filters.command(["kickme", "banme"]))
  208. async def kickbanme(_, message):
  209. await message.reply_text(
  210. "Haha, it doesn't work that way, You're stuck here with everyone."
  211. )