2024-11-30 15:48:03 -05:00
|
|
|
const fs = require('fs')
|
|
|
|
const irc = require('irc');
|
|
|
|
const readline = require('readline')
|
|
|
|
const model = 'user,date,message'
|
2024-11-30 16:44:06 -05:00
|
|
|
const { dirname } = require('path');
|
|
|
|
const rootDir = dirname(require.main.filename);
|
2024-11-30 16:45:23 -05:00
|
|
|
const settings = JSON.parse(fs.readFileSync(rootDir + '/settings.json'));
|
2024-11-30 15:48:03 -05:00
|
|
|
|
|
|
|
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}`;
|
2024-11-30 16:44:06 -05:00
|
|
|
const filename = rootDir + '/logs/' + channel + '.csv'
|
2024-11-30 15:48:03 -05:00
|
|
|
|
|
|
|
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()
|
|
|
|
})
|