aboutsummaryrefslogtreecommitdiff
path: root/bot.js
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2022-07-10 13:58:09 -0400
committerAndrew Lee <alee14498@protonmail.com>2022-07-10 13:58:09 -0400
commit10e93faf891c3fa3a68edb59d4ffb9d939680dc6 (patch)
tree18f91ef2434ad0eb2d613dad13d0815c64f7ffe1 /bot.js
parent626cef85162b08c1808d8f88b5b245060ff0dd54 (diff)
downloadDLAP-10e93faf891c3fa3a68edb59d4ffb9d939680dc6.tar.gz
DLAP-10e93faf891c3fa3a68edb59d4ffb9d939680dc6.tar.bz2
DLAP-10e93faf891c3fa3a68edb59d4ffb9d939680dc6.zip
Simple http server
Diffstat (limited to 'bot.js')
-rw-r--r--bot.js35
1 files changed, 33 insertions, 2 deletions
diff --git a/bot.js b/bot.js
index cbad4a9..5aee843 100644
--- a/bot.js
+++ b/bot.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
*/