From 89ab911ccdac219b020e1dac1f5c1fe7696cd477 Mon Sep 17 00:00:00 2001 From: John Facey Date: Tue, 5 Jul 2022 10:58:46 -0500 Subject: [PATCH] alerts added --- commands/alert.js | 28 ++++++++++++++++++++++++++++ commands/help.js | 3 ++- index.js | 2 +- libFlayer.js | 21 +++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 commands/alert.js diff --git a/commands/alert.js b/commands/alert.js new file mode 100644 index 0000000..0dcdbfc --- /dev/null +++ b/commands/alert.js @@ -0,0 +1,28 @@ +var libFlayer = require("../libFlayer.js"); + +module.exports = { + name: 'alert', + description: 'Alert', + async execute(message, args) { + try { + if (args.length < 1) { + message.reply(`Please use in !alert [state]`); + return; + } + var question = encodeURIComponent(args.join(" ")); + + var answerData = await libFlayer.weatherAlert(question); + answerData.forEach(feature => { + message.reply(` + ${feature.properties.areaDesc} + ${feature.properties.headline} + ${feature.properties.description} + `); + + }) + + } catch (err) { + message.reply(err.toString()); + } + } +}; \ No newline at end of file diff --git a/commands/help.js b/commands/help.js index 79f7e25..6ac3cfa 100644 --- a/commands/help.js +++ b/commands/help.js @@ -8,7 +8,7 @@ module.exports = { `**!help** - *Lists the available commands* **!key** - Testing remote Airtable: *!key url* **!categories** - Displays Categories: *!categories* - **!search** - Searches the RSS Sources: *!search google* + **!find** - Searches the RSS Sources: *!find google* **!get** - Retrieves Search By Index: *!get 25* **!add** - Add a new RSS Source: *!add http://www.engadget.com/rss.xml* **!update** - Updates all current RSS Feeds: *!update* @@ -20,6 +20,7 @@ module.exports = { **!stock** - AlphaVantage Stock Search: *!stock IBM* **!play** - Plays a trivia game question: *!play* **!answer** - Answers for a question above: *!answer 1* + **!alert** - Gets weather alerts for an area: *!alert TX* ` ); } diff --git a/index.js b/index.js index d6a8405..e286c47 100644 --- a/index.js +++ b/index.js @@ -85,7 +85,7 @@ client.on('interactionCreate', async interaction => { if (!interaction.isSelectMenu()) return; let aaa = interaction.values[0]; - await interaction.reply({ content: 'You picked something', ephemeral: true }); + await interaction.channel.send({ content: 'You picked something', ephemeral: true }); try { //await command.execute(interaction); diff --git a/libFlayer.js b/libFlayer.js index e342e81..e5ec49f 100644 --- a/libFlayer.js +++ b/libFlayer.js @@ -210,6 +210,27 @@ exports.loadFeeds = function () { }); } + +exports.weatherAlert = async function (state) { + + var answerURL = `https://api.weather.gov/alerts/active?area=${state}`; + console.log(answerURL); + answerData = []; + + await axios.get(answerURL) + .then(response => { + response.data.features.forEach(feature => { + answerData.push(feature); + }) + + return answerData; + }) + .catch(error => { + console.log(error); + }); + return answerData; +} + exports.search = async function (question) { var answerURL = `https://api.duckduckgo.com/?q=${question}&format=json&pretty=1`;