Init Commit

Server
- Working init discord bot
    - Modular events and commands
    - Has access to the socket server
- Working init socket server
    - Need to work on getting access to discord bot
- Working init web server

Currently working on breaking out the init of the socket server

Client
- Working init socket client

Currently working on the discord bot to join voice channels
This commit is contained in:
Logan Cusano
2024-01-08 00:12:47 -05:00
parent 86dd058d2a
commit 4a0b1004d2
16 changed files with 2599 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
import { Client, GatewayIntentBits } from 'discord.js';
import dotenv from 'dotenv';
dotenv.config()
export const serverClient = new Client({ intents: [GatewayIntentBits.Guilds] });
serverClient.on('ready', () => {
console.log(`Logged in as ${serverClient.user.tag}!`);
});

View File

@@ -0,0 +1,59 @@
import express from 'express';
import { createServer } from 'node:http';
import { Server } from 'socket.io';
import morgan from 'morgan';
export const app = express();
export const server = createServer(app);
export const nodeIo = new Server(server);
app.use(morgan('tiny'));
app.get('/', (req, res) => {
res.send('<h1>Hello world</h1>');
});
nodeIo.on('connection', (socket) => {
console.log('a user connected', socket.id);
socket.on('node-login', (data) => {
nodeLoginWrapper(data);
})
socket.on('node-update', (data) => {
updateNodeData(data);
})
socket.on('disconnect', () => {
console.log('user disconnected');
});
// Test commands
setTimeout(() => { sendNodeCommand(socket, "node-join", { 'some': 'data' }); }, 2500)
setTimeout(() => { sendNodeCommand(socket, "node-leave", {}); }, 3500)
});
function sendNodeCommand(socket, command, data) {
// TODO - Check to see if the command exists
// TODO - Check to see if the socket is alive?
// TODO - Validate the given data
socket.emit(command, data);
}
function loginNode() {
}
function registerNode() {
}
function updateNodeData(data) {
console.log("Data update sent by node: ", data);
}
function nodeLoginWrapper(data) {
console.log(`Login requested from node: ${data.id}`, data);
}