mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-09 14:43:05 -04:00
weather v2
This commit is contained in:
parent
a06f24d643
commit
911d28c46b
4 changed files with 65 additions and 60 deletions
|
@ -1,60 +0,0 @@
|
||||||
const { createEmbed } = require('../../../labscore/utils/embed')
|
|
||||||
const { editOrReply } = require('../../../labscore/utils/message')
|
|
||||||
const { STATICS } = require('../../../labscore/utils/statics')
|
|
||||||
|
|
||||||
const { weather } = require('../../../labscore/api');
|
|
||||||
const { pill, icon } = require('../../../labscore/utils/markdown');
|
|
||||||
|
|
||||||
const { Permissions } = require("detritus-client/lib/constants");
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: 'weather',
|
|
||||||
aliases: ['forecast'],
|
|
||||||
label: 'query',
|
|
||||||
metadata: {
|
|
||||||
description: 'Displays information about the weather.',
|
|
||||||
description_short: 'Local weather information',
|
|
||||||
examples: ['weather Otter, Germany'],
|
|
||||||
category: 'search',
|
|
||||||
usage: 'weather <location>'
|
|
||||||
},
|
|
||||||
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
|
||||||
run: async (context, args) => {
|
|
||||||
context.triggerTyping();
|
|
||||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (location).`)]})
|
|
||||||
try{
|
|
||||||
let data = await weather(context, args.query)
|
|
||||||
|
|
||||||
data = data.response.body
|
|
||||||
|
|
||||||
let e = createEmbed("default", context, {
|
|
||||||
description: `**${data.name}** ${pill(data.temperature.celcius.main)} ${pill(data.temperature.fahrenheit.main)}\n*${data.display.name}, ${data.display.description}*`,
|
|
||||||
fields: [{
|
|
||||||
name: `${icon("upvote")} Maximum Temperature`,
|
|
||||||
value: `${pill(data.temperature.celcius.max)} ${pill(data.temperature.fahrenheit.max)}\n\n${icon("downvote")} **Minimum Temperature**\n${pill(data.temperature.celcius.min)} ${pill(data.temperature.fahrenheit.min)}`,
|
|
||||||
inline: true
|
|
||||||
},{
|
|
||||||
name: `Humidity`,
|
|
||||||
value: `${pill(data.misc.humidity)}\n\n**Felt Temperature**\n${pill(data.temperature.celcius.feels_like)} ${pill(data.temperature.fahrenheit.feels_like)}`,
|
|
||||||
inline: true
|
|
||||||
},{
|
|
||||||
name: `Wind Speed`,
|
|
||||||
value: `${pill(data.wind.speed)}\n\n**Wind Direction**\n${pill(data.wind.degree + '°')}`,
|
|
||||||
inline: false
|
|
||||||
}],
|
|
||||||
thumbnail: {
|
|
||||||
url: data.display.icon
|
|
||||||
},
|
|
||||||
footer: {
|
|
||||||
iconUrl: STATICS.openweathermap,
|
|
||||||
text: `OpenWeatherMap • ${context.application.name}`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return editOrReply(context, {embeds: [e]})
|
|
||||||
}catch(e){
|
|
||||||
console.log(e)
|
|
||||||
return editOrReply(context, {embeds:[createEmbed("warning", context, `No weather data available for given location.`)]})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
58
commands/message/utils/weather.js
Normal file
58
commands/message/utils/weather.js
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
const { createEmbed } = require('../../../labscore/utils/embed')
|
||||||
|
const { editOrReply } = require('../../../labscore/utils/message')
|
||||||
|
|
||||||
|
const { darksky } = require('../../../labscore/api');
|
||||||
|
const { pill, iconPill, smallIconPill, smallPill, icon } = require('../../../labscore/utils/markdown');
|
||||||
|
|
||||||
|
const { Permissions } = require("detritus-client/lib/constants");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'weather',
|
||||||
|
aliases: ['forecast'],
|
||||||
|
label: 'query',
|
||||||
|
metadata: {
|
||||||
|
description: 'Displays information about the weather.',
|
||||||
|
description_short: 'Local weather information',
|
||||||
|
examples: ['weather Otter, Germany'],
|
||||||
|
category: 'utils',
|
||||||
|
usage: 'weather <location>'
|
||||||
|
},
|
||||||
|
permissionsClient: [Permissions.EMBED_LINKS, Permissions.SEND_MESSAGES, Permissions.USE_EXTERNAL_EMOJIS, Permissions.READ_MESSAGE_HISTORY],
|
||||||
|
run: async (context, args) => {
|
||||||
|
context.triggerTyping();
|
||||||
|
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (location).`)]})
|
||||||
|
try{
|
||||||
|
let data = await darksky(context, args.query)
|
||||||
|
|
||||||
|
data = data.response.body
|
||||||
|
|
||||||
|
let description = `### ${data.result.location} • ${data.result.current.condition}\n${iconPill("thermometer", data.result.current.temperature.current + "°C")} ${pill("Wind")} ${smallPill(data.result.current.wind.speed + " km/h")}`
|
||||||
|
|
||||||
|
let secondaryPills = [];
|
||||||
|
if(data.result.current.humidity > 0) secondaryPills.push(`${pill("Humidity")} ${smallPill(data.result.current.humidity)}`)
|
||||||
|
if(data.result.current.uvindex > 0) secondaryPills.push(`${pill("UV Index")} ${smallPill(data.result.current.uvindex)}`)
|
||||||
|
|
||||||
|
if(secondaryPills.length >= 1) description += '\n' + secondaryPills.join(` `)
|
||||||
|
|
||||||
|
// Render Forecasts
|
||||||
|
description += `\n`
|
||||||
|
for(const i of data.result.forecast){
|
||||||
|
description += `\n${pill(i.day)} ${smallPill(i.condition)} ${icon("thermometer")} Between ${smallPill(i.temperature.min + "°C")} and ${smallPill(i.temperature.max + "°C")} `
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let e = createEmbed("default", context, {
|
||||||
|
description,
|
||||||
|
thumbnail: {
|
||||||
|
url: data.result.current.icon
|
||||||
|
},
|
||||||
|
timestamp: new Date(data.result.current.date)
|
||||||
|
})
|
||||||
|
|
||||||
|
return editOrReply(context, {embeds: [e]})
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
return editOrReply(context, {embeds:[createEmbed("warning", context, `No weather data available for given location.`)]})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -176,6 +176,12 @@ module.exports.weather = async function(context, location){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.darksky = async function(context, location){
|
||||||
|
return await request(Api.UTILS_WEATHER, "GET", {}, {
|
||||||
|
location: location
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.wikihow = async function(context, query){
|
module.exports.wikihow = async function(context, query){
|
||||||
return await request(Api.SEARCH_WIKIHOW, "GET", {}, {
|
return await request(Api.SEARCH_WIKIHOW, "GET", {}, {
|
||||||
q: query
|
q: query
|
||||||
|
|
|
@ -191,6 +191,7 @@ module.exports.REDESIGN_ICONS = Object.freeze({
|
||||||
|
|
||||||
"generative_ai": "<:ico_generative_ai:1165258096227135498>",
|
"generative_ai": "<:ico_generative_ai:1165258096227135498>",
|
||||||
"latency": "<:ico_latency:1165258097338630235>",
|
"latency": "<:ico_latency:1165258097338630235>",
|
||||||
|
"thermometer": "<:ico_thermometer:1167576335133200414>",
|
||||||
|
|
||||||
"exclaim_0": "<:ico_exclaim_0:1165263543583649842>",
|
"exclaim_0": "<:ico_exclaim_0:1165263543583649842>",
|
||||||
"exclaim_1": "<:ico_exclaim_1:1165263545747914853>",
|
"exclaim_1": "<:ico_exclaim_1:1165263545747914853>",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue