Compare commits

..

No commits in common. "08b52216a959739f7d1e1e5c9c6e4cf83cfac02e" and "f55b54eb49397c395ea6584f245ced25249601fb" have entirely different histories.

3 changed files with 33 additions and 19 deletions

View file

@ -1,7 +1,7 @@
const { execFileSync } = require('child_process');
const path = require('path'); const path = require('path');
const fs = require('fs') const fs = require('fs')
const executeCommand = require('../../util/executeCommand');
module.exports = { module.exports = {
name: 'dl', name: 'dl',
description: 'Download a video', description: 'Download a video',
@ -38,7 +38,7 @@ module.exports = {
const originalMessage = await message.channel.send("Downloading video...") const originalMessage = await message.channel.send("Downloading video...")
if(executeCommand("yt-dlp", [url, "-P", downloadsDir, "--cookies", cookieFilepath]).error){ if(this.executeCommand("yt-dlp", [url, "-P", downloadsDir, "--cookies", cookieFilepath]).error){
originalMessage.edit("An error occurred when downloading the video."); originalMessage.edit("An error occurred when downloading the video.");
this.cleanUp(downloadsDir); this.cleanUp(downloadsDir);
return; return;
@ -68,4 +68,18 @@ module.exports = {
fs.rmSync(downloadsDir, {force: true, recursive: true}); fs.rmSync(downloadsDir, {force: true, recursive: true});
}, },
executeCommand(command, commandArgs, verbose=false) {
if (typeof command !== 'string' || !Array.isArray(commandArgs)) return { error: true };
console.log("Executing:", command, commandArgs.join(" "));
try {
const output = execFileSync(command, commandArgs, {encoding: 'utf8'})
if (output.length != 0 && verbose)
console.log(output)
} catch (error) {
console.error(`Error executing ${command} command:`, error);
return { error: true };
}
return { error: false };
},
} }

View file

@ -3,7 +3,7 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const { writeFile } = require('node:fs/promises') const { writeFile } = require('node:fs/promises')
const { Readable } = require('node:stream') const { Readable } = require('node:stream')
const executeCommand = require('../../util/executeCommand');
module.exports = { module.exports = {
name: 'tdoss', name: 'tdoss',
@ -60,8 +60,8 @@ module.exports = {
} }
const commandArgs = [tdossTemplate, "(", `${directory}/input.png`, "-resize", "800x800^", "-gravity", "center", "-extent", "1000x1000", ")", "-compose", "dst-over", "-composite", `${directory}/tdoss_result.png`] const command = `magick ${tdossTemplate} \\( ${directory}/input.png -resize 800x800^ -gravity center -extent 1000x1000 \\) -compose dst-over -composite ${directory}/tdoss_result.png`;
if (executeCommand("magick", commandArgs).error === true) { if (this.executeCommand(command).error === true) {
message.channel.send("Something went wrong during image manipulation.\nTry again and if it keeps happening, contact the owner of the bot.") message.channel.send("Something went wrong during image manipulation.\nTry again and if it keeps happening, contact the owner of the bot.")
fs.rmSync(`${directory}`, {recursive: true}) fs.rmSync(`${directory}`, {recursive: true})
return return
@ -75,6 +75,20 @@ module.exports = {
await message.channel.send({files: [final_image]}) await message.channel.send({files: [final_image]})
fs.rmSync(`${directory}`, {recursive: true}) fs.rmSync(`${directory}`, {recursive: true})
}, },
executeCommand(command) {
console.log("Executing:", command)
try {
const output = execSync(command, { encoding: 'utf-8' })
if (output.length != 0)
console.log(output)
} catch (error) {
console.error(`Error executing ${command.split(" ")[0]} command:`, error);
return { error: true };
}
return { error: false };
},
// https://stackoverflow.com/a/77210219 // https://stackoverflow.com/a/77210219
async downloadImage(url, path) { async downloadImage(url, path) {
let res; let res;

View file

@ -1,14 +0,0 @@
const { execFileSync } = require('child_process');
module.exports = function(command, commandArgs, verbose=false) {
if (typeof command !== 'string' || !Array.isArray(commandArgs)) return { error: true };
console.log("Executing:", command, commandArgs.join(" "));
try {
const output = execFileSync(command, commandArgs, {encoding: 'utf8'})
if (output.length !== 0 && verbose)
console.log(output)
} catch (error) {
console.error(`Error executing ${command} command:`, error);
return { error: true };
}
return { error: false };
}