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,
|
2024-11-30 18:41:59 -05:00
|
|
|
userName: 'gordown',
|
|
|
|
realName: 'Gor Down',
|
2024-11-30 15:48:03 -05:00
|
|
|
autoRejoin: true,
|
|
|
|
retryCount: 100000000,
|
|
|
|
retryDelay: 2*60*1000,
|
2024-12-01 20:42:44 -05:00
|
|
|
port: 6697,
|
|
|
|
secure: true,
|
2024-12-01 20:44:35 -05:00
|
|
|
certExpired: true,
|
|
|
|
selfSigned: true
|
2024-11-30 15:48:03 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
client.addListener('registered', () => {
|
2024-11-30 22:11:50 -05:00
|
|
|
|
|
|
|
//////////////LISTENERS////////////////////
|
2024-12-03 00:48:30 -05:00
|
|
|
|
2024-11-30 15:48:03 -05:00
|
|
|
client.addListener('error', (message) => {
|
|
|
|
console.log('Error: ' + message)
|
|
|
|
})
|
|
|
|
|
|
|
|
client.addListener('message', function (from, channel, message) {
|
2024-12-03 00:48:30 -05:00
|
|
|
//DMS SENT TO THE BOT
|
|
|
|
if (channel === client.nick){
|
|
|
|
console.log("DM from " + from + ": " + message)
|
|
|
|
|
|
|
|
const args = message.split("# ")[1]
|
|
|
|
if(args){
|
|
|
|
if(args === "GetInfo") client.say(from, "# HeresInfo: japanese nationalist")
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-11-30 15:48:03 -05:00
|
|
|
logMessage(from, channel, message)
|
|
|
|
});
|
|
|
|
|
2024-11-30 22:11:50 -05:00
|
|
|
|
2024-11-30 15:48:03 -05:00
|
|
|
client.addListener('join', (channel, nick) => {
|
|
|
|
logMessage(nick, channel, "Joined the channel")
|
2024-11-30 22:11:50 -05:00
|
|
|
//I'M THE ANIME GIRL FAGGOT
|
2024-12-03 00:48:30 -05:00
|
|
|
if (nick === client.nick){
|
|
|
|
sendMessage(channel, "# Appears as Jhenna_Hina.http://www.mermeliz.com/hina/dl/Jhenna_Hina.AVB")
|
|
|
|
}else{
|
|
|
|
client.say(nick, "# Appears as Jhenna_Hina.http://www.mermeliz.com/hina/dl/Jhenna_Hina.AVB")
|
|
|
|
}
|
2024-11-30 15:48:03 -05:00
|
|
|
})
|
|
|
|
|
2024-11-30 20:22:08 -05:00
|
|
|
client.addListener('part', (channel, nick, reason, _message) => {
|
2024-12-03 00:48:30 -05:00
|
|
|
logMessage(nick, channel, `Left${reason ? ":" + reason : "."}` )
|
2024-11-30 20:22:08 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
client.addListener('quit', (nick, reason, channels, _message) => {
|
2024-11-30 20:27:18 -05:00
|
|
|
for(i in channels){
|
2024-12-03 00:48:30 -05:00
|
|
|
logMessage(nick, channels[i], `Left${reason ? ":" + reason : "."}`)
|
2024-11-30 20:22:08 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
client.addListener('kick', (channel, nick, by, reason, _message) => {
|
2024-11-30 15:48:03 -05:00
|
|
|
logMessage(nick, channel, "Kicked by: " + by + ": " + reason)
|
|
|
|
})
|
2024-11-30 22:11:50 -05:00
|
|
|
////////////////////////////////////////////////////////////////
|
2024-11-30 18:41:59 -05:00
|
|
|
|
2024-11-30 15:48:03 -05:00
|
|
|
|
2024-11-30 22:11:50 -05:00
|
|
|
|
|
|
|
///LOGGING AND SHIT/////////////////////////////////////////////
|
2024-11-30 15:48:03 -05:00
|
|
|
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){
|
2024-11-30 18:41:59 -05:00
|
|
|
|
2024-11-30 15:48:03 -05:00
|
|
|
logMessage(settings.username, channel, message)
|
|
|
|
client.say(channel, message)
|
|
|
|
}
|
2024-11-30 22:11:50 -05:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
//COMMAND LINE SHIT/////////////////////////////////
|
|
|
|
|
|
|
|
const rl = readline.createInterface({
|
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout
|
|
|
|
});
|
|
|
|
|
|
|
|
function messagePrompt(){
|
|
|
|
rl.question(settings.username + ': ', (command) => {
|
|
|
|
|
|
|
|
|
|
|
|
const split = command.split("!")
|
|
|
|
const prefix = split[0]
|
|
|
|
if(prefix === "g"){
|
|
|
|
const terminalCommand = split[1].split(' ')[0]
|
2024-12-03 00:48:30 -05:00
|
|
|
const splitArgs = split[1].split(' ')
|
|
|
|
const args = splitArgs[1] ? splitArgs[1] : ""
|
2024-11-30 22:11:50 -05:00
|
|
|
switch (terminalCommand) {
|
|
|
|
case "switch_channel":
|
|
|
|
if (!args) {
|
|
|
|
console.log("Arguments required");
|
|
|
|
break
|
|
|
|
}
|
2024-11-30 23:47:49 -05:00
|
|
|
if(!checkIfIsInChannelAndLog(args)) break
|
2024-11-30 22:11:50 -05:00
|
|
|
currentChannel = args;
|
|
|
|
console.log("Current Channel set to:", currentChannel);
|
|
|
|
break;
|
|
|
|
case "get_current_channel":
|
|
|
|
console.log(currentChannel)
|
|
|
|
break
|
2024-11-30 23:06:15 -05:00
|
|
|
case "get_users":
|
|
|
|
let channel = currentChannel
|
|
|
|
if(args){
|
2024-11-30 23:47:49 -05:00
|
|
|
if(!checkIfIsInChannelAndLog(channel)) break
|
2024-11-30 23:06:15 -05:00
|
|
|
channel = args
|
|
|
|
}
|
|
|
|
for (user in client.chans[channel].users){
|
|
|
|
console.log(user)
|
|
|
|
}
|
|
|
|
break
|
2024-12-03 00:48:30 -05:00
|
|
|
case "message":
|
|
|
|
if(!args){
|
|
|
|
console.log("Arguments required")
|
|
|
|
}
|
|
|
|
const message = getMessageFromArgs(splitArgs)
|
|
|
|
if (!message) {
|
|
|
|
console.log("Message required");
|
|
|
|
break
|
|
|
|
}
|
|
|
|
client.say(args, message)
|
|
|
|
break
|
|
|
|
case "whois":
|
|
|
|
if(!args) return console.log("Arguments required")
|
|
|
|
client.whois(args, (info) => {
|
|
|
|
console.log(info)
|
|
|
|
})
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
console.log("Comando inexistente")
|
|
|
|
break
|
2024-11-30 22:11:50 -05:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
sendMessage(currentChannel, command)
|
|
|
|
}
|
|
|
|
messagePrompt()
|
|
|
|
});
|
|
|
|
}
|
2024-11-30 15:48:03 -05:00
|
|
|
|
|
|
|
rl.prompt();
|
|
|
|
messagePrompt()
|
2024-11-30 23:47:49 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
function checkIfIsInChannelAndLog(channel){
|
|
|
|
if(!client.chans[channel]){
|
|
|
|
console.log(`You're not in that channel!`);
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
2024-12-03 00:48:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function getMessageFromArgs(splitArgs){
|
|
|
|
splitArgs.shift()
|
|
|
|
splitArgs.shift()
|
|
|
|
return splitArgs.join(" ")
|
2024-11-30 23:47:49 -05:00
|
|
|
}
|