From e12be86164c749f0f7a9ce6f14c92a9e44814e0b Mon Sep 17 00:00:00 2001 From: Soso Playz Date: Mon, 9 Aug 2021 15:14:24 +0300 Subject: [PATCH] add expermental selenium_test, add screenshot and fix some commands. --- bot.py | 120 +++++++++++++++++++++++++++++++--- experimental/selenium_test.py | 21 ++++++ 2 files changed, 132 insertions(+), 9 deletions(-) create mode 100644 experimental/selenium_test.py diff --git a/bot.py b/bot.py index 04f68be..76d8508 100644 --- a/bot.py +++ b/bot.py @@ -18,6 +18,8 @@ from PyDictionary import PyDictionary from discord.ext import commands from google_images_search import GoogleImagesSearch from translate import Translator +from selenium import webdriver +from selenium.webdriver.chrome.options import Options # Configuration TOKEN = ('????????????????????????????????????????????????') @@ -2145,12 +2147,12 @@ async def archivelookup(ctx, msgid): @bot.command() async def filepreview(ctx, *, text): # Download the image - url = ctx.message.attachments[0].url - filename = ctx.message.attachments[0].filename filetype = ctx.message.attachments[0].content_type - headers = defaultheader + url = (""'{}'"").format(ctx.message.attachments[0].url) + filename = (""'{}'"").format(ctx.message.attachments[0].filename) + headers = {'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0'} r = requests.get(url, headers=headers, stream=True) - with open(filename, 'wb') as out_file: + with open(f"ytdl/{filename}", 'wb') as out_file: shutil.copyfileobj(r.raw, out_file) del r # run checks @@ -2158,14 +2160,115 @@ async def filepreview(ctx, *, text): await ctx.send(f"Error: Unsupported file type `{filetype}`") return # send feedback - await ctx.send(f" Processing... This might take a while", delete_after(5)) + await ctx.send(f" Processing... This might take a while") # process the image - os.system(f'convert 1.jpg -thumbnail 120x120 -bordercolor Lavender -background gray40 -gravity center -set caption "{text}" -polaroid 10 file_gen.png') + os.system(f'convert ytdl/{filename} -thumbnail 120x120 -bordercolor Lavender -background gray40 -gravity center -set caption "{text}" -polaroid 10 ytdl/file_gen.png') await ctx.channel.send(f"{ctx.author.mention}", file=discord.File("file_gen.png")) + os.system(f'rm ytdl/{filename}') + os.system(f'rm ytdl/file_gen.png') +@bot.command() +async def encryptimg(ctx, password): + # Download the image + filetype = ctx.message.attachments[0].content_type + url = (""'{}'"").format(ctx.message.attachments[0].url) + filename = (""'{}'"").format(ctx.message.attachments[0].filename) + headers = {'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0'} + r = requests.get(url, headers=headers, stream=True) + with open(f"ytdl/{filename}", 'wb') as out_file: + shutil.copyfileobj(r.raw, out_file) + del r + # run checks + if "image" not in filetype: + await ctx.send(f"Error: Unsupported file type `{filetype}`") + return + # send feedback + await ctx.send(f" Encrypting image {filename}...") + # process the image + os.system(f'echo "{password}" | convert ytdl/{filename} -encipher - -transpose -depth 8 png24:message_obfuscate.png') + # send it and delete old files + await ctx.channel.send(f"{ctx.author.mention} Encrypted image", file=discord.File("message_obfuscate.png")) + os.system(f'rm ytdl/{filename}') + os.system(f'rm message_obfuscate.png') + +@bot.command() +async def decryptimg(ctx, password): + # Download the image + filetype = ctx.message.attachments[0].content_type + url = (""'{}'"").format(ctx.message.attachments[0].url) + filename = (""'{}'"").format(ctx.message.attachments[0].filename) + headers = {'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0'} + r = requests.get(url, headers=headers, stream=True) + with open(f"{filename}", 'wb') as out_file: + shutil.copyfileobj(r.raw, out_file) + del r + # run checks + if "image" not in filetype: + await ctx.send(f"Error: Unsupported file type `{filetype}`") + return + # send feedback + await ctx.send(f" Decrypting image {filename}...") + # process the image + os.system(f'echo "{password}" | convert {filename} -transpose -decipher - message_restored_2.png') + # send it and delete old files + await ctx.channel.send(f"{ctx.author.mention} Decrypted image", file=discord.File("message_restored_2.png")) + os.system(f'rm ytdl/{filename}') + os.system(f'rm message_restored_2.png') +@bot.command() +async def dumpy(ctx, lines : int = 10): + try: + # Download the image + if lines > 30: + await ctx.send(f"YOU'RE GONNA CRASH THE BOT (Use a value less than 30, You would have to subtract `{(int - 30)}` from your original value of `{lines}`)") + return + filetype = ctx.message.attachments[0].content_type + url = (""'{}'"").format(ctx.message.attachments[0].url) + filename = (""'{}'"").format(ctx.message.attachments[0].filename) + headers = {'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0'} + r = requests.get(url, headers=headers, stream=True) + with open(f"ytdl/{filename}", 'wb') as out_file: + shutil.copyfileobj(r.raw, out_file) + del r + # run checks + if "image" not in filetype: + await ctx.send(f"Error: Unsupported file type `{filetype}`") + return + # send feedback + await ctx.send(f" Processing...") + # process the image + os.system(f'java -jar resources/dumpy.jar --lines {lines} --file ytdl/{filename}') + await ctx.channel.send(f"{ctx.author.mention}", file=discord.File("dumpy.gif")) + os.system(f'rm ytdl/{filename}') + os.system(f'rm dumpy.gif') + except Exception as x: + await ctx.send(f"<:error:871854416238612520> `{x}`") + + +@bot.command() +async def screenshot(ctx, url): + msg = await ctx.send(f"Processing request for {url} ") + try: + mobile_emulation = { + "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 }, + "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19"} + chrome_options = Options() + chrome_options.add_argument("--headless") + chrome_options.add_argument("--disable-gpu") + + chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) + + driver = webdriver.Chrome(chrome_options = chrome_options) + + driver.get(url) + driver.save_screenshot("ytdl/screenshot.png") + driver.quit() + except Exception as x: + await ctx.channel.send(f"error...\n`{x}`") + msg.delete() + await ctx.channel.send(f"{ctx.author.mention}", file=discord.File("ytdl/screenshot.png")) """ if number == None: z = int(idd) @@ -2177,9 +2280,8 @@ async def filepreview(ctx, *, text): await asyncio.sleep(1) await ctx.voice_client.disconnect() except Exception as x: - print(x) - exc = (":boom: **Error**```{0}```").format(x) - await ctx.channel.send(exc) + await ctx.send(f"<:error:871854416238612520> `{x}`") + else: z = int(idd) channel = bot.get_channel(z) diff --git a/experimental/selenium_test.py b/experimental/selenium_test.py new file mode 100644 index 0000000..996b1c1 --- /dev/null +++ b/experimental/selenium_test.py @@ -0,0 +1,21 @@ +from selenium import webdriver + +from selenium.webdriver.chrome.options import Options + +mobile_emulation = { + + "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 }, + + "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" } + +chrome_options = Options() +chrome_options.add_argument("--headless") +chrome_options.add_argument("--disable-gpu") + +chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) + +driver = webdriver.Chrome(chrome_options = chrome_options) + +driver.get('https://nhentai.net') +driver.save_screenshot("screenshot.png") +driver.quit()