misc.py 10 KB

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