Adding irc_channel, and sending message on connect.

This commit is contained in:
Stephen Vanderwarker 2021-06-21 18:21:28 -04:00
parent 32c368da38
commit 8eae3b335e
2 changed files with 13 additions and 1 deletions

View File

@ -19,6 +19,7 @@ gotify_message =
gotify_priority =
gotify_title =
gotify_url =
irc_channel =
irc_nick =
irc_sendto =
irc_server =

View File

@ -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("<!DOCTYPE html><html><head><title>Bot Online!</title><meta name='viewport' content='width=device-width, initial-scale=1.0'/></head><body><p>Bot Online!</p></body></html>"));
app.listen(app_port, () => console.log(`Listening on ${app_port}!`));