forked from Supositware/Haha-Yes
Removed useless logging and updated image fetch
This commit is contained in:
parent
b960829e72
commit
bd7f0d12e5
1 changed files with 27 additions and 28 deletions
|
@ -4,6 +4,8 @@ import Twit from 'twit';
|
|||
import fetch from 'node-fetch';
|
||||
import os from 'node:os';
|
||||
import fs from 'node:fs';
|
||||
import util from 'node:util';
|
||||
import stream from 'node:stream';
|
||||
|
||||
import db from '../../models/index.js';
|
||||
import wordToCensor from '../../json/censor.json' assert {type: 'json'};
|
||||
|
@ -29,8 +31,7 @@ export default {
|
|||
async execute(interaction, args, client) {
|
||||
const content = args.content;
|
||||
const attachment = args.image;
|
||||
console.log(args);
|
||||
console.log(attachment);
|
||||
|
||||
if (!content && !attachment) {
|
||||
return interaction.reply({ content: 'Uh oh! You are missing any content for me to tweet!', ephemeral: true });
|
||||
}
|
||||
|
@ -91,11 +92,11 @@ export default {
|
|||
// Make sure there is an attachment and if its an image
|
||||
if (attachment) {
|
||||
if (attachment.name.toLowerCase().endsWith('.jpg') || attachment.name.toLowerCase().endsWith('.png') || attachment.name.toLowerCase().endsWith('.gif')) {
|
||||
fetch(attachment.url)
|
||||
.then(res => {
|
||||
const dest = fs.createWriteStream(`${os.tmpdir()}/${attachment.name}`);
|
||||
res.body.pipe(dest);
|
||||
dest.on('finish', () => {
|
||||
const streamPipeline = util.promisify(stream.pipeline);
|
||||
const res = await fetch(attachment.url);
|
||||
if (!res.ok) return interaction.editReply('An error has occured while trying to download your image.');
|
||||
await streamPipeline(res.body, fs.createWriteStream(`${os.tmpdir()}/${attachment.name}`));
|
||||
|
||||
const file = fs.statSync(`${os.tmpdir()}/${attachment.name}`);
|
||||
const fileSize = file.size / 1000000.0;
|
||||
|
||||
|
@ -117,8 +118,6 @@ export default {
|
|||
Tweet(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
await interaction.editReply({ content: 'File type not supported, you can only send jpg/png/gif' });
|
||||
|
|
Loading…
Reference in a new issue