Convert to ES6
This commit is contained in:
parent
53624abff0
commit
1d4c7feb56
7 changed files with 48 additions and 49 deletions
|
@ -7,6 +7,7 @@
|
|||
"parserOptions": {
|
||||
"ecmaVersion": 2021
|
||||
},
|
||||
"sourceType": "module",
|
||||
"rules": {
|
||||
"arrow-spacing": ["warn", { "before": true, "after": true }],
|
||||
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { MessageEmbed, MessageActionRow, MessageSelectMenu } = require('discord.js');
|
||||
const { exec } = require('node:child_process');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
import { MessageEmbed, MessageActionRow, MessageSelectMenu } from 'discord.js';
|
||||
import { exec } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import utils from '../utils/videos.js';
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('download')
|
||||
.setDescription('Download a video.')
|
||||
|
@ -99,7 +100,7 @@ async function download(url, interaction) {
|
|||
if (interaction.values[1]) format += '+' + interaction.values[1];
|
||||
}
|
||||
|
||||
downloadVideo(url, interaction.id, format)
|
||||
utils.downloadVideo(url, interaction.id, format)
|
||||
.then(async () => {
|
||||
const file = fs.readdirSync(os.tmpdir()).filter(fn => fn.startsWith(interaction.id));
|
||||
const output = `${os.tmpdir()}/${file}`;
|
||||
|
@ -112,7 +113,7 @@ async function download(url, interaction) {
|
|||
await interaction.followUp('Uh oh! The video you tried to download is too big!', { ephemeral: true });
|
||||
}
|
||||
else if (fileSize > 8) {
|
||||
const fileURL = await upload(output)
|
||||
const fileURL = await utils.upload(output)
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
|
@ -130,31 +131,3 @@ async function download(url, interaction) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
|
||||
async function downloadVideo(url, output, format) {
|
||||
await new Promise((resolve, reject) => {
|
||||
exec(`./bin/yt-dlp -f ${format} ${url} -o "${os.tmpdir()}/${output}.%(ext)s" --force-overwrites`, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
reject(stderr);
|
||||
}
|
||||
if (stderr) {
|
||||
console.error(stderr);
|
||||
}
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function upload(file) {
|
||||
return await new Promise((resolve, reject) => {
|
||||
exec(`./bin/upload.sh ${file}`, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
reject(stderr);
|
||||
}
|
||||
if (stderr) {
|
||||
console.error(stderr);
|
||||
}
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Replies with Pong!'),
|
||||
|
|
|
@ -20,6 +20,23 @@ const commands = [
|
|||
option.setName('advanced')
|
||||
.setDescription('Choose the quality of the video.')
|
||||
.setRequired(false)),
|
||||
|
||||
|
||||
new SlashCommandBuilder()
|
||||
.setName('reddit')
|
||||
.setDescription('Send random images from the subreddit you choose')
|
||||
.addStringOption(option =>
|
||||
option.setName('subreddit')
|
||||
.setDescription('The subreddit you wish to see')
|
||||
.setRequired(true)),
|
||||
|
||||
new SlashCommandBuilder()
|
||||
.setName('vid2gif')
|
||||
.setDescription('Convert your video into a gif.')
|
||||
.addStringOption(option =>
|
||||
option.setName('url')
|
||||
.setDescription('URL of the video you want to convert')
|
||||
.setRequired(true)),
|
||||
]
|
||||
.map(command => command.toJSON());
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = {
|
||||
export default {
|
||||
name: 'interactionCreate',
|
||||
async execute(interaction) {
|
||||
const client = interaction.client;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
const { exec } = require('node:child_process');
|
||||
const https = require('node:https');
|
||||
require('dotenv').config();
|
||||
import { exec } from 'node:child_process';
|
||||
import https from 'node:https';
|
||||
import dotenv from 'dotenv'
|
||||
dotenv.config();
|
||||
const { uptimeURL, uptimeInterval } = process.env;
|
||||
|
||||
module.exports = {
|
||||
export default {
|
||||
name: 'ready',
|
||||
once: true,
|
||||
async execute(client) {
|
||||
|
|
19
index.js
19
index.js
|
@ -1,9 +1,14 @@
|
|||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { Client, Collection, Intents } = require('discord.js');
|
||||
require('dotenv').config();
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { Client, Collection, Intents } from 'discord.js';
|
||||
import dotenv from 'dotenv'
|
||||
dotenv.config()
|
||||
const { token } = process.env;
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
||||
|
||||
// Load commands from the commands folder
|
||||
|
@ -13,7 +18,8 @@ const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('
|
|||
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join(commandsPath, file);
|
||||
const command = require(filePath);
|
||||
let command = await import(filePath);
|
||||
command = command.default;
|
||||
|
||||
client.commands.set(command.data.name, command);
|
||||
}
|
||||
|
@ -24,7 +30,8 @@ const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'
|
|||
|
||||
for (const file of eventFiles) {
|
||||
const filePath = path.join(eventsPath, file);
|
||||
const event = require(filePath);
|
||||
let event = await import(filePath);
|
||||
event = event.default;
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue