brainlet-irc/index.js
2021-01-25 00:23:34 -05:00

85 lines
2.3 KiB
JavaScript

/*
Software to convert the Brainlet protocol to the IRC protocol
Copyright (C) 2021 hiimgoodpack
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const fs = require("fs");
const ircServer = require("./ircd.js/lib/server.js");
const ircClient = require("irc");
const crypto = require("crypto");
const brainlet = require("./brainlet-lib/index.js");
// Set up IRC server
const config = require(`${__dirname}/config.js`)
const genPass = () => {
// This should give us a reasonably secure password
return crypto.randomBytes(66).toString("base64");
}
// NOTE: You don't actually need the password to log into the account
let systemUsers = {
NickServ: {
password: "12345"
},
ChanServ: {
password: genPass()
},
DinoServ: {
password: genPass()
}
}
const ircConfig = {
network: "BrainletToIRC",
hostname: "localhost",
serverDescription: "A brainlet to IRC translation layer",
serverName: config.server,
port: 6667,
linkPort: 7777,
motd: config.motd,
whoWasLimit: 10000,
token: 1,
opers: systemUsers,
channels: {},
links: {
server: {
host: "127.0.0.1",
password: genPass(),
port: 7778,
token: 2
}
},
pingTimeout: 120,
maxNickLength: 30
};
fs.writeFileSync(`${__dirname}/ircd.js/config/config.json`, JSON.stringify(ircConfig));
ircServer.Server.boot();
// Set up system users
let tokens = {};
let sockets = {};
let availableBots = {};
// Maps channel names to category ids
let channelNameToCategoryId = {};
// Maps category ids to channel names
let categoryIdToChannelName = {};
for (const botIndex in config.bots) {
const bot = config.bots[botIndex];
require(`./bots/${bot}.js`).start(config, {tokens, sockets, availableBots, channelNameToCategoryId, categoryIdToChannelName});
availableBots[bot] = true;
}