From 8eae3b335e3df8fd004e7884b7ef1b4eb66e7e17 Mon Sep 17 00:00:00 2001 From: stephen Date: Mon, 21 Jun 2021 18:21:28 -0400 Subject: [PATCH] Adding irc_channel, and sending message on connect. --- config.ini.dist | 1 + index.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config.ini.dist b/config.ini.dist index 42ac44b..6a81efc 100644 --- a/config.ini.dist +++ b/config.ini.dist @@ -19,6 +19,7 @@ gotify_message = gotify_priority = gotify_title = gotify_url = +irc_channel = irc_nick = irc_sendto = irc_server = diff --git a/index.js b/index.js index 66acf7b..c3e9a84 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +// Dependency requirements const chalk = require('chalk'); const d2d = require('degrees-to-direction'); const express = require('express') @@ -12,6 +13,7 @@ let Parser = require('rss-parser'); let parser = new Parser(); const xmpp = require('simple-xmpp'); +// Setup config.ini const config = ini.parse(fs.readFileSync('./config.ini', 'utf-8')); const api_pass = config.api_pass; const api_url = config.api_url; @@ -34,6 +36,7 @@ const gotify_message = config.gotify_message; const gotify_priority = config.gotify_priority; const gotify_title = config.gotify_title; const gotify_url = config.gotify_url; +const irc_channel = config.irc_channel; const irc_nick = config.irc_nick; const irc_sendto = config.irc_sendto; const irc_server = config.irc_server; @@ -52,6 +55,8 @@ const vfc_url = config.vfc_url; const weather_api_key = config.weather_api_key; const weather_units = config.weather_units; + +// Initial setup var ami = new require('asterisk-manager')(asterisk_port, asterisk_host, asterisk_user, asterisk_password, false); let weather_url = `https://api.openweathermap.org/data/2.5/weather?id=${city_code}&appid=${weather_api_key}&units=${weather_units}` var client = mqtt.connect('tcp://' + mqtt_user + ':' + mqtt_password + '@' + mqtt_server); @@ -59,12 +64,18 @@ var M = new mastodon({ access_token: `${mastodon_token}`, timeout_ms: 60*1000, api_url: `${mastodon_url}`, -}) +}); +var iclient = new irc.Client('${irc_server}', '${irc_nick}', { + channels: ['${irc_channel}'], +}); + // Once we're online, we'll send a message alerting admins xmpp.on('online', function(data, to) { console.log('Connected with JID: ' + data.jid.user); xmpp.send(user_jid, "[ONLINE]", false); client.publish(mqtt_topic, mqtt_message); + iclient.join('${irc_channel}'); + iclient.say('${irc_channel}', '[ONLINE]'); M.post('statuses', { status: `${mastodon_toot}` }); app.get('/', (req, res) => res.send("Bot Online!

Bot Online!

")); app.listen(app_port, () => console.log(`Listening on ${app_port}!`));