Compare commits

..

No commits in common. "50b55edae355f06d3d45f452cba8260b428ae423" and "62666e2a3f8eeddb954e305b9a5f9e39a4863a30" have entirely different histories.

2 changed files with 7 additions and 24 deletions

View file

@ -1,5 +1,3 @@
// TODO
// Switch to 'twitter-api-v2'
import { SlashCommandBuilder } from 'discord.js'; import { SlashCommandBuilder } from 'discord.js';
import Twit from 'twit'; import Twit from 'twit';

View file

@ -19,10 +19,6 @@ export default {
option.setName('quality') option.setName('quality')
.setDescription('Quality of the gif conversion. Default 70. Number between 1 and 100') .setDescription('Quality of the gif conversion. Default 70. Number between 1 and 100')
.setRequired(false)) .setRequired(false))
.addIntegerOption(option =>
option.setName('fps')
.setDescription('Change the speed at which the gif play at. Default 20. Number between 1 and 100.')
.setRequired(false))
.addBooleanOption(option => .addBooleanOption(option =>
option.setName('noloop') option.setName('noloop')
.setDescription('Stop the gif from looping') .setDescription('Stop the gif from looping')
@ -36,22 +32,11 @@ export default {
const maxFileSize = await utils.getMaxFileSize(interaction.guild); const maxFileSize = await utils.getMaxFileSize(interaction.guild);
const url = args.url; const url = args.url;
let quality = args.quality; let quality = args.quality;
if (quality) { if (quality <= 0) {
if (quality <= 0) { quality = 1;
quality = 1;
}
else if (quality > 100) {
quality = 100;
}
} }
else if (quality > 100) {
if (args.fps) { quality = 100;
if (args.fps <= 0) {
args.fps = 1;
}
else if (args.fps > 100) {
args.fps = 100;
}
} }
if (!await utils.stringIsAValidurl(url)) { if (!await utils.stringIsAValidurl(url)) {
@ -69,7 +54,7 @@ export default {
// Extract every frame for gifski // Extract every frame for gifski
await utils.ffmpeg(['-i', output, `${os.tmpdir()}/frame${interaction.id}%04d.png`]); await utils.ffmpeg(['-i', output, `${os.tmpdir()}/frame${interaction.id}%04d.png`]);
// Make it look better // Make it look better
await gifski(gifskiOutput, `${os.tmpdir()}/frame${interaction.id}*`, quality, args.fps); await gifski(gifskiOutput, `${os.tmpdir()}/frame${interaction.id}*`, quality);
// Optimize it // Optimize it
await gifsicle(gifskiOutput, gifsicleOutput, args.noloop); await gifsicle(gifskiOutput, gifsicleOutput, args.noloop);
@ -94,10 +79,10 @@ export default {
}, },
}; };
async function gifski(output, input, quality, fps) { async function gifski(output, input, quality) {
return await new Promise((resolve, reject) => { return await new Promise((resolve, reject) => {
// Shell: true should be fine as no user input is being passed // Shell: true should be fine as no user input is being passed
execFile('gifski', ['--quality', quality ? quality : 70, '--fps', fps ? fps : 20, '-o', output, input], { shell: true }, (err, stdout, stderr) => { execFile('gifski', ['--quality', quality ? quality : 70, '-o', output, input], { shell: true }, (err, stdout, stderr) => {
if (err) { if (err) {
reject(stderr); reject(stderr);
} }