Skip to content

Commit

Permalink
feat: Improve weather alerts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Moffitt committed Jan 14, 2022
1 parent 18bbce1 commit 27ec0da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
20 changes: 13 additions & 7 deletions modules/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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']))
}
}
}
}
Expand Down

0 comments on commit 27ec0da

Please sign in to comment.