Compare commits

...

4 commits

6 changed files with 57 additions and 3 deletions

View file

@ -33,5 +33,5 @@ labels:
**Did someone already report that bug?** **Did someone already report that bug?**
- [ ] Yes <!-- If you have to put yes you don't need to submit that feature request. --> - [ ] Yes <!-- If you have to put yes you don't need to submit that bug report. -->
- [ ] No - [ ] No

3
.gitignore vendored
View file

@ -1,7 +1,8 @@
.env .env
node_modules/ node_modules/
bin/
config/config.json config/config.json
json/board/ json/board/
unloaded/ unloaded/
database.sqlite3 database.sqlite3
bin/yt-dlp
tmp/*.js

0
bin/.keep Normal file
View file

View file

@ -0,0 +1,30 @@
import { SlashCommandBuilder } from 'discord.js';
import util from 'node:util';
import stream from 'node:stream';
import fs from 'node:fs';
export default {
data: new SlashCommandBuilder()
.setName('downloadandload')
.setDescription('Download a command and load it.')
.addAttachmentOption(option =>
option.setName('file')
.setDescription('The .js file that will be loaded by the bot.')
.setRequired(true)),
category: 'owner',
ownerOnly: true,
async execute(interaction, args, client) {
await interaction.deferReply();
const streamPipeline = util.promisify(stream.pipeline);
const res = await fetch(args.file.url);
if (!res.ok) return interaction.editReply('An error has occured while trying to download your image.');
await streamPipeline(res.body, fs.createWriteStream(`./tmp/${args.file.name}`));
let command = await import(`../../tmp/${args.file.name}`);
command = command.default;
client.commands.set(command.data.name, command);
return await interaction.editReply(`${command.data.name} has been loaded.`);
},
};

0
tmp/.keep Normal file
View file

View file

@ -9,6 +9,7 @@ export default {
stringIsAValidurl, stringIsAValidurl,
compressVideo, compressVideo,
getVideoCodec, getVideoCodec,
getMaxFileSize,
}; };
async function downloadVideo(urlArg, output, format = 'bestvideo*+bestaudio/best') { async function downloadVideo(urlArg, output, format = 'bestvideo*+bestaudio/best') {
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
@ -91,3 +92,25 @@ async function getVideoCodec(input) {
}); });
}); });
} }
async function getMaxFileSize(guild) {
return await new Promise((resolve, reject) => {
const tier = guild.premiumTier;
console.log(tier);
switch (tier) {
case 0:
case 1:
resolve(8);
break;
case 2:
resolve('50');
break;
case 3:
resolve('100');
break;
default:
reject('An error has occured');
break;
}
});
}