misc.py 10 KB

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