Created
January 7, 2023 14:39
-
-
Save AaronJackson/0ff1c78b897b974eafec85e237e490dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const IRCCloud = require('irccloud'); | |
const MQTT = require('mqtt') | |
const mqtt = MQTT.connect('mqtt://mqtt address', { | |
username: '', | |
password: '', | |
clientId: 'nodejs_irccloud', | |
}); | |
console.log(mqtt); | |
mqtt.on('connect', () => { | |
console.log('mqtt connected'); | |
mqtt.publish('irc/asjackson/notify', "nodejs irccloud started"); | |
}); | |
mqtt.on('error', (err) => { | |
console.log(err); | |
}); | |
mqtt.on('close', () => { | |
console.log('mqtt disconnect'); | |
mqtt.reconnect(); | |
}); | |
const email = "irc email"; | |
const password = "irc password"; | |
var irc = new IRCCloud(); | |
irc.connect(email, password, true); | |
irc.on('connect', () => { | |
console.log('irccloud connected') | |
}); | |
irc.on('disconnect', (code, reason, initByUs) => { | |
console.log('irccloud disconnect'); | |
if (initByUs) return; | |
irc.connect(email, password, true); | |
}); | |
irc.on('message', (buf, sender, msg, highlight) => { | |
if (!highlight) return; | |
console.log('message: ' + msg); | |
mqtt.publish('irc/asjackson/notify', "<" + sender.nick + "> " + msg); | |
}); | |
irc.on('error', (err) => { | |
console.log(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment