misc.py 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. /webss [URL] - Take A Screenshot Of A Webpage
  45. #RTFM - Tell noobs to read the manual
  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. return await message.reply_text("Reply To A Message lol")
  55. await message.reply_to_message.reply_text(
  56. "Are You Lost? READ THE FUCKING DOCS!"
  57. )
  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. try:
  65. id = (await app.get_users(message.text.split(None, 1)[1].strip())).id
  66. except Exception:
  67. return await message.reply_text("No Such User")
  68. text = f"**ID:** `{id}`"
  69. return await message.reply_text(text, parse_mode="html")
  70. text_unping = "<b>Chat ID:</b>"
  71. if message.chat.username:
  72. text_unping = (
  73. f'<a href="https://t.me/{message.chat.username}">{text_unping}</a>'
  74. )
  75. text_unping += f" <code>{message.chat.id}</code>\n"
  76. text = "<b>Message ID:</b>"
  77. if message.link:
  78. text = f'<a href="{message.link}">{text}</a>'
  79. text += f" <code>{message.message_id}</code>\n"
  80. text_unping += text
  81. if message.from_user:
  82. text_unping += f'<b><a href="tg://user?id={message.from_user.id}">User ID:</a></b> <code>{message.from_user.id}</code>\n'
  83. text_ping = text_unping
  84. reply = message.reply_to_message
  85. if not getattr(reply, "empty", True):
  86. text_unping += "\n"
  87. text = "<b>Replied Message ID:</b>"
  88. if reply.link:
  89. text = f'<a href="{reply.link}">{text}</a>'
  90. text += f" <code>{reply.message_id}</code>\n"
  91. text_unping += text
  92. text_ping = text_unping
  93. if reply.from_user:
  94. text = "<b>Replied User ID:</b>"
  95. if reply.from_user.username:
  96. text = f'<a href="https://t.me/{reply.from_user.username}">{text}</a>'
  97. text += f" <code>{reply.from_user.id}</code>\n"
  98. text_unping += text
  99. 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'
  100. if reply.forward_from:
  101. text_unping += "\n"
  102. text = "<b>Forwarded User ID:</b>"
  103. if reply.forward_from.username:
  104. text = f'<a href="https://t.me/{reply.forward_from.username}">{text}</a>'
  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. return await message.reply_text(
  121. '"/random" Needs An Argurment.' " Ex: `/random 5`"
  122. )
  123. length = message.text.split(None, 1)[1]
  124. try:
  125. if 1 < int(length) < 1000:
  126. alphabet = string.ascii_letters + string.digits
  127. password = "".join(
  128. secrets.choice(alphabet) for i in range(int(length))
  129. )
  130. await message.reply_text(f"`{password}`")
  131. else:
  132. await message.reply_text("Specify A Length Between 1-1000")
  133. except ValueError:
  134. await message.reply_text(
  135. "Strings Won't Work!, Pass A Positive Integer Less Than 1000"
  136. )
  137. # Encrypt
  138. @app.on_message(filters.command("encrypt") & ~filters.edited)
  139. @capture_err
  140. async def encrypt(_, message):
  141. if not message.reply_to_message:
  142. return await message.reply_text("Reply To A Message To Encrypt It.")
  143. text = message.reply_to_message.text
  144. text_in_bytes = bytes(text, "utf-8")
  145. cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
  146. encrypted_text = cipher_suite.encrypt(text_in_bytes)
  147. bytes_in_text = encrypted_text.decode("utf-8")
  148. await message.reply_text(bytes_in_text)
  149. # Decrypt
  150. @app.on_message(filters.command("decrypt") & ~filters.edited)
  151. @capture_err
  152. async def decrypt(_, message):
  153. if not message.reply_to_message:
  154. return await message.reply_text("Reply To A Message To Decrypt It.")
  155. text = message.reply_to_message.text
  156. text_in_bytes = bytes(text, "utf-8")
  157. cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
  158. try:
  159. decoded_text = cipher_suite.decrypt(text_in_bytes)
  160. except Exception:
  161. return await message.reply_text("Incorrect token")
  162. bytes_in_text = decoded_text.decode("utf-8")
  163. await message.reply_text(bytes_in_text)
  164. async def fetch_text(url):
  165. async with aiohttp.ClientSession(
  166. headers={"user-agent": "curl"}
  167. ) as session:
  168. async with session.get(url) as resp:
  169. data = await resp.text()
  170. return data
  171. # Cheat.sh
  172. @app.on_message(filters.command("cheat") & ~filters.edited)
  173. @capture_err
  174. async def cheat(_, message):
  175. if len(message.command) < 3:
  176. return await message.reply_text("/cheat [language] [query]")
  177. text = message.text.split(None, 1)[1]
  178. m = await message.reply_text("Searching")
  179. try:
  180. ftext = text.split()
  181. language = ftext[0]
  182. query = ftext[1]
  183. data = await fetch_text(f"http://cht.sh/{language}/{query}?QT")
  184. if not data:
  185. return await m.edit("Found Literally Nothing!")
  186. await m.edit(f"`{data}`")
  187. except Exception as e:
  188. await m.edit(str(e))
  189. print(str(e))
  190. # Translate
  191. @app.on_message(filters.command("tr") & ~filters.edited)
  192. @capture_err
  193. async def tr(_, message):
  194. if len(message.command) != 2:
  195. return await message.reply_text("/tr [LANGUAGE_CODE]")
  196. lang = message.text.split(None, 1)[1]
  197. if not message.reply_to_message or not lang:
  198. return await message.reply_text(
  199. "Reply to a message with /tr [language code]"
  200. + "\nGet supported language list from here -"
  201. + " https://py-googletrans.readthedocs.io/en"
  202. + "/latest/#googletrans-languages"
  203. )
  204. if message.reply_to_message.text:
  205. text = message.reply_to_message.text
  206. elif message.reply_to_message.caption:
  207. text = message.reply_to_message.caption
  208. result = await arq.translate(text, lang)
  209. if not result.ok:
  210. return await message.reply_text(result.result)
  211. await message.reply_text(result.result.translatedText)
  212. @app.on_message(filters.command("json") & ~filters.edited)
  213. @capture_err
  214. async def json_fetch(_, message):
  215. if len(message.command) != 2:
  216. return await message.reply_text("/json [URL]")
  217. url = message.text.split(None, 1)[1]
  218. m = await message.reply_text("Fetching")
  219. try:
  220. data = await fetch(url)
  221. data = await json_prettify(data)
  222. if len(data) < 4090:
  223. await m.edit(data)
  224. else:
  225. link = await paste(data)
  226. await m.edit(
  227. f"[OUTPUT_TOO_LONG]({link})", disable_web_page_preview=True
  228. )
  229. except Exception as e:
  230. await m.edit(str(e))
  231. @app.on_message(filters.command("webss"))
  232. @capture_err
  233. async def take_ss(_, message):
  234. if len(message.command) != 2:
  235. return await message.reply_text("Give A Url To Fetch Screenshot.")
  236. url = message.text.split(None, 1)[1]
  237. m = await message.reply_text("**Uploading**")
  238. try:
  239. await app.send_photo(
  240. message.chat.id,
  241. photo=f"https://webshot.amanoteam.com/print?q={url}",
  242. )
  243. except Exception:
  244. return await m.edit("No Such Website.")
  245. await m.delete()