This commit is contained in:
derpystuff 2022-10-09 23:22:17 +02:00
parent 7107108cbe
commit 974f5c6a53
5 changed files with 72 additions and 1 deletions

View file

@ -0,0 +1,55 @@
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');
module.exports = {
name: 'weather',
label: 'query',
metadata: {
description: 'Weather information.',
examples: ['weather Berlin'],
category: 'search',
usage: 'weather <location>'
},
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.`)]})
}
},
};

View file

@ -35,6 +35,7 @@ const Api = Object.freeze({
SEARCH_RULE34: '/search/booru', SEARCH_RULE34: '/search/booru',
SEARCH_TINEYE: '/search/tineye', SEARCH_TINEYE: '/search/tineye',
SEARCH_URBANDICTIONARY: '/search/urbandictionary', SEARCH_URBANDICTIONARY: '/search/urbandictionary',
SEARCH_WEATHER: '/search/weather',
SEARCH_WIKIHOW: '/search/wikihow', SEARCH_WIKIHOW: '/search/wikihow',
SEARCH_WOLFRAM_ALPHA: '/search/wolfram-alpha', SEARCH_WOLFRAM_ALPHA: '/search/wolfram-alpha',
SEARCH_YOUTUBE: '/search/youtube', SEARCH_YOUTUBE: '/search/youtube',

View file

@ -164,6 +164,12 @@ module.exports.urbandictionary = async function(context, query){
}) })
} }
module.exports.weather = async function(context, location){
return await request(Api.SEARCH_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

View file

@ -23,7 +23,11 @@ module.exports.timestamp = function(time, flag = "t"){
return `<t:${Math.floor(time/1000)}:${flag}>` return `<t:${Math.floor(time/1000)}:${flag}>`
} }
module.exports.pill = function(content){
return " **` " + content + " `**"
}
module.exports.iconPill = function(icon, content){ module.exports.iconPill = function(icon, content){
if(!ICONS[icon]) icon = "question" if(!ICONS[icon]) icon = "question"
return ICONS[icon] + " **` " + content + " `**" return ICONS[icon] + " **` " + content + " `**"
} }

View file

@ -28,6 +28,10 @@ const Statics = Object.freeze({
file: "brands/makesweet.png", file: "brands/makesweet.png",
revision: 0 revision: 0
}, },
openweathermap: {
file: "brands/openweathermap.png",
revision: 0
},
photofunia: { photofunia: {
file: "brands/photofunia.png", file: "brands/photofunia.png",
revision: 1 revision: 1
@ -88,6 +92,7 @@ module.exports.STATICS = Object.freeze({
emojipedia: staticAsset(Statics.brands.emojipedia), emojipedia: staticAsset(Statics.brands.emojipedia),
inferkit: staticAsset(Statics.brands.inferkit), inferkit: staticAsset(Statics.brands.inferkit),
makesweet: staticAsset(Statics.brands.makesweet), makesweet: staticAsset(Statics.brands.makesweet),
openweathermap: staticAsset(Statics.brands.openweathermap),
photofunia: staticAsset(Statics.brands.photofunia), photofunia: staticAsset(Statics.brands.photofunia),
reddit: staticAsset(Statics.brands.reddit), reddit: staticAsset(Statics.brands.reddit),
tineye: staticAsset(Statics.brands.tineye), tineye: staticAsset(Statics.brands.tineye),