misc.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 googletrans import Translator
  25. from pyrogram import filters
  26. from wbb import FERNET_ENCRYPTION_KEY, app
  27. from wbb.core.decorators.errors import capture_err
  28. from wbb.utils import random_line
  29. from wbb.utils.fetch import fetch
  30. from wbb.utils.json_prettify import json_prettify
  31. from wbb.utils.pastebin import paste
  32. __MODULE__ = "Misc"
  33. __HELP__ = """
  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. /weather [City] - To Get Weather Info
  42. /tr [en] - Translate A Message
  43. /json [URL] - Get JSON Response From An API or Something.
  44. /arq - Statistics Of ARQ API.
  45. #RTFM - Check it lol
  46. """
  47. @app.on_message(filters.command("commit") & ~filters.edited)
  48. async def commit(_, message):
  49. await message.reply_text((await random_line("wbb/utils/commit.txt")))
  50. @app.on_message(filters.command("RTFM", "#"))
  51. async def rtfm(_, message):
  52. await message.delete()
  53. if not message.reply_to_message:
  54. await message.reply_text("Reply To A Message lol")
  55. return
  56. await message.reply_to_message.reply_text(
  57. "Are You Lost? READ THE FUCKING DOCS!"
  58. )
  59. @app.on_message(filters.command("runs") & ~filters.edited)
  60. async def runs(_, message):
  61. await message.reply_text((await random_line("wbb/utils/runs.txt")))
  62. @app.on_message(filters.command("id"))
  63. async def getid(_, message):
  64. if len(message.command) == 2:
  65. id = (await app.get_users(message.text.split(None, 1)[1])).id
  66. text = f"**ID:** `{id}`"
  67. await message.reply_text(text, parse_mode="html")
  68. return
  69. text_unping = "<b>Chat ID:</b>"
  70. if message.chat.username:
  71. text_unping = f'<a href="https://t.me/{message.chat.username}">{text_unping}</a>'
  72. text_unping += f" <code>{message.chat.id}</code>\n"
  73. text = "<b>Message ID:</b>"
  74. if message.link:
  75. text = f'<a href="{message.link}">{text}</a>'
  76. text += f" <code>{message.message_id}</code>\n"
  77. text_unping += text
  78. if message.from_user:
  79. text_unping += f'<b><a href="tg://user?id={message.from_user.id}">User ID:</a></b> <code>{message.from_user.id}</code>\n'
  80. text_ping = text_unping
  81. reply = message.reply_to_message
  82. if not getattr(reply, "empty", True):
  83. text_unping += "\n"
  84. text = "<b>Replied Message ID:</b>"
  85. if reply.link:
  86. text = f'<a href="{reply.link}">{text}</a>'
  87. text += f" <code>{reply.message_id}</code>\n"
  88. text_unping += text
  89. text_ping = text_unping
  90. if reply.from_user:
  91. text = "<b>Replied User ID:</b>"
  92. if reply.from_user.username:
  93. text = f'<a href="https://t.me/{reply.from_user.username}">{text}</a>'
  94. text += f" <code>{reply.from_user.id}</code>\n"
  95. text_unping += text
  96. text_ping += f'<b><a href="tg://user?id={reply.from_user.id}">Replied User ID:</a></b> <code>{reply.from_user.id}</code>\n'
  97. if reply.forward_from:
  98. text_unping += "\n"
  99. text = "<b>Forwarded User ID:</b>"
  100. if reply.forward_from.username:
  101. text = f'<a href="https://t.me/{reply.forward_from.username}">{text}</a>'
  102. text += f" <code>{reply.forward_from.id}</code>\n"
  103. text_unping += text
  104. text_ping += f'\n<b><a href="tg://user?id={reply.forward_from.id}">Forwarded User ID:</a></b> <code>{reply.forward_from.id}</code>\n'
  105. reply = await message.reply_text(
  106. text_unping, disable_web_page_preview=True, parse_mode="html"
  107. )
  108. if text_unping != text_ping:
  109. await reply.edit_text(
  110. text_ping, disable_web_page_preview=True, parse_mode="html"
  111. )
  112. # Random
  113. @app.on_message(filters.command("random") & ~filters.edited)
  114. @capture_err
  115. async def random(_, message):
  116. if len(message.command) != 2:
  117. await message.reply_text(
  118. '"/random" Needs An Argurment.' " Ex: `/random 5`"
  119. )
  120. return
  121. length = message.text.split(None, 1)[1]
  122. try:
  123. if 1 < int(length) < 1000:
  124. alphabet = string.ascii_letters + string.digits
  125. password = "".join(
  126. secrets.choice(alphabet) for i in range(int(length))
  127. )
  128. await message.reply_text(f"`{password}`")
  129. else:
  130. await message.reply_text("Specify A Length Between 1-1000")
  131. except ValueError:
  132. await message.reply_text(
  133. "Strings Won't Work!, Pass A" + " Positive Integer Between 1-1000"
  134. )
  135. # Encrypt
  136. @app.on_message(filters.command("encrypt") & ~filters.edited)
  137. @capture_err
  138. async def encrypt(_, message):
  139. if not message.reply_to_message:
  140. await message.reply_text("Reply To A Message To Encrypt It.")
  141. return
  142. text = message.reply_to_message.text
  143. text_in_bytes = bytes(text, "utf-8")
  144. cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
  145. encrypted_text = cipher_suite.encrypt(text_in_bytes)
  146. bytes_in_text = encrypted_text.decode("utf-8")
  147. await message.reply_text(bytes_in_text)
  148. # Decrypt
  149. @app.on_message(filters.command("decrypt") & ~filters.edited)
  150. @capture_err
  151. async def decrypt(_, message):
  152. if not message.reply_to_message:
  153. await message.reply_text("Reply To A Message To Decrypt It.")
  154. return
  155. text = message.reply_to_message.text
  156. text_in_bytes = bytes(text, "utf-8")
  157. cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
  158. decoded_text = cipher_suite.decrypt(text_in_bytes)
  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. await message.reply_text("/cheat [language] [query]")
  174. return
  175. text = message.text.split(None, 1)[1]
  176. m = await message.reply_text("Searching")
  177. try:
  178. ftext = text.split()
  179. language = ftext[0]
  180. query = ftext[1]
  181. data = await fetch_text(f"http://cht.sh/{language}/{query}?QT")
  182. if not data:
  183. await m.edit("Found Literally Nothing!")
  184. return
  185. await m.edit(f"`{data}`")
  186. except Exception as e:
  187. await m.edit(str(e))
  188. print(str(e))
  189. # Weather
  190. @app.on_message(filters.command("weather") & ~filters.edited)
  191. @capture_err
  192. async def weather(_, message):
  193. if len(message.command) != 2:
  194. await message.reply_text("/weather [city]")
  195. return
  196. city = message.text.split(None, 1)[1]
  197. m = await message.reply_text("Fetching Data")
  198. data = await fetch_text(f"https://wttr.in/{city}?mnTC0")
  199. await m.edit(f"`{data}`")
  200. # Translate
  201. @app.on_message(filters.command("tr") & ~filters.edited)
  202. @capture_err
  203. async def tr(_, message):
  204. if len(message.command) != 2:
  205. await message.reply_text("/tr [LANGUAGE_CODE]")
  206. return
  207. lang = message.text.split(None, 1)[1]
  208. if not message.reply_to_message or not lang:
  209. await message.reply_text(
  210. "Reply to a message with /tr [language code]"
  211. + "\nGet supported language list from here -"
  212. + " https://py-googletrans.readthedocs.io/en"
  213. + "/latest/#googletrans-languages"
  214. )
  215. return
  216. if message.reply_to_message.text:
  217. text = message.reply_to_message.text
  218. try:
  219. i = Translator().translate(text, dest=lang)
  220. except ValueError:
  221. await message.reply_text("[ERROR]: LANGUAGE NOT FOUND")
  222. return
  223. await message.reply_text(i.text)
  224. elif message.reply_to_message.caption:
  225. text = message.reply_to_message.caption
  226. i = Translator().translate(text, dest=lang)
  227. await message.reply_text(i.text)
  228. fetch_limit = 0
  229. @app.on_message(filters.command("json") & ~filters.edited)
  230. @capture_err
  231. async def json_fetch(_, message):
  232. global fetch_limit
  233. if len(message.command) != 2:
  234. await message.reply_text("/json [URL]")
  235. return
  236. elif fetch_limit > 500:
  237. await message.reply_text("Today's Quota Exceeded!, lol")
  238. return
  239. url = message.text.split(None, 1)[1]
  240. try:
  241. data = await fetch(url)
  242. data = await json_prettify(data)
  243. fetch_limit += 1
  244. if len(data) < 4090:
  245. await message.reply_text(data)
  246. else:
  247. link = await paste(data)
  248. await message.reply_text(
  249. f"[OUTPUT_TOO_LONG]({link})", disable_web_page_preview=True
  250. )
  251. except Exception as e:
  252. await message.reply_text(str(e))
  253. print(str(e))
  254. @app.on_message(filters.command("bun"))
  255. async def bunn(_, message):
  256. if message.reply_to_message:
  257. await message.reply_to_message.reply_sticker(
  258. "CAACAgUAAx0CWIlO9AABARyRYBhyjKXFATVhu7AGQwip3TzSFiMAAuMBAAJ7usBUIu2xBtXTmuweBA"
  259. )
  260. await app.send_message(message.chat.id, text="Eat Bun")
  261. return
  262. if not message.reply_to_message:
  263. await message.reply_sticker(
  264. "CAACAgUAAx0CWIlO9AABARyRYBhyjKXFATVhu7AGQwip3TzSFiMAAuMBAAJ7usBUIu2xBtXTmuweBA"
  265. )
  266. await app.send_message(message.chat.id, text="Eat Bun")