misc.py 10 KB

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