From e045235817004a1ed7b56887f054c354682a77dd Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sun, 19 Apr 2020 13:51:37 -0700 Subject: [PATCH] Clean up shooter --- .../discord-bot/commands/archive.js | 84 ++++++++++--------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/experiments/skin-database/discord-bot/commands/archive.js b/experiments/skin-database/discord-bot/commands/archive.js index d18e7a31..c9261bd4 100644 --- a/experiments/skin-database/discord-bot/commands/archive.js +++ b/experiments/skin-database/discord-bot/commands/archive.js @@ -35,50 +35,58 @@ async function handler(message) { // Construct IA Webamp URL const shooter = new Shooter("https://webamp.org"); - for (const file of files) { - const skin = await Skins.getSkinByMd5(file.md5); - if (skin != null) { - await message.channel.send(`This skin is already in our collection.`); - await Utils.postSkin({ - md5: file.md5, - dest: message.channel, - }); - } else { - await message.channel.send( - `Thanks! ${file.filename} is a brand new skin. 👏 Uploading to our server and taking a screenshot...` - ); - const tempFile = temp.path({ suffix: ".wsz" }); - fs.writeFileSync(tempFile, file.buffer); - const tempScreenshotPath = temp.path({ suffix: ".png" }); - - try { - await shooter.takeScreenshot(tempFile, tempScreenshotPath, { - minify: true, + try { + for (const file of files) { + const skin = await Skins.getSkinByMd5(file.md5); + if (skin != null) { + await message.channel.send(`This skin is already in our collection.`); + await Utils.postSkin({ + md5: file.md5, + dest: message.channel, }); - } catch (e) { - console.error(e); + } else { await message.channel.send( - `Something went wrong taking the screenshot of ${file.filename}. Sorry.` + `Thanks! ${file.filename} is a brand new skin. 👏 Uploading to our server and taking a screenshot...` ); - continue; - } + const tempFile = temp.path({ suffix: ".wsz" }); + fs.writeFileSync(tempFile, file.buffer); + const tempScreenshotPath = temp.path({ suffix: ".png" }); - await S3.putScreenshot(file.md5, fs.readFileSync(tempScreenshotPath)); - await S3.putSkin(file.md5, file.buffer); - await Skins.addSkin({ - md5: file.md5, - filePath: file.filename, - uploader: message.author.username, - }); - await message.channel.send( - `Done! ${file.filename} has been queued for archiving. In the mean time, here's a screenshot and a link to it on Webamp.` - ); - await Utils.postSkin({ - md5: file.md5, - dest: message.channel, - }); + try { + await shooter.takeScreenshot(tempFile, tempScreenshotPath, { + minify: true, + }); + } catch (e) { + console.error(e); + await message.channel.send( + `Something went wrong taking the screenshot of ${file.filename}. Sorry.` + ); + continue; + } + + await S3.putScreenshot(file.md5, fs.readFileSync(tempScreenshotPath)); + await S3.putSkin(file.md5, file.buffer); + await Skins.addSkin({ + md5: file.md5, + filePath: file.filename, + uploader: message.author.username, + }); + await message.channel.send( + `Done! ${file.filename} has been queued for archiving. In the mean time, here's a screenshot and a link to it on Webamp.` + ); + await Utils.postSkin({ + md5: file.md5, + dest: message.channel, + }); + } } + } catch (e) { + console.error(e); + message.channel.send( + "There was an error archiving your skin. Please ping @captbaritone." + ); } + shooter.dispose(); } module.exports = {