sans-bot/bot.js

34 lines
1.0 KiB
JavaScript

// includes
const irc = require("irc");
const lisp = require("./lisp").lisp;
// create the configuration
const config = {
channels: ["##qrxdkw", "##webpals"],
server: "irc.libera.chat",
port: 6667,
botName: "blotbotboot",
};
// create the bot name
let bot = new irc.Client(config.server, config.botName, {
channels: config.channels,
});
// listen for commands
bot.addListener("message", function (from, to, text, message) {
if (text.startsWith(",echo")) {
const content = text.substring(6); // where 6 is the length of the trigger command, !echo + 1 space
bot.say(to, content); // to ensures that the response goes to the channel the message was sent on
} else if (text.startsWith(",pm")) {
bot.say(from, "yes?"); // from makes this response a private message to the sender
} else if (text.startsWith(",lisp")) {
const code = text.substring(6); // FIXME: if lisp crashes so does the bot
const ret = lisp.interpret(lisp.parse(code));
bot.say(to, ret);
}
});
// run w/
// $ node bot.js