Subj : Weather alerts to IRC room
To : ansunent
From : echicken
Date : Thu Jan 26 2023 07:58 pm
Re: Weather alerts to IRC room
By: ansunent to Digital Man on Tue Jan 24 2023 00:31:30
an> That makes sense. I'll look into what I need to use in substitution for
an> this "=>".
You've got other problems beyond incompatible syntax.
In the code that you posted, you were doing something like:
http.get(url, res => {
let data = '';
res.on('data', d => data += d);
res.on('end', () => {
// do stuff with data
});
});
I suspect you took inspiration from a rather outdated node.js example. None of this will work here. In fact a vast amount of example JS code that you find online simply won't work here without significant alteration.
You want something like:
function getWeatherAlerts(channel) {
var data = http.Get(weatherURL);
var alerts = JSON.parse(data).features;
if (alerts.length < 1) {
client.say(channel, 'No severe weather alerts at this time.');
} else {
alerts.forEach(function (alert) {
client.say(channel, alert.properties.headline);
});
}
}