From 4c1f24143cf739f8da603bca7bd3c737a0fa4068 Mon Sep 17 00:00:00 2001 From: gor_down Date: Sat, 30 Nov 2024 17:48:03 -0300 Subject: [PATCH] init --- .gitignore | 2 ++ index.js | 80 +++++++++++++++++++++++++++++++++++++++++ package-lock.json | 82 +++++++++++++++++++++++++++++++++++++++++++ package.json | 15 ++++++++ process.json | 6 ++++ settings.json | 5 +++ settings_example.json | 5 +++ 7 files changed, 195 insertions(+) create mode 100644 .gitignore create mode 100644 index.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 process.json create mode 100644 settings.json create mode 100644 settings_example.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3452843 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +logs +node_modules \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..455b540 --- /dev/null +++ b/index.js @@ -0,0 +1,80 @@ +const fs = require('fs') +const irc = require('irc'); +const settings = JSON.parse(fs.readFileSync('settings.json')); +const readline = require('readline') +const model = 'user,date,message' + +let currentChannel = settings.channels[0] + +const client = new irc.Client(settings.server, settings.username, { + channels: settings.channels, + autoRejoin: true, + retryCount: 100000000, + retryDelay: 2*60*1000, + // secure: true, + // certExpired: true, + // selfSigned: true +}); + +client.addListener('registered', () => { + + client.addListener('error', (message) => { + console.log('Error: ' + message) + }) + + client.addListener('message', function (from, channel, message) { + if (channel === settings.username) return + logMessage(from, channel, message) + }); + + client.addListener('join', (channel, nick) => { + logMessage(nick, channel, "Joined the channel") + if (nick === settings.username) sendMessage(channel, "# Appears as Jhenna_Hina.http://www.mermeliz.com/hina/dl/Jhenna_Hina.AVB") + }) + + client.addListener('quit', (channel, nick, by, reason) => { + logMessage(nick, channel, "Kicked by: " + by + ": " + reason) + }) + + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + + function messagePrompt(){ + rl.question(settings.username + ': ', (command) => { + sendMessage(currentChannel, command) + messagePrompt() + }); + } + + function logMessage(from, channel, message){ + const currentDate = new Date(); + ////////////////////////////////////////////////////////////////DATE FORMAT + const year = currentDate.getFullYear(); + const month = String(currentDate.getMonth() + 1).padStart(2, '0'); + const day = String(currentDate.getDate()).padStart(2, '0'); + const hours = String(currentDate.getHours()).padStart(2, '0'); + const minutes = String(currentDate.getMinutes()).padStart(2, '0'); + const seconds = String(currentDate.getSeconds()).padStart(2, '0'); + + //////////////////////////////////////////////////////////////// + const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; + const filename = 'logs/' + channel + '.csv' + + if (!fs.existsSync(filename)){ + fs.writeFileSync(filename, model) + } + + fs.appendFileSync(filename, `\n${from},${formattedDate},"${message}"`) + if(from !== settings.username)console.log(`${from}: ${message}`) + } + + function sendMessage(channel, message){ + logMessage(settings.username, channel, message) + client.say(channel, message) + } + + rl.prompt(); + messagePrompt() +}) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..e0c0523 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,82 @@ +{ + "name": "true-irc-logger", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "true-irc-logger", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "irc": "^0.5.2", + "readline": "^1.3.0" + } + }, + "node_modules/iconv": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/iconv/-/iconv-2.2.3.tgz", + "integrity": "sha512-evIiYeKdt5nEGYKNkQcGPQy781sYgbBKi3gEkt1s4CwteCdOHSjGGRyyp6lP8inYFZwvzG3lgjXEvGUC8nqQ5A==", + "hasInstallScript": true, + "license": "ISC", + "optional": true, + "dependencies": { + "nan": "^2.3.5" + }, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/irc": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/irc/-/irc-0.5.2.tgz", + "integrity": "sha512-KnrvkV05Y71SWmRWHtnlWEIH7LA/YeDul6l7tncCGLNEw4B6Obtmkatb3ACnSLj0kOJ6UBiuhss9e+eRG3zlxw==", + "license": "GPL-3.0", + "dependencies": { + "irc-colors": "^1.1.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "optionalDependencies": { + "iconv": "~2.2.1", + "node-icu-charset-detector": "~0.2.0" + } + }, + "node_modules/irc-colors": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/irc-colors/-/irc-colors-1.5.0.tgz", + "integrity": "sha512-HtszKchBQTcqw1DC09uD7i7vvMayHGM1OCo6AHt5pkgZEyo99ClhHTMJdf+Ezc9ovuNNxcH89QfyclGthjZJOw==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/nan": { + "version": "2.22.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.22.0.tgz", + "integrity": "sha512-nbajikzWTMwsW+eSsNm3QwlOs7het9gGJU5dDZzRTQGk03vyBOauxgI4VakDzE0PtsGTmXPsXTbbjVhRwR5mpw==", + "license": "MIT", + "optional": true + }, + "node_modules/node-icu-charset-detector": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/node-icu-charset-detector/-/node-icu-charset-detector-0.2.0.tgz", + "integrity": "sha512-DYOFJ3NfKdxEi9hPbmoCss6WydGhJsxpSleUlZfAWEbZt3AU7JuxailgA9tnqQdsHiujfUY9VtDfWD9m0+ThtQ==", + "hasInstallScript": true, + "optional": true, + "dependencies": { + "nan": "^2.3.3" + }, + "engines": { + "node": ">=0.6" + } + }, + "node_modules/readline": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz", + "integrity": "sha512-k2d6ACCkiNYz222Fs/iNze30rRJ1iIicW7JuX/7/cozvih6YCkFZH+J6mAFDVgv0dRBaAyr4jDqC95R2y4IADg==", + "license": "BSD" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..5bb3f34 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "true-irc-logger", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "irc": "^0.5.2", + "readline": "^1.3.0" + } +} diff --git a/process.json b/process.json new file mode 100644 index 0000000..2dd2cb2 --- /dev/null +++ b/process.json @@ -0,0 +1,6 @@ +{ + "script": "index.js", + "name": "irc-logger", + "watch": true, + "ignore_watch": ["public", "node_modules", "package.json", "package-lock.json", ".git", "logs"] + } \ No newline at end of file diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..d62bdea --- /dev/null +++ b/settings.json @@ -0,0 +1,5 @@ +{ + "username": "G0R-D0WN", + "server": "irc.koshka.love", + "channels": ["#niggarts"] +} \ No newline at end of file diff --git a/settings_example.json b/settings_example.json new file mode 100644 index 0000000..d62bdea --- /dev/null +++ b/settings_example.json @@ -0,0 +1,5 @@ +{ + "username": "G0R-D0WN", + "server": "irc.koshka.love", + "channels": ["#niggarts"] +} \ No newline at end of file