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": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 2021
|
"ecmaVersion": 2021
|
||||||
},
|
},
|
||||||
|
"sourceType": "module",
|
||||||
"rules": {
|
"rules": {
|
||||||
"arrow-spacing": ["warn", { "before": true, "after": true }],
|
"arrow-spacing": ["warn", { "before": true, "after": true }],
|
||||||
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
|
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||||
const { MessageEmbed, MessageActionRow, MessageSelectMenu } = require('discord.js');
|
import { MessageEmbed, MessageActionRow, MessageSelectMenu } from 'discord.js';
|
||||||
const { exec } = require('node:child_process');
|
import { exec } from 'node:child_process';
|
||||||
const fs = require('node:fs');
|
import fs from 'node:fs';
|
||||||
const os = require('node:os');
|
import os from 'node:os';
|
||||||
|
import utils from '../utils/videos.js';
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('download')
|
.setName('download')
|
||||||
.setDescription('Download a video.')
|
.setDescription('Download a video.')
|
||||||
|
@ -99,7 +100,7 @@ async function download(url, interaction) {
|
||||||
if (interaction.values[1]) format += '+' + interaction.values[1];
|
if (interaction.values[1]) format += '+' + interaction.values[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadVideo(url, interaction.id, format)
|
utils.downloadVideo(url, interaction.id, format)
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
const file = fs.readdirSync(os.tmpdir()).filter(fn => fn.startsWith(interaction.id));
|
const file = fs.readdirSync(os.tmpdir()).filter(fn => fn.startsWith(interaction.id));
|
||||||
const output = `${os.tmpdir()}/${file}`;
|
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 });
|
await interaction.followUp('Uh oh! The video you tried to download is too big!', { ephemeral: true });
|
||||||
}
|
}
|
||||||
else if (fileSize > 8) {
|
else if (fileSize > 8) {
|
||||||
const fileURL = await upload(output)
|
const fileURL = await utils.upload(output)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
|
@ -130,31 +131,3 @@ async function download(url, interaction) {
|
||||||
});
|
});
|
||||||
return;
|
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()
|
data: new SlashCommandBuilder()
|
||||||
.setName('ping')
|
.setName('ping')
|
||||||
.setDescription('Replies with Pong!'),
|
.setDescription('Replies with Pong!'),
|
||||||
|
|
|
@ -20,6 +20,23 @@ const commands = [
|
||||||
option.setName('advanced')
|
option.setName('advanced')
|
||||||
.setDescription('Choose the quality of the video.')
|
.setDescription('Choose the quality of the video.')
|
||||||
.setRequired(false)),
|
.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());
|
.map(command => command.toJSON());
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module.exports = {
|
export default {
|
||||||
name: 'interactionCreate',
|
name: 'interactionCreate',
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const client = interaction.client;
|
const client = interaction.client;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
const { exec } = require('node:child_process');
|
import { exec } from 'node:child_process';
|
||||||
const https = require('node:https');
|
import https from 'node:https';
|
||||||
require('dotenv').config();
|
import dotenv from 'dotenv'
|
||||||
|
dotenv.config();
|
||||||
const { uptimeURL, uptimeInterval } = process.env;
|
const { uptimeURL, uptimeInterval } = process.env;
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
name: 'ready',
|
name: 'ready',
|
||||||
once: true,
|
once: true,
|
||||||
async execute(client) {
|
async execute(client) {
|
||||||
|
|
19
index.js
19
index.js
|
@ -1,9 +1,14 @@
|
||||||
const fs = require('node:fs');
|
import fs from 'node:fs';
|
||||||
const path = require('node:path');
|
import path from 'node:path';
|
||||||
const { Client, Collection, Intents } = require('discord.js');
|
import { fileURLToPath } from 'node:url';
|
||||||
require('dotenv').config();
|
import { Client, Collection, Intents } from 'discord.js';
|
||||||
|
import dotenv from 'dotenv'
|
||||||
|
dotenv.config()
|
||||||
const { token } = process.env;
|
const { token } = process.env;
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
||||||
|
|
||||||
// Load commands from the commands folder
|
// Load commands from the commands folder
|
||||||
|
@ -13,7 +18,8 @@ const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('
|
||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
const filePath = path.join(commandsPath, file);
|
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);
|
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) {
|
for (const file of eventFiles) {
|
||||||
const filePath = path.join(eventsPath, file);
|
const filePath = path.join(eventsPath, file);
|
||||||
const event = require(filePath);
|
let event = await import(filePath);
|
||||||
|
event = event.default;
|
||||||
if (event.once) {
|
if (event.once) {
|
||||||
client.once(event.name, (...args) => event.execute(...args));
|
client.once(event.name, (...args) => event.execute(...args));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue