diff --git a/.gitignore b/.gitignore index 749d496..4ee868f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ tags # secrets secrets +node_modules diff --git a/ljsthw-bot.js b/ljsthw-bot.js index cb8ff0c..af52144 100644 --- a/ljsthw-bot.js +++ b/ljsthw-bot.js @@ -1,6 +1,24 @@ import { Client, Intents } from "discord.js"; import assert from "assert"; -import { TOKEN } from "../secrets/discord.js"; +import { TOKEN, chat_secret } from "./secrets/discord.js"; +import http from "http"; +import { io } from "socket.io-client"; + +const server = http.createServer(); +const socket = io("ws://localhost:5001"); + +socket.io.on("error", (error) => { + console.error(error); +}); + +socket.io.on("ping", () => { + console.log("PING"); +}); + +socket.on("connect", () => { + console.log("CONNECTED", socket.connected); +}); + const client = new Client({ intents: [ @@ -143,14 +161,12 @@ client.on("messageCreate", async msg => { } else if(msg.channel.name === "livestream") { console.log(">>> LIVESTREAM CHAT MESSAGE FROM", msg.author.username, msg.channel.type, msg.channel.name, msg.content); - // banlist lookup user - const is_ban = BAN_LIST[msg.author.username]; - if(is_ban) { - console.log("IGNORE BANNED USER", msg.author.username); - } else { - // else - // socket_conn send message - } + const initials = `${msg.author.username[0]}${msg.author.username[1]}`; + + socket.emit("/chat/message", { + chat_secret, user_id: initials, text: msg.content + }); + } else { console.log("IGNORED MESSAGE FROM", msg.author.username, "IN", msg.channel.name); }