|
|
@ -27,7 +27,26 @@ async function init() { |
|
|
|
discordClient.login(config['chat']['discord']['token']); |
|
|
|
discordClient.login(config['chat']['discord']['token']); |
|
|
|
} |
|
|
|
} |
|
|
|
if(config['chat']['irc']['enabled']){ |
|
|
|
if(config['chat']['irc']['enabled']){ |
|
|
|
|
|
|
|
ircClient = new irc.Client(config['chat']['irc']['server'], config['chat']['irc']['nickname'], { |
|
|
|
|
|
|
|
userName: config['chat']['irc']['username'], |
|
|
|
|
|
|
|
realName: config['chat']['irc']['realname'], |
|
|
|
|
|
|
|
port: config['chat']['irc']['port'], |
|
|
|
|
|
|
|
secure: config['chat']['irc']['tls'], |
|
|
|
|
|
|
|
sasl: config['chat']['irc']['sasl'], |
|
|
|
|
|
|
|
password: config['chat']['irc']['password'], |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
ircClient.addListener('error', (message) => { |
|
|
|
|
|
|
|
console.log('IRC Client Error: ', message); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
ircClient.once('registered', () => { |
|
|
|
|
|
|
|
console.log("IRC Client Ready"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
ircClient.on('message', (from, to, msg) => { |
|
|
|
|
|
|
|
var lu = getUsr(to, 'irc'); |
|
|
|
|
|
|
|
for(var i=0;i<lu.length;i++){ |
|
|
|
|
|
|
|
sendAll(lu[i], [from, msg], "irc") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
if(config['chat']['xmpp']['enabled']){ |
|
|
|
if(config['chat']['xmpp']['enabled']){ |
|
|
|
|
|
|
|
|
|
|
@ -50,6 +69,7 @@ async function updateInteg() { |
|
|
|
if(liveUsers.length === 1) { |
|
|
|
if(liveUsers.length === 1) { |
|
|
|
chatIntegration = await db.query('SELECT * FROM chat_integration WHERE username='+db.raw.escape(liveUsers[0]['username'])); |
|
|
|
chatIntegration = await db.query('SELECT * FROM chat_integration WHERE username='+db.raw.escape(liveUsers[0]['username'])); |
|
|
|
console.log('updated ci'); |
|
|
|
console.log('updated ci'); |
|
|
|
|
|
|
|
updateIRCChan(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var qs: string; |
|
|
|
var qs: string; |
|
|
@ -61,6 +81,7 @@ async function updateInteg() { |
|
|
|
chatIntegration = await db.query('SELECT * FROM chat_integration WHERE username='+qs); |
|
|
|
chatIntegration = await db.query('SELECT * FROM chat_integration WHERE username='+qs); |
|
|
|
console.log('updated integrations'); |
|
|
|
console.log('updated integrations'); |
|
|
|
console.log(chatIntegration); |
|
|
|
console.log(chatIntegration); |
|
|
|
|
|
|
|
updateIRCChan(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function sendAll(user: string, msg: Array<string>, src: string) { |
|
|
|
async function sendAll(user: string, msg: Array<string>, src: string) { |
|
|
@ -72,7 +93,7 @@ async function sendAll(user: string, msg: Array<string>, src: string) { |
|
|
|
|
|
|
|
|
|
|
|
if(user === null) return; |
|
|
|
if(user === null) return; |
|
|
|
|
|
|
|
|
|
|
|
//if(src !== "irc") sendIRC();
|
|
|
|
if(src !== "irc") sendIRC(getCh(user, "irc"), '['+src.toUpperCase()+']'+msg[0]+': '+msg[1]); |
|
|
|
//if(src !== "twitch") sendTwitch();
|
|
|
|
//if(src !== "twitch") sendTwitch();
|
|
|
|
if(src !== "discord") sendDiscord(getCh(user, "discord"), '['+src.toUpperCase()+']'+msg[0]+': '+msg[1]); |
|
|
|
if(src !== "discord") sendDiscord(getCh(user, "discord"), '['+src.toUpperCase()+']'+msg[0]+': '+msg[1]); |
|
|
|
//if(src !== "xmpp") sendXMPP();
|
|
|
|
//if(src !== "xmpp") sendXMPP();
|
|
|
@ -82,6 +103,7 @@ async function sendAll(user: string, msg: Array<string>, src: string) { |
|
|
|
async function sendIRC(channel: string, msg: string) { |
|
|
|
async function sendIRC(channel: string, msg: string) { |
|
|
|
if(!config['chat']['irc']['enabled']) return; |
|
|
|
if(!config['chat']['irc']['enabled']) return; |
|
|
|
if(channel === null) return; |
|
|
|
if(channel === null) return; |
|
|
|
|
|
|
|
ircClient.say(channel, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function sendDiscord(channel: string, msg: string) { |
|
|
|
async function sendDiscord(channel: string, msg: string) { |
|
|
@ -123,4 +145,14 @@ function getUsr(channel: string, ctype: string): Array<string>{ |
|
|
|
return list; |
|
|
|
return list; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function updateIRCChan() { |
|
|
|
|
|
|
|
var clist: Array<string> = []; |
|
|
|
|
|
|
|
for(var i=0;i<chatIntegration.length;i++){ |
|
|
|
|
|
|
|
if(chatIntegration[i]['irc'].trim() !== "" && chatIntegration[i]['irc'] !== null) clist.push(chatIntegration[i]['irc']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for(var i=0;i<clist.length;i++){ |
|
|
|
|
|
|
|
ircClient.join(clist[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export { init, sendAll }; |
|
|
|
export { init, sendAll }; |