From f20031b673f5f0d47dcf62a59ab842bb602b011b Mon Sep 17 00:00:00 2001 From: hgw Date: Mon, 2 Oct 2023 02:14:36 +0000 Subject: [PATCH] webp support + other fixes --- banter/banter.py | 23 +++++++++++++++-------- banter/requirements.txt | 3 ++- bot.js | 10 +++++++--- output.txt | 0 4 files changed, 24 insertions(+), 12 deletions(-) delete mode 100644 output.txt diff --git a/banter/banter.py b/banter/banter.py index ad238eb..0c77beb 100755 --- a/banter/banter.py +++ b/banter/banter.py @@ -11,25 +11,32 @@ import validators import wget import subprocess import glob, os +import requests def main(imgPath, delay, ASCIIWIDTH, COLORCHAR, FILLER, fileType): + if os.path.exists("image.png"): + os.remove("image.png") + if os.path.exists("image.jpg"): + os.remove("image.jpg") + if os.path.exists("image.webp"): + os.remove("image.webp") + if os.path.exists("output.txt"): + os.remove("output.txt") if validators.url(imgPath) == True: - for f in glob.glob("P*.png"): - os.remove(f) - for f in glob.glob("P*.jpg"): - os.remove(f) - if os.path.exists("output.txt"): - os.remove("output.txt") print('URL') print('Downloading image to ' + "/home/node/app/image." + fileType) - wget.download(imgPath, "/home/node/app/image." + fileType) - #subprocess.run(["wget", imgPath, "-o", "image." + fileType]) + #wget.download(imgPath, "/home/node/app/image." + fileType) + imagefile = requests.get(imgPath) + open("/home/node/app/image." + fileType, "wb").write(imagefile.content) if fileType == "png": print('PNG') imgPath = "/home/node/app/image.png" if fileType == "jpg": print('JPG') imgPath = "/home/node/app/image.jpg" + if fileType == "webp": + print('WEBP') + imgPath = "/home/node/app/image.webp" im = Image.open(imgPath, 'r') im = ImageOps.scale(im, ASCIIWIDTH / im.width) diff --git a/banter/requirements.txt b/banter/requirements.txt index 3244d02..10be2af 100644 --- a/banter/requirements.txt +++ b/banter/requirements.txt @@ -1,3 +1,4 @@ Pillow==8.0.1 validators==0.20.0 -wget==3.2 \ No newline at end of file +wget==3.2 +requests==2.22.0 \ No newline at end of file diff --git a/bot.js b/bot.js index b4fd568..bd757cc 100644 --- a/bot.js +++ b/bot.js @@ -9,7 +9,7 @@ var config = { //edit your shit here server: "irc.supernets.org", port: 6697, SSL: true, - channels: ['#fascinus'], + channels: ['#dev'], botName: "fascinus", userName: "fascinus", realName: "Sneed" @@ -107,11 +107,14 @@ async function rspam(chan, amt) { } async function art(chan, url) { + var ext = path.extname(url) if (ext === ".png") { var filetype = "png" } else if (ext === ".jpg") { var filetype = "jpg" + } else if (ext === ".webp") { + var filetype = "webp" } else { bot.say(chan, "Image must be PNG or JPG"); return @@ -122,7 +125,7 @@ async function art(chan, url) { pythonProcess.stdout.on('data', (data) => { console.log(data.toString()) }); - await timer(1000); + await timer(5000); fs.stat('output.txt', function(err, stat) { if (err == null) { console.log('File exists'); @@ -134,9 +137,10 @@ async function art(chan, url) { bot.say(chan, line); }); } else if (err.code === 'ENOENT') { + console.log(err); bot.say(chan, "Error") } else { - bot.say(chan, "Error") + bot.say(chan, "Other Error") } }); } diff --git a/output.txt b/output.txt deleted file mode 100644 index e69de29..0000000