about summary refs log tree commit diff stats
path: root/js/blotbotboot/bot.js
blob: dc115fef9deb72ea1cd71a35c2be83a3cea4122a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// 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);
    const ret = lisp.interpret(lisp.parse(code));
    bot.say(to, ret);
  }
});

// run w/
// $ node bot.js