misc.py 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. """
  2. MIT License
  3. Copyright (c) 2021 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 secrets
  21. import string
  22. import aiohttp
  23. from cryptography.fernet import Fernet
  24. from pyrogram import filters
  25. from wbb import FERNET_ENCRYPTION_KEY, app, arq
  26. from wbb.core.decorators.errors import capture_err
  27. from wbb.utils import random_line
  28. from wbb.utils.http import get
  29. from wbb.utils.json_prettify import json_prettify
  30. from wbb.utils.pastebin import paste
  31. __MODULE__ = "Misc"
  32. __HELP__ = """
  33. /asq - Ask a question
  34. /commit - Generate Funny Commit Messages
  35. /runs - Idk Test Yourself
  36. /id - Get Chat_ID or User_ID
  37. /random [Length] - Generate Random Complex Passwords
  38. /encrypt - Encrypt Text [Can Only Be Decrypted By This Bot]
  39. /decrypt - Decrypt Text
  40. /cheat [Language] [Query] - Get Programming Related Help
  41. /tr [en] - Translate A Message
  42. /json [URL] - Get JSON Response From An API or Something.
  43. /arq - Statistics Of ARQ API.
  44. /webss [URL] - Take A Screenshot Of A Webpage
  45. /reverse - Reverse search an image.
  46. /carbon - Make Carbon from code.
  47. /tts - Convert Text To Speech.
  48. #RTFM - Tell noobs to read the manual
  49. """
  50. @app.on_message(filters.command("asq"))
  51. async def asq(_, message):
  52. err = "Reply to text message or pass the question as argument"
  53. if message.reply_to_message:
  54. if not message.reply_to_message.text:
  55. return await message.reply(err)
  56. question = message.reply_to_message.text
  57. else:
  58. if len(message.command) < 2:
  59. return await message.reply(err)
  60. question = message.text.split(None, 1)[1]
  61. m = await message.reply("Thinking...")
  62. resp = await arq.asq(question)
  63. await m.edit(resp.result)
  64. @app.on_message(filters.command("commit") & ~filters.edited)
  65. async def commit(_, message):
  66. await message.reply_text(
  67. await get("http://whatthecommit.com/index.txt")
  68. )
  69. @app.on_message(filters.command("RTFM", "#"))
  70. async def rtfm(_, message):
  71. await message.delete()
  72. if not message.reply_to_message:
  73. return await message.reply_text("Reply To A Message lol")
  74. await message.reply_to_message.reply_text(
  75. "Are You Lost? READ THE FUCKING DOCS!"
  76. )
  77. @app.on_message(filters.command("runs") & ~filters.edited)
  78. async def runs(_, message):
  79. await message.reply_text(
  80. (await random_line("wbb/utils/runs.txt"))
  81. )
  82. @app.on_message(filters.command("id"))
  83. async def getid(_, message):
  84. chat = message.chat
  85. your_id = message.from_user.id
  86. message_id = message.message_id
  87. reply = message.reply_to_message
  88. text = f"**[Message ID:]({message.link})** `{message_id}`\n"
  89. text += f"**[Your ID:](tg://user?id={your_id})** `{your_id}`\n"
  90. if len(message.command) == 2:
  91. try:
  92. split = message.text.split(None, 1)[1].strip()
  93. user_id = (await app.get_users(split)).id
  94. text += f"**[User ID:](tg://user?id={user_id})** `{user_id}`\n"
  95. except Exception:
  96. return await message.reply_text(
  97. "This user doesn't exist."
  98. )
  99. text += f"**[Chat ID:](https://t.me/{chat.username})** `{chat.id}`\n\n"
  100. if not getattr(reply, "empty", True):
  101. text += f"**[Replied Message ID:]({reply.link})** `{reply.message_id}`\n"
  102. text += f"**[Replied User ID:](tg://user?id={reply.from_user.id})** `{reply.from_user.id}`"
  103. await message.reply_text(
  104. text, disable_web_page_preview=True, parse_mode="md"
  105. )
  106. # Random
  107. @app.on_message(filters.command("random") & ~filters.edited)
  108. @capture_err
  109. async def random(_, message):
  110. if len(message.command) != 2:
  111. return await message.reply_text(
  112. '"/random" Needs An Argurment.' " Ex: `/random 5`"
  113. )
  114. length = message.text.split(None, 1)[1]
  115. try:
  116. if 1 < int(length) < 1000:
  117. alphabet = string.ascii_letters + string.digits
  118. password = "".join(
  119. secrets.choice(alphabet) for i in range(int(length))
  120. )
  121. await message.reply_text(f"`{password}`")
  122. else:
  123. await message.reply_text(
  124. "Specify A Length Between 1-1000"
  125. )
  126. except ValueError:
  127. await message.reply_text(
  128. "Strings Won't Work!, Pass A Positive Integer Less Than 1000"
  129. )
  130. # Encrypt
  131. @app.on_message(filters.command("encrypt") & ~filters.edited)
  132. @capture_err
  133. async def encrypt(_, message):
  134. if not message.reply_to_message:
  135. return await message.reply_text(
  136. "Reply To A Message To Encrypt It."
  137. )
  138. text = message.reply_to_message.text
  139. text_in_bytes = bytes(text, "utf-8")
  140. cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
  141. encrypted_text = cipher_suite.encrypt(text_in_bytes)
  142. bytes_in_text = encrypted_text.decode("utf-8")
  143. await message.reply_text(bytes_in_text)
  144. # Decrypt
  145. @app.on_message(filters.command("decrypt") & ~filters.edited)
  146. @capture_err
  147. async def decrypt(_, message):
  148. if not message.reply_to_message:
  149. return await message.reply_text(
  150. "Reply To A Message To Decrypt It."
  151. )
  152. text = message.reply_to_message.text
  153. text_in_bytes = bytes(text, "utf-8")
  154. cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
  155. try:
  156. decoded_text = cipher_suite.decrypt(text_in_bytes)
  157. except Exception:
  158. return await message.reply_text("Incorrect token")
  159. bytes_in_text = decoded_text.decode("utf-8")
  160. await message.reply_text(bytes_in_text)
  161. async def fetch_text(url):
  162. async with aiohttp.ClientSession(
  163. headers={"user-agent": "curl"}
  164. ) as session:
  165. async with session.get(url) as resp:
  166. data = await resp.text()
  167. return data
  168. # Cheat.sh
  169. @app.on_message(filters.command("cheat") & ~filters.edited)
  170. @capture_err
  171. async def cheat(_, message):
  172. if len(message.command) < 3:
  173. return await message.reply_text("/cheat [language] [query]")
  174. text = message.text.split(None, 2)
  175. m = await message.reply_text("Searching")
  176. try:
  177. language = text[1]
  178. query = text[2]
  179. data = await fetch_text(
  180. f"http://cht.sh/{language}/{query}?QT"
  181. )
  182. if not data:
  183. return await m.edit("Found Literally Nothing!")
  184. if len(data) > 4090:
  185. with open("cheat.txt", "w") as f:
  186. f.write(data)
  187. return await message.reply_document(data)
  188. await m.edit(f"`{data}`")
  189. except Exception as e:
  190. await m.edit(str(e))
  191. print(str(e))
  192. # Translate
  193. @app.on_message(filters.command("tr") & ~filters.edited)
  194. @capture_err
  195. async def tr(_, message):
  196. if len(message.command) != 2:
  197. return await message.reply_text("/tr [LANGUAGE_CODE]")
  198. lang = message.text.split(None, 1)[1]
  199. if not message.reply_to_message or not lang:
  200. return await message.reply_text(
  201. "Reply to a message with /tr [language code]"
  202. + "\nGet supported language list from here -"
  203. + " https://py-googletrans.readthedocs.io/en"
  204. + "/latest/#googletrans-languages"
  205. )
  206. reply = message.reply_to_message
  207. text = reply.text or reply.caption
  208. if not text:
  209. return await message.reply_text(
  210. "Reply to a text to translate it"
  211. )
  212. result = await arq.translate(text, lang)
  213. if not result.ok:
  214. return await message.reply_text(result.result)
  215. await message.reply_text(result.result.translatedText)
  216. @app.on_message(filters.command("json") & ~filters.edited)
  217. @capture_err
  218. async def json_fetch(_, message):
  219. if len(message.command) != 2:
  220. return await message.reply_text("/json [URL]")
  221. url = message.text.split(None, 1)[1]
  222. m = await message.reply_text("Fetching")
  223. try:
  224. data = await get(url)
  225. data = await json_prettify(data)
  226. if len(data) < 4090:
  227. await m.edit(data)
  228. else:
  229. link = await paste(data)
  230. await m.edit(
  231. f"[OUTPUT_TOO_LONG]({link})",
  232. disable_web_page_preview=True,
  233. )
  234. except Exception as e:
  235. await m.edit(str(e))
  236. @app.on_message(filters.command("webss"))
  237. @capture_err
  238. async def take_ss(_, message):
  239. if len(message.command) != 2:
  240. return await message.reply_text(
  241. "Give A Url To Fetch Screenshot."
  242. )
  243. url = message.text.split(None, 1)[1]
  244. m = await message.reply_text("**Uploading**")
  245. try:
  246. await app.send_photo(
  247. message.chat.id,
  248. photo=f"https://webshot.amanoteam.com/print?q={url}",
  249. )
  250. except Exception:
  251. return await m.edit("No Such Website.")
  252. await m.delete()
  253. @app.on_message(filters.command(["kickme", "banme"]))
  254. async def kickbanme(_, message):
  255. await message.reply_text(
  256. "Haha, it doesn't work that way, You're stuck with everyone here."
  257. )