misc.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import secrets
  2. import string
  3. import requests
  4. import ipinfo
  5. from pyrogram import filters
  6. from pyrogram.types import Message
  7. from googletrans import Translator
  8. from cryptography.fernet import Fernet
  9. from wbb.utils.botinfo import BOT_ID
  10. from wbb import app, FERNET_ENCRYPTION_KEY
  11. from wbb.utils import cust_filter, random_line
  12. __MODULE__ = "Misc"
  13. __HELP__ = '''/commit - Generate Funny Commit Messages
  14. /runs - Idk Test Yourself
  15. /quote - Get Random Linux Quotes
  16. /id - Get Chat_ID or User_ID
  17. /dev - Forward Anything To Developers [SPAM = GBAN]
  18. /random - Generate Random Complex Passwords
  19. /http - Get Cats Reference Photo For Http Error Codes
  20. /encrypt - Encrypt Text [Can Only Be Decrypted By This Bot]
  21. /decrypt - Decrypt Text
  22. /ipinfo - Get Info About An Ip Address
  23. /cheat - Get Programming Related Help
  24. /weather - To Get Weather Info
  25. /tr - Translate A Message'''
  26. @app.on_message(cust_filter.command(commands=("commit")) & ~filters.edited)
  27. async def commit(_, message: Message):
  28. await message.reply_text((await random_line('wbb/utils/commit.txt')))
  29. @app.on_message(cust_filter.command(commands=("runs")) & ~filters.edited)
  30. async def runs(_, message: Message):
  31. await message.reply_text((await random_line('wbb/utils/runs.txt')))
  32. @app.on_message(cust_filter.command(commands=("quote")) & ~filters.edited)
  33. async def quote(_, message: Message):
  34. await message.reply_text((await random_line('wbb/utils/quotes.txt')))
  35. @app.on_message(cust_filter.command(commands=("id")) & ~filters.edited)
  36. async def get_id(_, message: Message):
  37. app.set_parse_mode("markdown")
  38. if message.text != '/id':
  39. username = message.text.replace('/id', '')
  40. user_id = (await app.get_users(username)).id
  41. msg = f"{username}'s ID is `{user_id}`"
  42. await message.reply_text(msg)
  43. elif message.text == '/id' and not bool(message.reply_to_message):
  44. chat_id = message.chat.id
  45. msg = f"{message.chat.title}'s ID is `{chat_id}`"
  46. await message.reply_text(msg)
  47. elif message.text == '/id' and bool(message.reply_to_message):
  48. from_user_id = message.reply_to_message.from_user.id
  49. from_user_mention = message.reply_to_message.from_user.mention
  50. msg = f"{from_user_mention}'s ID is `{from_user_id}`"
  51. await message.reply_text(msg)
  52. @app.on_message(cust_filter.command(commands=("dev")) & ~filters.edited)
  53. async def dev(_, message: Message):
  54. app.set_parse_mode("markdown")
  55. if (await app.get_chat_member(
  56. message.chat.id,
  57. BOT_ID)).can_restrict_members:
  58. await message.reply_to_message.forward('WBBSupport')
  59. await app.send_message("WBBSupport",
  60. "Forwarded By: `{}` | {}\n"
  61. "Forwarded From: `{}` | {}"
  62. .format(message.from_user.id,
  63. message.from_user.mention,
  64. message.chat.id,
  65. message.chat.title))
  66. await message.reply_text("Your Message Has Been Forward To Devs,"
  67. + " Any Missuse Of This Feature Will Not"
  68. + " Be Tolerated And You Will Be"
  69. + " Gbanned instantaneously!")
  70. else:
  71. await message.reply_text("To Use This Feature You Have To Make Me"
  72. + " Admin")
  73. # Password
  74. @app.on_message(cust_filter.command(commands=('random')) & ~filters.edited)
  75. async def random(_, message: Message):
  76. app.set_parse_mode('markdown')
  77. if message.text != "/random":
  78. length = message.text.replace('/random', '')
  79. try:
  80. if 1 < int(length) < 1000:
  81. alphabet = string.ascii_letters + string.digits
  82. password = ''.join(secrets.choice(alphabet) for i in
  83. range(int(length)))
  84. await message.reply_text(f"`{password}`")
  85. else:
  86. await message.reply_text('Specify A Length Between 1-1000')
  87. except ValueError:
  88. await message.reply_text("Strings Won't Work!, Pass A"
  89. + " Positive Integer Between 1-1000")
  90. else:
  91. await message.reply_text('"/random" Needs An Argurment.'
  92. ' Ex: `/random 5`')
  93. # http cat search
  94. @app.on_message(cust_filter.command(commands=('http')) & ~filters.edited)
  95. async def http(_, message: Message):
  96. if message.text != "/http":
  97. code = message.text.replace('/http', '')
  98. url = f"https://http.cat/{code}"
  99. final = url.replace(' ', '')
  100. await message.reply_photo(final)
  101. else:
  102. await message.reply_text('"/http" Needs An Argument. Ex: `/http 404`')
  103. # Encrypt
  104. @app.on_message(cust_filter.command(commands=('encrypt')) & ~filters.edited)
  105. async def encrypt(_, message: Message):
  106. app.set_parse_mode('markdown')
  107. if not message.reply_to_message:
  108. await message.reply_text('Reply To A Message To Encrypt It.')
  109. else:
  110. text = message.reply_to_message.text
  111. text_in_bytes = bytes(text, 'utf-8')
  112. cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
  113. encrypted_text = cipher_suite.encrypt(text_in_bytes)
  114. bytes_in_text = encrypted_text.decode("utf-8")
  115. await message.reply_text(bytes_in_text)
  116. # Decrypt
  117. @app.on_message(cust_filter.command(commands=('decrypt')) & ~filters.edited)
  118. async def decrypt(_, message: Message):
  119. if not message.reply_to_message:
  120. await message.reply_text('Reply To A Message To Decrypt It.')
  121. else:
  122. text = message.reply_to_message.text
  123. text_in_bytes = bytes(text, 'utf-8')
  124. cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
  125. decoded_text = cipher_suite.decrypt(text_in_bytes)
  126. bytes_in_text = decoded_text.decode("utf-8")
  127. await message.reply_text(bytes_in_text)
  128. # Ipinfo
  129. @app.on_message(cust_filter.command(commands=('ipinfo')) & ~filters.edited)
  130. async def ipaddrinfo(_, message: Message):
  131. app.set_parse_mode('markdown')
  132. ipaddr = message.text.replace("/ipinfo", "")
  133. if ipaddr != "":
  134. handler = ipinfo.getHandler()
  135. details = handler.getDetails(ipaddr)
  136. await message.reply_text(f'''`IP - {details.ip}
  137. City - {details.city}
  138. Region - {details.region}
  139. Country - {details.country}
  140. Location - {details.loc}
  141. ORG - {details.org}
  142. Postal - {details.postal}
  143. Timezone - {details.timezone}`''')
  144. else:
  145. await message.reply_text('`/ipinfo` Requires An IP As Argument'
  146. + '. Ex - `/ipinfo 1.1.1.1`')
  147. # Cheat.sh
  148. @app.on_message(cust_filter.command(commands=("cheat")) & ~filters.edited)
  149. async def cheat(_, message: Message):
  150. text = message.text.replace("/cheat ", "")
  151. ftext = text.split()
  152. try:
  153. language = ftext[0]
  154. except IndexError:
  155. await message.reply_text("/cheat [language] [query]")
  156. try:
  157. query = ftext[1]
  158. except IndexError:
  159. await message.reply_text("/cheat [language] [query]")
  160. r = requests.get(f"http://cht.sh/{language}/{query}?QT")
  161. reply = r.text
  162. await message.reply_text(f"`{reply}`")
  163. # Weather
  164. @app.on_message(cust_filter.command(commands=("weather")) & ~filters.edited)
  165. async def weather(_, message: Message):
  166. city = message.text.replace("/weather ", "")
  167. if city != "":
  168. r = requests.get(f"https://wttr.in/{city}?mnTC0")
  169. data = r.text
  170. await message.reply_text(f"`{data}`")
  171. else:
  172. await message.reply_text("/weather [city]")
  173. # Translate
  174. @app.on_message(cust_filter.command(commands=("tr")) & ~filters.edited)
  175. async def tr(_, message: Message):
  176. lang = message.text.replace("/tr", "")
  177. flang = lang.replace(" ", "")
  178. if message.reply_to_message and flang != "":
  179. text = message.reply_to_message.text
  180. i = Translator().translate(text, dest=flang)
  181. await message.reply_text(i.text)
  182. else:
  183. await message.reply_text("Reply to a message with /tr [language code]"
  184. + "\nGet supported language list from here -"
  185. + " https://py-googletrans.readthedocs.io/en"
  186. + "/latest/#googletrans-languages")