aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-05-15 13:32:23 +0200
committerMinteck <contact@minteck.org>2022-05-15 13:32:23 +0200
commitdfc64c43589dd9189aa316b6c1d454c2de0ae21a (patch)
tree6ad95ff86aa006637a6403ccb667a2544f27cb51
parent9d48f74a6f23b1d7b21d72b8efb9f5b58050c0cd (diff)
downloaddj-pon-3-dfc64c43589dd9189aa316b6c1d454c2de0ae21a.tar.gz
dj-pon-3-dfc64c43589dd9189aa316b6c1d454c2de0ae21a.tar.bz2
dj-pon-3-dfc64c43589dd9189aa316b6c1d454c2de0ae21a.zip
Some fixes
-rw-r--r--commands/debug.ts2
-rw-r--r--commands/seek.ts65
-rw-r--r--commands/stop.ts2
-rw-r--r--core/DJPon3.ts2
-rw-r--r--core/PresenceManager.ts18
-rw-r--r--core/TimeManipulation.ts25
-rw-r--r--core/VoiceBase.ts2
-rw-r--r--package-lock.json72
-rw-r--r--package.json2
9 files changed, 187 insertions, 3 deletions
diff --git a/commands/debug.ts b/commands/debug.ts
index 305f926..3fbca50 100644
--- a/commands/debug.ts
+++ b/commands/debug.ts
@@ -26,7 +26,7 @@ export class DebugCommand extends CommandBase {
"OS: " + os.type() + " " + os.arch() + " " + os.release() + "\n" +
"\n" +
"# Bot #\n" +
- "Version: " + (fs.existsSync("./.git/refs/heads/mane") ? fs.readFileSync("./.git/refs/heads/mane").toString().trim().substring(0, 8) : "dev") + ", build " + (fs.existsSync("./build.txt") ? fs.readFileSync("./build.txt").toString().trim() : "dev") + "\n" +
+ "Version: " + (fs.existsSync("./.git/refs/heads/mane") ? fs.readFileSync("./.git/refs/heads/mane").toString().trim().substring(0, 8) : (fs.existsSync("../.git/refs/heads/mane") ? fs.readFileSync("../.git/refs/heads/mane").toString().trim().substring(0, 8) : "live")) + ", build " + (fs.existsSync("./build.txt") ? fs.readFileSync("./build.txt").toString().trim() : (fs.existsSync("../build.txt") ? fs.readFileSync("../build.txt").toString().trim() : "dev")) + "\n" +
"ImportedModules: " + Object.keys(require.cache).length + "\n" +
"RAM: " + Math.round(process.memoryUsage().heapTotal / 1024) + "K\n" +
"ConnectDate: " + global.client.readyAt.toISOString() + "\n" +
diff --git a/commands/seek.ts b/commands/seek.ts
new file mode 100644
index 0000000..c0c268f
--- /dev/null
+++ b/commands/seek.ts
@@ -0,0 +1,65 @@
+import { CommandBase } from "../core/CommandBase";
+import { CommandInteraction, MessageEmbed } from "discord.js";
+import { SlashCommandBuilder } from "@discordjs/builders";
+import { validateURL } from "ytdl-core";
+import {TimeManipulation} from "../core/TimeManipulation";
+
+export class SeekCommand extends CommandBase {
+ constructor () {
+ super();
+ this.slashCommandData = new SlashCommandBuilder()
+ .setName("seek")
+ .setDescription("Go to a specific part of the song")
+ .addStringOption(option =>
+ option.setName('position')
+ .setDescription("An absolute, relative, or percentage value to go to")
+ .setRequired(true)
+ )
+ }
+
+ public handle (interaction: CommandInteraction) {
+ let VoiceBase = global.VoiceBase;
+
+ if (VoiceBase.connected) {
+ if (!VoiceBase.playing) {
+ interaction.reply({ embeds: [
+ new MessageEmbed()
+ .setDescription(":x: The bot is not playing, please use `/play`.")
+ ] });
+ return;
+ }
+
+ if (VoiceBase.paused) {
+ interaction.reply({ embeds: [
+ new MessageEmbed()
+ .setDescription(":x: The bot is not paused, please use `/play`.")
+ ] });
+ return;
+ }
+
+ let time = interaction.options.getString('position').trim();
+
+ if (!(TimeManipulation.isPercentage(time) ||
+ TimeManipulation.isSeconds(time) ||
+ TimeManipulation.isTime(time) ||
+ TimeManipulation.isRelativeTime(time) ||
+ TimeManipulation.isRelativeSeconds(time) ||
+ TimeManipulation.isRelativePercentage(time)
+ )) {
+ interaction.reply({ embeds: [
+ new MessageEmbed()
+ .setDescription(":x: Invalid time specification. Accepted formats are: percentage, number of seconds, MM:SS, and relative values.")
+ ] });
+ } else {
+ if (TimeManipulation.isSeconds(time)) {
+
+ }
+ }
+ } else {
+ interaction.reply({ embeds: [
+ new MessageEmbed()
+ .setDescription(":x: The bot is disconnected, please use `/join`.")
+ ] });
+ }
+ }
+} \ No newline at end of file
diff --git a/commands/stop.ts b/commands/stop.ts
index 778a3b4..7185db5 100644
--- a/commands/stop.ts
+++ b/commands/stop.ts
@@ -18,7 +18,7 @@ export class StopCommand extends CommandBase {
new MessageEmbed()
.setDescription(":hourglass: Just a moment...")
] }).then(() => {
- VoiceBase.player.stop();
+ if (VoiceBase.player) VoiceBase.player.stop();
VoiceBase.connection.disconnect();
VoiceBase.connected = false;
VoiceBase.playing = false;
diff --git a/core/DJPon3.ts b/core/DJPon3.ts
index 5c49488..8bbc163 100644
--- a/core/DJPon3.ts
+++ b/core/DJPon3.ts
@@ -4,6 +4,7 @@ import * as fs from 'fs';
import { LogManager } from "./LogManager";
import { CommandInteractionManager } from "./CommandInteractionManager";
import { VoiceBase } from "./VoiceBase";
+import { PresenceManager } from "./PresenceManager";
global.VoiceBase = new VoiceBase();
@@ -23,6 +24,7 @@ export class DJPon3 {
client.on('ready', () => {
LogManager.info(`Logged in as ${client.user.tag}!`);
+ PresenceManager.start(client);
});
client.on('interactionCreate', async interaction => {
diff --git a/core/PresenceManager.ts b/core/PresenceManager.ts
new file mode 100644
index 0000000..8e5867c
--- /dev/null
+++ b/core/PresenceManager.ts
@@ -0,0 +1,18 @@
+import { Client } from "discord.js";
+
+export class PresenceManager {
+ public static start (client: Client): void {
+ let VoiceBase = global.VoiceBase;
+ setInterval(() => {
+ if (!VoiceBase.playing) {
+ client.user.setPresence({ activities: [{ name: '⏹ Stopped' }], status: 'online' });
+ } else {
+ if (VoiceBase.paused) {
+ client.user.setPresence({ activities: [{ name: '⏸ ' + VoiceBase.queue.get(0).title }], status: 'online' });
+ } else {
+ client.user.setPresence({ activities: [{ name: '▶️ ' + VoiceBase.queue.get(0).title }], status: 'online' });
+ }
+ }
+ }, 1000);
+ }
+} \ No newline at end of file
diff --git a/core/TimeManipulation.ts b/core/TimeManipulation.ts
new file mode 100644
index 0000000..1735d6d
--- /dev/null
+++ b/core/TimeManipulation.ts
@@ -0,0 +1,25 @@
+export class TimeManipulation {
+ public static isPercentage (time: string): boolean {
+ return time.match(/^(1|)\d{1,2}%$/gm) !== null;
+ }
+
+ public static isTime (time: string): boolean {
+ return time.match(/^(\d|)\d:\d\d$/gm) !== null;
+ }
+
+ public static isSeconds (time: string): boolean {
+ return time.match(/^\d*$/gm) !== null;
+ }
+
+ public static isRelativeTime (time: string): boolean {
+ return time.match(/^[+|-](\d|)\d:\d\d$/gm) !== null;
+ }
+
+ public static isRelativeSeconds (time: string): boolean {
+ return time.match(/^[+|-]\d*$/gm) !== null;
+ }
+
+ public static isRelativePercentage (time: string): boolean {
+ return time.match(/^[+|-](1|)\d{1,2}%$/gm) !== null;
+ }
+} \ No newline at end of file
diff --git a/core/VoiceBase.ts b/core/VoiceBase.ts
index 3df433f..44b0d6f 100644
--- a/core/VoiceBase.ts
+++ b/core/VoiceBase.ts
@@ -23,7 +23,7 @@ export class VoiceBase {
this.repeat = false;
this.voiceChannel = null;
this.textChannel = null;
- this.currentSong = null
+ this.currentSong = null;
this.queue = new QueueManager();
}
} \ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 3f49980..43d9c84 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -16,11 +16,13 @@
"chalk": "^4.1.2",
"discord-api-types": "^0.32.1",
"discord.js": "^13.6.0",
+ "fluent-ffmpeg": "^2.1.2",
"sodium": "^3.0.2",
"youtube-dl-exec": "^2.0.11",
"ytdl-core": "^4.11.0"
},
"devDependencies": {
+ "@types/fluent-ffmpeg": "^2.1.20",
"nodemon": "^2.0.16",
"typescript": "^4.6.4"
}
@@ -255,6 +257,15 @@
"node": ">=6"
}
},
+ "node_modules/@types/fluent-ffmpeg": {
+ "version": "2.1.20",
+ "resolved": "https://registry.npmjs.org/@types/fluent-ffmpeg/-/fluent-ffmpeg-2.1.20.tgz",
+ "integrity": "sha512-B+OvhCdJ3LgEq2PhvWNOiB/EfwnXLElfMCgc4Z1K5zXgSfo9I6uGKwR/lqmNPFQuebNnes7re3gqkV77SyypLg==",
+ "dev": true,
+ "dependencies": {
+ "@types/node": "*"
+ }
+ },
"node_modules/@types/node": {
"version": "17.0.32",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.32.tgz",
@@ -388,6 +399,11 @@
"node": ">=10"
}
},
+ "node_modules/async": {
+ "version": "3.2.3",
+ "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz",
+ "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g=="
+ },
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
@@ -882,6 +898,29 @@
"node": ">=8"
}
},
+ "node_modules/fluent-ffmpeg": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/fluent-ffmpeg/-/fluent-ffmpeg-2.1.2.tgz",
+ "integrity": "sha1-yVLeIkD4EuvaCqgAbXd27irPfXQ=",
+ "dependencies": {
+ "async": ">=0.2.9",
+ "which": "^1.1.1"
+ },
+ "engines": {
+ "node": ">=0.8.0"
+ }
+ },
+ "node_modules/fluent-ffmpeg/node_modules/which": {
+ "version": "1.3.1",
+ "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
+ "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
+ "dependencies": {
+ "isexe": "^2.0.0"
+ },
+ "bin": {
+ "which": "bin/which"
+ }
+ },
"node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
@@ -2487,6 +2526,15 @@
"defer-to-connect": "^1.0.1"
}
},
+ "@types/fluent-ffmpeg": {
+ "version": "2.1.20",
+ "resolved": "https://registry.npmjs.org/@types/fluent-ffmpeg/-/fluent-ffmpeg-2.1.20.tgz",
+ "integrity": "sha512-B+OvhCdJ3LgEq2PhvWNOiB/EfwnXLElfMCgc4Z1K5zXgSfo9I6uGKwR/lqmNPFQuebNnes7re3gqkV77SyypLg==",
+ "dev": true,
+ "requires": {
+ "@types/node": "*"
+ }
+ },
"@types/node": {
"version": "17.0.32",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.32.tgz",
@@ -2595,6 +2643,11 @@
"readable-stream": "^3.6.0"
}
},
+ "async": {
+ "version": "3.2.3",
+ "resolved": "https://registry.npmjs.org/async/-/async-3.2.3.tgz",
+ "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g=="
+ },
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
@@ -2967,6 +3020,25 @@
"to-regex-range": "^5.0.1"
}
},
+ "fluent-ffmpeg": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/fluent-ffmpeg/-/fluent-ffmpeg-2.1.2.tgz",
+ "integrity": "sha1-yVLeIkD4EuvaCqgAbXd27irPfXQ=",
+ "requires": {
+ "async": ">=0.2.9",
+ "which": "^1.1.1"
+ },
+ "dependencies": {
+ "which": {
+ "version": "1.3.1",
+ "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",
+ "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==",
+ "requires": {
+ "isexe": "^2.0.0"
+ }
+ }
+ }
+ },
"form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
diff --git a/package.json b/package.json
index 2b7da9d..bb9eb4f 100644
--- a/package.json
+++ b/package.json
@@ -14,6 +14,7 @@
"author": "Minteck",
"license": "MIT",
"devDependencies": {
+ "@types/fluent-ffmpeg": "^2.1.20",
"nodemon": "^2.0.16",
"typescript": "^4.6.4"
},
@@ -25,6 +26,7 @@
"chalk": "^4.1.2",
"discord-api-types": "^0.32.1",
"discord.js": "^13.6.0",
+ "fluent-ffmpeg": "^2.1.2",
"sodium": "^3.0.2",
"youtube-dl-exec": "^2.0.11",
"ytdl-core": "^4.11.0"