From 27ec0da63eb83b7833c3a810a83d7d5e2fe4bfe1 Mon Sep 17 00:00:00 2001 From: Ian Moffitt Date: Fri, 14 Jan 2022 07:46:18 -0500 Subject: [PATCH] feat: Improve weather alerts. --- index.js | 4 +--- modules/weather.js | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index e158b08..7d89d10 100644 --- a/index.js +++ b/index.js @@ -109,8 +109,6 @@ bot.on('start', function () { bot.on('message', function (data) { - // console.log(data); - if (typeof data.text !== 'undefined') { let message = data.text; @@ -159,7 +157,7 @@ bot.on('message', function (data) { }.bind(this), function (error) { let rr = [':shrug: [whoopsie: ' + error + ']']; say(rr, data.channel); - console.log(error); + console.error(error); cooldown(); }.bind(this)); diff --git a/modules/weather.js b/modules/weather.js index c227361..5356903 100644 --- a/modules/weather.js +++ b/modules/weather.js @@ -75,7 +75,7 @@ module.exports = { let response = []; - this.apiGet(lat, lon).then(function (weather) { + this.apiGet(lat, lon, false).then(function (weather) { if (allAlerts) { let daily = this.formatDay(weather); @@ -139,7 +139,7 @@ module.exports = { let response = false; - this.apiGet(lat, lon).then(function (weather) { + this.apiGet(lat, lon, true).then(function (weather) { response = true; @@ -155,7 +155,11 @@ module.exports = { }, - apiGet: function (lat, lon) { + apiGet: function (lat, lon, fillAlerts) { + + if (typeof fillAlerts === 'undefined' || fillAlerts === null) { + fillAlerts = false; + } let _this = this; @@ -184,11 +188,13 @@ module.exports = { if (typeof weather.alerts !== 'undefined') { _this.alerts = weather.alerts; - _this.sentAlerts = []; + if (fillAlerts) { + _this.sentAlerts = []; - for (var j in _this.alerts) { - if (_this.alerts.hasOwnProperty(j)) { - _this.sentAlerts.push(breiutil.slugify(_this.alerts[j]['start'] + '-' + _this.alerts[j]['end'] + '-' + _this.alerts[j]['event'])) + for (var j in _this.alerts) { + if (_this.alerts.hasOwnProperty(j)) { + _this.sentAlerts.push(breiutil.slugify(_this.alerts[j]['start'] + '-' + _this.alerts[j]['end'] + '-' + _this.alerts[j]['event'])) + } } } }