mirror of
https://github.com/Alee14/DLAP.git
synced 2025-01-22 19:02:57 -05:00
Simple http server
This commit is contained in:
parent
626cef8516
commit
10e93faf89
5 changed files with 40 additions and 10 deletions
|
@ -11,7 +11,7 @@ Make a new file called `config.json`.
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
"token": "token_here",
|
"token": "token_here",
|
||||||
"txtFile": true/false
|
"txtFile": true/false,
|
||||||
"statusChannel": "channel_id",
|
"statusChannel": "channel_id",
|
||||||
"voiceChannel": "voice_channel_id"
|
"voiceChannel": "voice_channel_id"
|
||||||
"guildID": "guild_id",
|
"guildID": "guild_id",
|
||||||
|
|
35
bot.js
35
bot.js
|
@ -22,15 +22,46 @@ import { Client, MessageEmbed, Collection, version } from 'discord.js';
|
||||||
import { voiceInit } from './AudioBackend.js';
|
import { voiceInit } from './AudioBackend.js';
|
||||||
import { readdirSync, readFileSync } from 'node:fs';
|
import { readdirSync, readFileSync } from 'node:fs';
|
||||||
// import config from './config.json' assert { type: 'json' } Not supported by ESLint yet
|
// 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 config = JSON.parse(readFileSync('./config.json'));
|
||||||
|
|
||||||
const bot = new Client({ intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_VOICE_STATES'] });
|
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:
|
* Project Ideas:
|
||||||
* Shuffle or "Play by order" mode
|
|
||||||
* Audio streaming
|
* Audio streaming
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,7 @@ export default {
|
||||||
|
|
||||||
const beats = readdirSync(musicFolder).join('\n');
|
const beats = readdirSync(musicFolder).join('\n');
|
||||||
readdir(musicFolder, async(err, files) => {
|
readdir(musicFolder, async(err, files) => {
|
||||||
await interaction.reply(
|
await interaction.reply(`Listing ${files.length} audio tracks...\n\`\`\`\n${beats}\n\`\`\``);
|
||||||
`Listing ${files.length} audio tracks...\n\`\`\`\n${beats}\n\`\`\``
|
|
||||||
);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
import { SlashCommandBuilder } from '@discordjs/builders';
|
import { SlashCommandBuilder } from '@discordjs/builders';
|
||||||
import { MessageEmbed } from 'discord.js';
|
import { MessageEmbed } from 'discord.js';
|
||||||
import { audio, audioArray, currentTrack, playerState } from '../AudioBackend.js';
|
import { audio, audioArray, currentTrack, files, playerState } from '../AudioBackend.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
@ -37,6 +37,7 @@ export default {
|
||||||
const controlEmbed = new MessageEmbed()
|
const controlEmbed = new MessageEmbed()
|
||||||
.setAuthor({ name: `${bot.user.username} Status`, iconURL: bot.user.avatarURL() })
|
.setAuthor({ name: `${bot.user.username} Status`, iconURL: bot.user.avatarURL() })
|
||||||
.addField('State', playerState)
|
.addField('State', playerState)
|
||||||
|
.addField('Tracks', `${audioID}/${files.length}`)
|
||||||
.addField('Currently Playing', audio)
|
.addField('Currently Playing', audio)
|
||||||
.addField('Up Next', audioName)
|
.addField('Up Next', audioName)
|
||||||
.setColor('#0066ff');
|
.setColor('#0066ff');
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "dlap",
|
"name": "dlap",
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "bot.js",
|
"main": "bot.js",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
"discord-api-types": "^0.36.1",
|
"discord-api-types": "^0.36.1",
|
||||||
"discord.js": "^13.8.1",
|
"discord.js": "^13.8.1",
|
||||||
"ffmpeg-static": "^5.0.0",
|
"ffmpeg-static": "^5.0.0",
|
||||||
"libsodium-wrappers": "^0.7.10"
|
"sodium": "^3.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.0.1",
|
"eslint": "^8.0.1",
|
||||||
|
|
Loading…
Reference in a new issue