aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AudioBackend.js5
-rw-r--r--WebStream.js33
-rw-r--r--bot.js35
-rw-r--r--commands/status.js4
4 files changed, 42 insertions, 35 deletions
diff --git a/AudioBackend.js b/AudioBackend.js
index 909882c..8b02766 100644
--- a/AudioBackend.js
+++ b/AudioBackend.js
@@ -95,13 +95,12 @@ export async function nextAudio(bot) {
if (currentTrack >= totalTrack) {
console.log('All beats in the playlist has finished, reshuffling...');
- await shufflePlaylist(bot);
+ return await shufflePlaylist(bot);
} else {
currentTrack++;
audio = audioArray[currentTrack];
+ return await playAudio(bot);
}
-
- return await playAudio(bot);
}
export async function inputAudio(bot, integer) {
diff --git a/WebStream.js b/WebStream.js
new file mode 100644
index 0000000..efe36c8
--- /dev/null
+++ b/WebStream.js
@@ -0,0 +1,33 @@
+import { createServer } from 'node:http';
+const port = 1337;
+
+export function webServer() {
+ const server = createServer((req, res) => {
+ let body = '{"test": "test"}';
+ // Get the data as utf8 strings.
+ // If an encoding is not set, Buffer objects will be received.
+ req.setEncoding('utf8');
+
+ // Readable streams emit 'data' events once a listener is added.
+ req.on('data', (chunk) => {
+ body += chunk;
+ });
+
+ // The 'end' event indicates that the entire body has been received.
+ req.on('end', () => {
+ try {
+ const data = JSON.parse(body);
+ // Write back something interesting to the user:
+ res.write(typeof data);
+ res.end();
+ } catch (er) {
+ // uh oh! bad json!
+ res.statusCode = 400;
+ return res.end(`error: ${er.message}`);
+ }
+ });
+ });
+
+ server.listen(port);
+ console.log(`Web server started! Port: ${port}`);
+}
diff --git a/bot.js b/bot.js
index 5aee843..a8958df 100644
--- a/bot.js
+++ b/bot.js
@@ -21,44 +21,15 @@
import { Client, MessageEmbed, Collection, version } from 'discord.js';
import { voiceInit } from './AudioBackend.js';
import { readdirSync, readFileSync } from 'node:fs';
+import { webServer } from './WebStream.js';
// import config from './config.json' assert { type: 'json' } Not supported by ESLint yet
-import { createServer } from 'node:http';
const config = JSON.parse(readFileSync('./config.json'));
const bot = new Client({ intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_VOICE_STATES'] });
-const port = 1337;
+bot.login(config.token);
-const server = createServer((req, res) => {
- let body = '{"test": "test"}';
- // Get the data as utf8 strings.
- // If an encoding is not set, Buffer objects will be received.
- req.setEncoding('utf8');
-
- // Readable streams emit 'data' events once a listener is added.
- req.on('data', (chunk) => {
- body += chunk;
- });
-
- // The 'end' event indicates that the entire body has been received.
- req.on('end', () => {
- try {
- const data = JSON.parse(body);
- // Write back something interesting to the user:
- res.write(typeof data);
- res.end();
- } catch (er) {
- // uh oh! bad json!
- res.statusCode = 400;
- return res.end(`error: ${er.message}`);
- }
- });
-});
-
-server.listen(port);
-console.log(`Web server started! Port: ${port}`);
-
-// bot.login(config.token);
+// webServer();
/**
* Project Ideas:
diff --git a/commands/status.js b/commands/status.js
index e135113..d3d70a6 100644
--- a/commands/status.js
+++ b/commands/status.js
@@ -34,6 +34,10 @@ export default {
let audioName = audioArray[audioID];
audioName = audioName.split('.').slice(0, -1).join('.');
+ if (audioName == null) {
+ audioName = 'Finish';
+ }
+
const controlEmbed = new MessageEmbed()
.setAuthor({ name: `${bot.user.username} Status`, iconURL: bot.user.avatarURL() })
.addField('State', playerState)