Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create the configuration
- var config = {
- path: "/root/snap/ipfs/ircbot/", // Path to store the log file
- server: "irc.freenode.net", // Hostname of the IRC server
- channel: ["#logtoipfs"], // Name of the channel
- botName: "logtoipfs" // Nickname of the bot
- };
- // Get the lib for IRC
- var irc = require("irc");
- // Get the lib for filesystem writing
- const fs = require('fs');
- const CreateFiles = fs.createWriteStream(config.path + config.channel[0] + ".log", {
- flags: 'a' //flags: 'a' preserved old data
- })
- // Set date in ISO 8601 format
- var date = new Date();
- date.toISOString();
- // Create the bot
- var bot = new irc.Client(config.server, config.botName, {
- channels: config.channel
- });
- // Listen for any channel message, write it to a file
- bot.addListener("message" + config.channel, function(nick, text, message) {
- console.log(nick + ' => ' + ': ' + text);
- CreateFiles.write("{\r\n \"timestamp\": \"" + date +"\",\r\n \"channel\": \"" + config.channel +"\",\r\n \"nick\": \"" + JSON.stringify(nick) +"\",\r\n \"text\": \"" + tex
- t +"\"\r\n}\r\n")
- });
- // Write errors to the console
- bot.addListener('error', function(message) {
- console.log('error: ', message);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement