misc.py 10 KB

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