add expermental selenium_test, add screenshot and fix some commands.
This commit is contained in:
parent
8f4656c5ae
commit
e12be86164
120
bot.py
120
bot.py
|
@ -18,6 +18,8 @@ from PyDictionary import PyDictionary
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from google_images_search import GoogleImagesSearch
|
from google_images_search import GoogleImagesSearch
|
||||||
from translate import Translator
|
from translate import Translator
|
||||||
|
from selenium import webdriver
|
||||||
|
from selenium.webdriver.chrome.options import Options
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
TOKEN = ('????????????????????????????????????????????????')
|
TOKEN = ('????????????????????????????????????????????????')
|
||||||
|
@ -2145,12 +2147,12 @@ async def archivelookup(ctx, msgid):
|
||||||
@bot.command()
|
@bot.command()
|
||||||
async def filepreview(ctx, *, text):
|
async def filepreview(ctx, *, text):
|
||||||
# Download the image
|
# Download the image
|
||||||
url = ctx.message.attachments[0].url
|
|
||||||
filename = ctx.message.attachments[0].filename
|
|
||||||
filetype = ctx.message.attachments[0].content_type
|
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)
|
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)
|
shutil.copyfileobj(r.raw, out_file)
|
||||||
del r
|
del r
|
||||||
# run checks
|
# run checks
|
||||||
|
@ -2158,14 +2160,115 @@ async def filepreview(ctx, *, text):
|
||||||
await ctx.send(f"Error: Unsupported file type `{filetype}`")
|
await ctx.send(f"Error: Unsupported file type `{filetype}`")
|
||||||
return
|
return
|
||||||
# send feedback
|
# send feedback
|
||||||
await ctx.send(f"<a:load:769818027956895744> Processing... This might take a while", delete_after(5))
|
await ctx.send(f"<a:load:769818027956895744> Processing... This might take a while")
|
||||||
# process the image
|
# 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"))
|
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"<a:load:769818027956895744> 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"<a:load:769818027956895744> 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"<a:load:769818027956895744> 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} <a:load:769818027956895744>")
|
||||||
|
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:
|
if number == None:
|
||||||
z = int(idd)
|
z = int(idd)
|
||||||
|
@ -2177,9 +2280,8 @@ async def filepreview(ctx, *, text):
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
await ctx.voice_client.disconnect()
|
await ctx.voice_client.disconnect()
|
||||||
except Exception as x:
|
except Exception as x:
|
||||||
print(x)
|
await ctx.send(f"<:error:871854416238612520> `{x}`")
|
||||||
exc = (":boom: **Error**```{0}```").format(x)
|
|
||||||
await ctx.channel.send(exc)
|
|
||||||
else:
|
else:
|
||||||
z = int(idd)
|
z = int(idd)
|
||||||
channel = bot.get_channel(z)
|
channel = bot.get_channel(z)
|
||||||
|
|
|
@ -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()
|
Loading…
Reference in New Issue