Advertisement
jurjendevries

Untitled

Feb 14th, 2021
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Create the configuration
  2. var config = {
  3.         path: "/root/snap/ipfs/ircbot/", // Path to store the log file
  4.         server: "irc.freenode.net", // Hostname of the IRC server
  5.         channel: ["#logtoipfs"], // Name of the channel
  6.         botName: "logtoipfs" // Nickname of the bot
  7. };
  8.  
  9. // Get the lib for IRC
  10. var irc = require("irc");
  11.  
  12. // Get the lib for filesystem writing
  13. const fs = require('fs');
  14.  
  15. const CreateFiles = fs.createWriteStream(config.path + config.channel[0] + ".log", {
  16.       flags: 'a' //flags: 'a' preserved old data
  17. })
  18.  
  19. // Set date in ISO 8601 format
  20. var date = new Date();
  21. date.toISOString();
  22.  
  23. // Create the bot
  24. var bot = new irc.Client(config.server, config.botName, {
  25.         channels: config.channel
  26. });
  27.  
  28. // Listen for any channel message, write it to a file
  29.  bot.addListener("message" + config.channel, function(nick, text, message) {
  30.     console.log(nick + ' => ' + ': ' + text);
  31.     CreateFiles.write("{\r\n \"timestamp\": \"" + date +"\",\r\n \"channel\": \"" + config.channel +"\",\r\n \"nick\": \"" + JSON.stringify(nick) +"\",\r\n \"text\": \"" + tex
  32. t +"\"\r\n}\r\n")
  33. });
  34.  
  35. // Write errors to the console
  36. bot.addListener('error', function(message) {
  37.     console.log('error: ', message);
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement