diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2022-07-10 13:58:09 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2022-07-10 13:58:09 -0400 |
| commit | 10e93faf891c3fa3a68edb59d4ffb9d939680dc6 (patch) | |
| tree | 18f91ef2434ad0eb2d613dad13d0815c64f7ffe1 | |
| parent | 626cef85162b08c1808d8f88b5b245060ff0dd54 (diff) | |
| download | DLAP-10e93faf891c3fa3a68edb59d4ffb9d939680dc6.tar.gz DLAP-10e93faf891c3fa3a68edb59d4ffb9d939680dc6.tar.bz2 DLAP-10e93faf891c3fa3a68edb59d4ffb9d939680dc6.zip | |
Simple http server
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | bot.js | 35 | ||||
| -rw-r--r-- | commands/list.js | 4 | ||||
| -rw-r--r-- | commands/status.js | 3 | ||||
| -rw-r--r-- | package.json | 4 |
5 files changed, 40 insertions, 10 deletions
@@ -11,7 +11,7 @@ Make a new file called `config.json`. ``` { "token": "token_here", - "txtFile": true/false + "txtFile": true/false, "statusChannel": "channel_id", "voiceChannel": "voice_channel_id" "guildID": "guild_id", @@ -55,4 +55,4 @@ You need to edit `/commands/about.js` to uncomment the `.addField('Forked by', ' Be sure to replace that with your name. # Contributing -When contributing, be sure to add yourself to the contributors list in `/commands/about.js`.
\ No newline at end of file +When contributing, be sure to add yourself to the contributors list in `/commands/about.js`. @@ -22,15 +22,46 @@ import { Client, MessageEmbed, Collection, version } from 'discord.js'; import { voiceInit } from './AudioBackend.js'; import { readdirSync, readFileSync } from 'node:fs'; // 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'] }); -bot.login(config.token); +const port = 1337; + +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); /** * Project Ideas: - * Shuffle or "Play by order" mode * Audio streaming */ diff --git a/commands/list.js b/commands/list.js index 8f2010b..7101e16 100644 --- a/commands/list.js +++ b/commands/list.js @@ -33,9 +33,7 @@ export default { const beats = readdirSync(musicFolder).join('\n'); readdir(musicFolder, async(err, files) => { - await interaction.reply( - `Listing ${files.length} audio tracks...\n\`\`\`\n${beats}\n\`\`\`` - ); + await interaction.reply(`Listing ${files.length} audio tracks...\n\`\`\`\n${beats}\n\`\`\``); if (err) { console.error(err); } diff --git a/commands/status.js b/commands/status.js index c78e736..e135113 100644 --- a/commands/status.js +++ b/commands/status.js @@ -21,7 +21,7 @@ import { SlashCommandBuilder } from '@discordjs/builders'; import { MessageEmbed } from 'discord.js'; -import { audio, audioArray, currentTrack, playerState } from '../AudioBackend.js'; +import { audio, audioArray, currentTrack, files, playerState } from '../AudioBackend.js'; export default { data: new SlashCommandBuilder() @@ -37,6 +37,7 @@ export default { const controlEmbed = new MessageEmbed() .setAuthor({ name: `${bot.user.username} Status`, iconURL: bot.user.avatarURL() }) .addField('State', playerState) + .addField('Tracks', `${audioID}/${files.length}`) .addField('Currently Playing', audio) .addField('Up Next', audioName) .setColor('#0066ff'); diff --git a/package.json b/package.json index 5e72c09..9ca9bbd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dlap", - "version": "1.3.0", + "version": "1.4.0", "type": "module", "main": "bot.js", "license": "GPL-3.0", @@ -15,7 +15,7 @@ "discord-api-types": "^0.36.1", "discord.js": "^13.8.1", "ffmpeg-static": "^5.0.0", - "libsodium-wrappers": "^0.7.10" + "sodium": "^3.0.2" }, "devDependencies": { "eslint": "^8.0.1", |
