46 lines
936 B
JavaScript
46 lines
936 B
JavaScript
|
import { Client } from "irc-framework";
|
||
|
import Save from "./Save.js";
|
||
|
|
||
|
function middleware() {
|
||
|
return function (client, raw_events, parsed_events) {
|
||
|
parsed_events.use(log);
|
||
|
};
|
||
|
|
||
|
function log(command, event, client, next) {
|
||
|
const formatTime = (i) => {
|
||
|
return (i = i < 10 ? "0" + i : i);
|
||
|
};
|
||
|
|
||
|
const time = new Date();
|
||
|
let h = formatTime(time.getHours());
|
||
|
let m = formatTime(time.getMinutes());
|
||
|
|
||
|
if (command === "message") {
|
||
|
if (event.nick)
|
||
|
Save(event.target, `${h}:${m} < ${event.nick}> ${event.message}`);
|
||
|
}
|
||
|
|
||
|
next();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const bot = new Client();
|
||
|
bot.use(middleware());
|
||
|
bot.connect({
|
||
|
host: "localhost",
|
||
|
nick: "g-itz",
|
||
|
port: 6667,
|
||
|
version: "g-itz",
|
||
|
username: "g-itz",
|
||
|
gecos: "g-itz",
|
||
|
});
|
||
|
bot.on("registered", () => {
|
||
|
console.log("Connected!");
|
||
|
bot.join("#grizzly");
|
||
|
bot.join("#grizzly2");
|
||
|
});
|
||
|
|
||
|
bot.on("close", () => {
|
||
|
console.log("Connection close");
|
||
|
});
|