diff --git a/.gitmodules b/.gitmodules index 2f6ff2c..eb76380 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "brainlet-lib"] path = brainlet-lib url = https://git.hippoz.xyz/hiimgoodpack/brainlet-lib.git +[submodule "ircd.js"] + path = ircd.js + url = https://github.com/TestingPlant/ircd.js.git diff --git a/README.md b/README.md index 7cdc33a..d6282e5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ # brainlet-irc -Brainlet to IRC translation layer \ No newline at end of file +Brainlet to IRC translation layer + +# Technical notes + +This uses irc@0.5.0. See [this](https://github.com/martynsmith/node-irc/issues/495) for more information + +This also uses a fork of ircdjs to add the NOTICE command. [This pull request](https://github.com/alexyoung/ircd.js/pull/99) +is trying to get it merged with the main repository, but I'm not sure how fast it'll get merged seeing the date of the last commit. diff --git a/config.js b/config.js index 9d64118..0c2244d 100644 --- a/config.js +++ b/config.js @@ -4,10 +4,30 @@ module.exports = { name: "BrainletToIrcSpectator", password: "Put a secure password here. See the README for more info" }, - motd: `A Brainlet to IRC translation layer. -SECURITY WARNING: The traffic to the Brainlet server is not encrypted + motd: "A Brainlet to IRC translation layer.\n" + + "SECURITY WARNING: The traffic to the Brainlet server is not encrypted.\n" + + "Use \"/msg NickServ help\" to see how to use an account", -To sign up, use /nick YourName and then /msg NickServ REGISTER YourPassword YourEmail -To log in, use /msg NickServ IDENTIFY YourName YourPassword` + responses: { + NickServ: { + help: `NickServ allows you to use and create a Brainlet account from IRC. +You can use a command with "/msg NickServ " + +Commands: +HELP - Shows this message +REGISTER - Creates an account, using your current nick as the username. + Note: The email is not directly used by IRC, but may be used by the Brainlet host. +IDENTIFY - Logs into an account.`, + + // Sent on invalid command + invalid: "Invalid command. Use \"/msg NickServ help\" for help", + + // Sent on an invalid entry. + // %s is replaced with how it's invalid. + invalidName: "Invalid username specified. %s", + invalidEmail: "Invalid email specified. %s", + invalidPassword: "Invalid password specified. %s" + } + } } diff --git a/index.js b/index.js index 450d65a..b1062b5 100644 --- a/index.js +++ b/index.js @@ -16,12 +16,12 @@ along with this program. If not, see . */ const fs = require("fs"); -const ircServer = require("ircdjs"); +const ircServer = require("./ircd.js/lib/server.js"); const ircClient = require("irc"); const crypto = require("crypto"); // Set up IRC server -const translationConfig = require(`${__dirname}/config.js`) +const config = require(`${__dirname}/config.js`) const genPass = () => { // This should give us a reasonably secure password @@ -37,10 +37,10 @@ const ircConfig = { network: "BrainletToIRC", hostname: "localhost", serverDescription: "A brainlet to IRC translation layer", - serverName: translationConfig.server, + serverName: config.server, port: 6667, linkPort: 7777, - motd: translationConfig.motd, + motd: config.motd, whoWasLimit: 10000, token: 1, opers: systemUsers, @@ -56,22 +56,56 @@ const ircConfig = { pingTimeout: 120, maxNickLength: 30 }; -fs.writeFileSync(`${__dirname}/node_modules/ircdjs/config/config.json`, JSON.stringify(ircConfig)); +fs.writeFileSync(`${__dirname}/ircd.js/config/config.json`, JSON.stringify(ircConfig)); ircServer.Server.boot(); // Set up system users -// TODO: Figure out why user is not joining const ircServerAddress = ircConfig.links.server.host; const ircServerPort = ircConfig.links.server.port; -let NickServ = new ircClient.Client("127.0.0.1", "NickServ", { - userName: "NickServ", - realName: "NickServ", - port: ircServerPort, - channels: ["#foo"], - password: systemUsers.NickServ.password -}); + +let NickServ = new ircClient.Client("localhost", "NickServ"); +console.log(NickServ) NickServ.addListener("error", console.error); -NickServ.addListener("join", () => { - console.log("Joined server"); -}) +NickServ.addListener("message", (from, to, text, message) => { + // Make sure it's a private message to NickServ + if (to !== NickServ.opt.nick) + return; + + const args = text.split(" "); + if (args.length == 0) { + NickServ.notice(from, config.responses.NickServ.invalid); + return; + } + + switch (args[0].toLowerCase()) { + case "help": { + NickServ.notice(from, config.responses.NickServ.help); + break; + } + case "register": { + const password = args[1]; + const email = args[2]; + if (!password || !email) { + NickServ.notice(from, config.responses.NickServ.invalid); + return; + } + NickServ.notice(from, "Account registration is currently not implemented"); + break; + } + case "identify": { + const name = args[1]; + const password = args[2]; + if (!name || !password) { + NickServ.notice(from, config.responses.NickServ.invalid); + return; + } + NickServ.notice(from, "Account login is currently not implemented"); + break; + } + default: { + NickServ.notice(from, config.responses.NickServ.invalid); + break; + } + } +}); diff --git a/ircd.js b/ircd.js new file mode 160000 index 0000000..53e18a0 --- /dev/null +++ b/ircd.js @@ -0,0 +1 @@ +Subproject commit 53e18a0032600abd092aced978e232f637221d1d