Compare commits
6 commits
1f8c5585dc
...
a4eab091c7
Author | SHA1 | Date | |
---|---|---|---|
a4eab091c7 | |||
7f8895660b | |||
1861e5b6e7 | |||
dfbc5630f8 | |||
d44fabf554 | |||
851112de0a |
12 changed files with 77 additions and 22 deletions
|
@ -5,9 +5,9 @@
|
||||||
"es6": true
|
"es6": true
|
||||||
},
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 2021
|
"ecmaVersion": 2022,
|
||||||
|
"sourceType": "module"
|
||||||
},
|
},
|
||||||
"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 }],
|
||||||
|
|
17
.vscode/launch.json
vendored
Normal file
17
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "pwa-node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch Program",
|
||||||
|
"skipFiles": [
|
||||||
|
"<node_internals>/**"
|
||||||
|
],
|
||||||
|
"program": "${workspaceFolder}/index.js"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||||
import { MessageEmbed } from 'discord.js';
|
import { MessageEmbed } from 'discord.js';
|
||||||
import fetch from 'node-fetch'
|
import fetch from 'node-fetch';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
@ -34,7 +34,7 @@ export default {
|
||||||
.setURL('https://reddit.com' + response.data.children[i].data.permalink)
|
.setURL('https://reddit.com' + response.data.children[i].data.permalink)
|
||||||
.setFooter(`/r/${response.data.children[i].data.subreddit} | ⬆ ${response.data.children[i].data.ups} 🗨 ${response.data.children[i].data.num_comments}`);
|
.setFooter(`/r/${response.data.children[i].data.subreddit} | ⬆ ${response.data.children[i].data.ups} 🗨 ${response.data.children[i].data.num_comments}`);
|
||||||
|
|
||||||
interaction.editReply({ embeds: [redditEmbed]});
|
interaction.editReply({ embeds: [redditEmbed] });
|
||||||
interaction.followUp(response.data.children[i].data.url);
|
interaction.followUp(response.data.children[i].data.url);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -25,9 +25,12 @@ export default {
|
||||||
const gifskiOutput = output.replace(path.extname(output), '.gif');
|
const gifskiOutput = output.replace(path.extname(output), '.gif');
|
||||||
const gifsicleOutput = output.replace(path.extname(output), 'gifsicle.gif');
|
const gifsicleOutput = output.replace(path.extname(output), 'gifsicle.gif');
|
||||||
|
|
||||||
await utils.ffmpeg(`-i ${output} ${os.tmpdir()}/frame${interaction.id}%04d.png`); // Extract every frame for gifski
|
// Extract every frame for gifski
|
||||||
await gifski(gifskiOutput, `${os.tmpdir()}/frame${interaction.id}*`); // Make it look better
|
await utils.ffmpeg(`-i ${output} ${os.tmpdir()}/frame${interaction.id}%04d.png`);
|
||||||
await gifsicle(gifskiOutput, gifsicleOutput); // Optimize it
|
// Make it look better
|
||||||
|
await gifski(gifskiOutput, `${os.tmpdir()}/frame${interaction.id}*`);
|
||||||
|
// Optimize it
|
||||||
|
await gifsicle(gifskiOutput, gifsicleOutput);
|
||||||
|
|
||||||
const fileStat = fs.statSync(gifsicleOutput);
|
const fileStat = fs.statSync(gifsicleOutput);
|
||||||
const fileSize = fileStat.size / 1000000.0;
|
const fileSize = fileStat.size / 1000000.0;
|
||||||
|
|
|
@ -42,6 +42,12 @@ const commands = [
|
||||||
|
|
||||||
const rest = new REST({ version: '9' }).setToken(token);
|
const rest = new REST({ version: '9' }).setToken(token);
|
||||||
|
|
||||||
|
if (process.argv[2] === 'global') {
|
||||||
|
rest.put(Routes.applicationCommands(clientId), { body: commands })
|
||||||
|
.then(() => console.log('Successfully registered application commands globally.'))
|
||||||
|
.catch(console.error);
|
||||||
|
}
|
||||||
|
|
||||||
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
|
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
|
||||||
.then(() => console.log('Successfully registered application commands.'))
|
.then(() => console.log(`Successfully registered application commands for the guild ${guildId}.`))
|
||||||
.catch(console.error);
|
.catch(console.error);
|
|
@ -1,6 +1,6 @@
|
||||||
import { exec } from 'node:child_process';
|
import { exec } from 'node:child_process';
|
||||||
import https from 'node:https';
|
import https from 'node:https';
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv';
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
const { uptimeURL, uptimeInterval } = process.env;
|
const { uptimeURL, uptimeInterval } = process.env;
|
||||||
|
|
7
events/process/unhandledRejection.js
Normal file
7
events/process/unhandledRejection.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export default {
|
||||||
|
name: 'unhandledRejection',
|
||||||
|
once: true,
|
||||||
|
async execute(error) {
|
||||||
|
console.error('Unhandled promise rejection:', error);
|
||||||
|
},
|
||||||
|
};
|
30
index.js
30
index.js
|
@ -2,8 +2,8 @@ import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { Client, Collection, Intents } from 'discord.js';
|
import { Client, Collection, Intents } from 'discord.js';
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv';
|
||||||
dotenv.config()
|
dotenv.config();
|
||||||
const { token } = process.env;
|
const { token } = process.env;
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
@ -24,12 +24,12 @@ for (const file of commandFiles) {
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load events from the events folder
|
// Load client events from the events folder
|
||||||
const eventsPath = path.join(__dirname, 'events');
|
const clientEventsPath = path.join(__dirname, 'events/client');
|
||||||
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
|
const clientEventFiles = fs.readdirSync(clientEventsPath).filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
for (const file of eventFiles) {
|
for (const file of clientEventFiles) {
|
||||||
const filePath = path.join(eventsPath, file);
|
const filePath = path.join(clientEventsPath, file);
|
||||||
let event = await import(filePath);
|
let event = await import(filePath);
|
||||||
event = event.default;
|
event = event.default;
|
||||||
if (event.once) {
|
if (event.once) {
|
||||||
|
@ -40,4 +40,20 @@ for (const file of eventFiles) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load process events from the events folder
|
||||||
|
const processEventsPath = path.join(__dirname, 'events/process');
|
||||||
|
const processEventFiles = fs.readdirSync(processEventsPath).filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
|
for (const file of processEventFiles) {
|
||||||
|
const filePath = path.join(processEventsPath, file);
|
||||||
|
let event = await import(filePath);
|
||||||
|
event = event.default;
|
||||||
|
if (event.once) {
|
||||||
|
process.once(event.name, (...args) => event.execute(...args));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
process.on(event.name, (...args) => event.execute(...args));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
client.login(token);
|
client.login(token);
|
||||||
|
|
12
package.json
12
package.json
|
@ -1,15 +1,19 @@
|
||||||
{
|
{
|
||||||
"name": "haha-yes-new",
|
"name": "haha-yes",
|
||||||
"version": "1.0.0",
|
"version": "4.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"start": "node .",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"lintfix": "eslint . --fix",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "Supositware",
|
||||||
"license": "ISC",
|
"homepage": "https://libtar.de",
|
||||||
|
"license": "AGPL",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/builders": "^0.13.0",
|
"@discordjs/builders": "^0.13.0",
|
||||||
"@discordjs/rest": "^0.4.1",
|
"@discordjs/rest": "^0.4.1",
|
||||||
|
|
|
@ -13,6 +13,8 @@ You need to install the following
|
||||||
|
|
||||||
* ffmpeg (Optional but very recommanded: for yt-dlp to merge video/audio formats)
|
* ffmpeg (Optional but very recommanded: for yt-dlp to merge video/audio formats)
|
||||||
* yt-dlp ([a file can download it for you](prereq.js))
|
* yt-dlp ([a file can download it for you](prereq.js))
|
||||||
|
* gifsicle (For [vid2gif](commands/vid2gif.js))
|
||||||
|
* giski (For [vid2gif](commands/vid2gif.js))
|
||||||
* Somewhere to upload files larger than 8 mb (I use a self hosted (XBackBone)[https://github.com/SergiX44/XBackBone/] with the upload.sh script made from it, you can use anything else just need to be located in bin/upload.sh)
|
* Somewhere to upload files larger than 8 mb (I use a self hosted (XBackBone)[https://github.com/SergiX44/XBackBone/] with the upload.sh script made from it, you can use anything else just need to be located in bin/upload.sh)
|
||||||
|
|
||||||
### Installing
|
### Installing
|
||||||
|
@ -24,7 +26,7 @@ npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
To run the bot for the first time you need to execute [deploy-guild-commands.js](deploy-guild-commands.js) so the commands can be registered, don't forget to set your .env accordingly.
|
To run the bot for the first time you need to execute [deploy-guild-commands.js](deploy-guild-commands.js) so the commands can be registered, don't forget to set your .env accordingly.
|
||||||
``node deploy-commands.js``
|
``node deploy-commands.cjs``
|
||||||
|
|
||||||
then you can just run it normally.
|
then you can just run it normally.
|
||||||
``node index.js``
|
``node index.js``
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { exec } from 'node:child_process';
|
||||||
export default {
|
export default {
|
||||||
downloadVideo,
|
downloadVideo,
|
||||||
upload,
|
upload,
|
||||||
ffmpeg
|
ffmpeg,
|
||||||
};
|
};
|
||||||
async function downloadVideo(url, output, format = 'bestvideo*+bestaudio/best') {
|
async function downloadVideo(url, output, format = 'bestvideo*+bestaudio/best') {
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
|
|
Loading…
Reference in a new issue