mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-29 04:50:14 +00:00
Clean up shooter
This commit is contained in:
parent
b73b44bfd9
commit
e045235817
1 changed files with 46 additions and 38 deletions
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue