Kaynağa Gözat

Inkripsan (#25)

Added /encrypt , /decrypt and /wiki
TheHamkerCat 5 yıl önce
ebeveyn
işleme
3f06cec16d

+ 3 - 0
commands.txt

@@ -4,9 +4,11 @@ ban - Ban A User
 banme - Ban Yourself
 cat - Get Cute Cats Images
 commit - Generate Funny Commit Messages
+decrypt - Decrypt Text
 del - Delete Replied Message
 dev - Forward Anything To Developers [SPAM = GBAN]
 dog - Get Cute Dogs Images
+encrypt - Encrypt Text
 google - Search For Something On Google
 gh - Search For Something On Github
 help - Help Yourself!
@@ -35,3 +37,4 @@ ud - Search For Something In Urban Dictionary
 unban - Unban A User
 unpin - Unpin The Last Pinned Message.
 wall - Get Wallpapers
+wiki - Search For Something On Wikipedia

+ 1 - 0
requirements.txt

@@ -8,3 +8,4 @@ speedtest-cli
 uvloop
 youtube_dl
 search_engine_parser
+wikipedia

+ 1 - 0
sample_config.ini

@@ -8,6 +8,7 @@ owner_id = 1243703097
 sudo_user_id = 79813487
 neofetch = True
 alpha_coders_wall_api_key = ca45r8c444s55g7t5s3a4esd33hs6t
+fernet_encryption_key = # Follow this tutorial to generate a key https://cryptography.io/en/latest/fernet.html
 
 [prefix]
 prefixes = /

+ 1 - 0
wbb/__init__.py

@@ -34,6 +34,7 @@ OWNER_ID = int(config.get("admin", "owner_id"))
 SUDO_USER_ID = int(config.get("admin", "sudo_user_id"))
 NEOFETCH = (config.get("admin", "neofetch"))
 WALL_API_KEY = (config.get("admin", "alpha_coders_wall_api_key"))
+FERNET_ENCRYPTION_KEY = (config.get("admin", "fernet_encryption_key"))
 Command = config.get("prefix", "prefixes").split()
 MOD_LOAD = config.get("mods", "load_modules").split()
 MOD_NOLOAD = config.get("mods", "noload_modules").split()

+ 2 - 2
wbb/modules/images.py

@@ -1,12 +1,12 @@
 import urllib.request
 import json
-from random import randint
 import asyncio
+from random import randint
 import requests as r
+from pyrogram import filters
 from pyrogram.types import Message
 from wbb.utils import cust_filter
 from wbb import app, WALL_API_KEY
-from pyrogram import filters
 
 __MODULE__ = "Images"
 __HELP__ = '''/cat  - Get Cute Cats Images

+ 39 - 5
wbb/modules/misc.py

@@ -1,11 +1,11 @@
 import secrets
 import string
-from wbb.utils.botinfo import BOT_ID
+from pyrogram import filters
 from pyrogram.types import Message
-from wbb import app
+from cryptography.fernet import Fernet
+from wbb.utils.botinfo import BOT_ID
+from wbb import app, FERNET_ENCRYPTION_KEY
 from wbb.utils import cust_filter, random_line
-from pyrogram import filters
-
 
 __MODULE__ = "Misc"
 __HELP__ = '''/commit - Generate Funny Commit Messages
@@ -14,7 +14,9 @@ __HELP__ = '''/commit - Generate Funny Commit Messages
 /id - Get Chat_ID or User_ID
 /dev - Forward Anything To Developers [SPAM = GBAN]
 /random - Generate Random Complex Passwords
-/http - Get Cats Reference Photo For Http Error Codes'''
+/http - Get Cats Reference Photo For Http Error Codes
+/encrypt - Encrypt Text [Can Only Be Decrypted By This Bot]
+/decrypt - Decrypt Text'''
 
 
 @app.on_message(cust_filter.command(commands=("commit")) & ~filters.edited)
@@ -110,3 +112,35 @@ async def http(_, message: Message):
         await message.reply_photo(final)
     else:
         await message.reply_text('"/http" Needs An Argument. Ex: `/http 404`')
+
+
+# Encrypt
+
+
+@app.on_message(cust_filter.command(commands=('encrypt')) & ~filters.edited)
+async def encrypt(_, message: Message):
+    app.set_parse_mode('markdown')
+    if not message.reply_to_message:
+        await message.reply_text('Reply To A Message To Encrypt It.')
+    else:
+        text = message.reply_to_message.text
+        text_in_bytes = bytes(text, 'utf-8')
+        cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
+        encrypted_text = cipher_suite.encrypt(text_in_bytes)
+        bytes_in_text = encrypted_text.decode("utf-8")
+        await message.reply_text(bytes_in_text)
+
+# Decrypt
+
+
+@app.on_message(cust_filter.command(commands=('decrypt')) & ~filters.edited)
+async def decrypt(_, message: Message):
+    if not message.reply_to_message:
+        await message.reply_text('Reply To A Message To Decrypt It.')
+    else:
+        text = message.reply_to_message.text
+        text_in_bytes = bytes(text, 'utf-8')
+        cipher_suite = Fernet(FERNET_ENCRYPTION_KEY)
+        decoded_text = cipher_suite.decrypt(text_in_bytes)
+        bytes_in_text = decoded_text.decode("utf-8")
+        await message.reply_text(bytes_in_text)

+ 1 - 1
wbb/modules/music.py

@@ -2,10 +2,10 @@ from __future__ import unicode_literals
 from urllib.parse import urlparse
 import os
 import youtube_dl
+from pyrogram import filters
 from pyrogram.types import Message
 from wbb.utils import cust_filter
 from wbb import app
-from pyrogram import filters
 
 __MODULE__ = "Music"
 __HELP__ = "/music [link] To Download Music From Various Websites"

+ 1 - 1
wbb/modules/paste.py

@@ -1,8 +1,8 @@
 import os
+from pyrogram import filters
 from pyrogram.types import Message
 from wbb.utils import cust_filter, nekobin
 from wbb import app
-from pyrogram import filters
 
 __MODULE__ = "Paste"
 __HELP__ = "/paste - To Paste Replied Text Or Document To Neokobin"

+ 3 - 1
wbb/modules/ping.py

@@ -1,8 +1,10 @@
 import requests
+from pyrogram import filters
 from pyrogram.types import Message
 from wbb import app
 from wbb.utils import cust_filter
-from pyrogram import filters
+
+
 __MODULE__ = "Ping"
 __HELP__ = " /ping - To Get Response Time From All TG Datacenters"
 

+ 1 - 1
wbb/modules/repo.py

@@ -1,7 +1,7 @@
+from pyrogram import filters
 from pyrogram.types import Message
 from wbb import app
 from wbb.utils import cust_filter
-from pyrogram import filters
 
 __MODULE__ = "Repo"
 __HELP__ = "/repo - To Get My Github Repository Link " \

+ 26 - 1
wbb/modules/search.py

@@ -1,3 +1,4 @@
+import wikipedia
 from search_engine_parser import GoogleSearch
 from pyrogram.types import Message
 from pyrogram import filters
@@ -9,7 +10,8 @@ __MODULE__ = "Search"
 __HELP__ = '''/ud - Search For Something In Urban Dictionary
 /google - Search For Something On google
 /so - Search For Something On StackOverflow
-/gh - Search For Something On Github'''
+/gh - Search For Something On Github
+/wiki - Search For Something On Wikipedia'''
 
 # ud -  urbandictionary
 
@@ -103,3 +105,26 @@ async def github(_, message: Message):
         await message.reply_text(result, disable_web_page_preview=True)
     else:
         await message.reply_text('"/gh" Needs An Argument')
+
+# Wikipedia
+
+
+@app.on_message(cust_filter.command(commands=("wiki")) & ~filters.edited)
+async def wiki(_, message: Message):
+    query = message.text.replace("/wiki", '')
+    limit = 5
+    if message.reply_to_message:
+        query = message.reply_to_message.text
+    if not query:
+        await message.reply_text('Reply To A Message Or Give An Argument')
+        return
+    wikipedia.set_lang("en")
+    results = wikipedia.search(query)
+    output = "```Found These Topics```"
+    for i, j in enumerate(results, start=1):
+        page = wikipedia.page(j)
+        url = page.url
+        output += f"[{j}]({url})\n"
+        if i == limit:
+            break
+    await message.reply_text(output, disable_web_page_preview=True)