Advertisement
jurjendevries

Untitled

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