irc_bot/index.js

54 lines
1.1 KiB
JavaScript

import { Client } from "irc-framework";
import InitDB from "./components/db.js";
import Weather from "./components/Weather.js";
import UrlTitle from "./components/UrlTitle.js";
import Roll from "./components/Roll.js";
import Help from "./components/Help.js";
InitDB();
function middleware() {
return function (client, raw_events, parsed_events) {
parsed_events.use(title);
};
function title(command, event, client, next) {
if (command === "message") {
UrlTitle(event);
}
next();
}
}
const bot = new Client();
bot.use(middleware());
bot.connect({
// host: "irc.libera.chat",
host: "localhost",
nick: "g-bot",
port: 6667,
version: "grizzlys bot",
username: "g-bot",
gecos: "g-bot",
});
bot.on("registered", () => {
console.log("Connected!");
bot.join("#grizzly");
});
bot.on("close", () => {
console.log("Connection close");
});
bot.matchMessage(/^,w/, async (event) => {
return Weather(event);
});
bot.matchMessage(/^,r/, async (event) => {
return Roll(event);
});
bot.matchMessage(/^,help/, (event) => {
return Help(event);
});