mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 22:23:03 -04:00
quick units, add kelvin support
This commit is contained in:
parent
f910be7ab7
commit
9eeb7f2721
3 changed files with 46 additions and 17 deletions
|
@ -11,12 +11,14 @@ const { ApplicationCommandOptionTypes } = require('detritus-client/lib/constants
|
|||
|
||||
const modifiers = {
|
||||
"°C": (i)=>i,
|
||||
"°F": (i)=>(i*(9/5))+32
|
||||
"°F": (i)=>(i*(9/5))+32,
|
||||
"K": (i)=>i+273.15
|
||||
}
|
||||
|
||||
const unitNames = {
|
||||
"°C": "Celcius",
|
||||
"°F": "Fahrenheit"
|
||||
"°F": "Fahrenheit",
|
||||
"K": "Kelvin"
|
||||
}
|
||||
|
||||
function temperature(value, units){
|
||||
|
@ -54,7 +56,7 @@ function renderWeatherCard(context, data, units){
|
|||
if(data.result.warnings.length >= 1){
|
||||
for(const w of [data.result.warnings[0]]){
|
||||
if(description.includes(stringwrap(w.label, 50))) continue;
|
||||
description += `\n\n${icon("weather_warning_" + (w.icon || "generic").toLowerCase())} **${stringwrap(w.label, 50)}**\n-# ${stringwrap(w.source, 50)} • ${link(w.url, "Learn More", "Learn more about this alert")}`
|
||||
description += `\n\n${icon("weather_warning_" + (w.icon || "generic").toLowerCase())} **${stringwrap(w.label, 50)}**\n-# ${stringwrap(w.source, 50)} • ${link(w.url, "Learn More", "Learn more about this alert")}`
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,6 +120,10 @@ module.exports = {
|
|||
{
|
||||
value: "fahrenheit",
|
||||
name: "Fahrenheit"
|
||||
},
|
||||
{
|
||||
value: "kelvin",
|
||||
name: "Kelvin"
|
||||
}
|
||||
],
|
||||
required: false
|
||||
|
@ -139,11 +145,15 @@ module.exports = {
|
|||
data = data.response.body
|
||||
|
||||
let units = ["°C", "°F"]
|
||||
if(args.units) if(["f","fahrenheit","°f"].includes(args.units.toLowerCase())) units = ["°F", "°C"]
|
||||
if(args.units){
|
||||
if(args.units == "fahrenheit") units = ["°F"]
|
||||
else if (args.units == "kelvin") units = ["K"]
|
||||
}
|
||||
|
||||
let pages = []
|
||||
pages.push(page(renderWeatherCard(context, data, units[0])))
|
||||
pages.push(page(renderWeatherCard(context, data, units[1])))
|
||||
for(const u of units) pages.push(page(renderWeatherCard(context, data, u)))
|
||||
|
||||
if(pages.length == 1) return editOrReply(context, pages[0])
|
||||
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
|
|
|
@ -2,7 +2,7 @@ const { paginator } = require('#client');
|
|||
|
||||
const { createEmbed, page, formatPaginationEmbeds } = require("#utils/embed");
|
||||
const { guildFeaturesField } = require("#utils/fields");
|
||||
const { icon, highlight, timestamp, codeblock, iconPill, smallIconPill } = require("#utils/markdown");
|
||||
const { icon, highlight, timestamp, codeblock, smallIconPill } = require("#utils/markdown");
|
||||
const { editOrReply } = require("#utils/message");
|
||||
|
||||
// TODO: Turn this into a general purpose permissions constant
|
||||
|
|
|
@ -11,12 +11,14 @@ const { Permissions } = require("detritus-client/lib/constants");
|
|||
|
||||
const modifiers = {
|
||||
"°C": (i)=>i,
|
||||
"°F": (i)=>(i*(9/5))+32
|
||||
"°F": (i)=>(i*(9/5))+32,
|
||||
"K": (i)=>i+273.15
|
||||
}
|
||||
|
||||
const unitNames = {
|
||||
"°C": "Celcius",
|
||||
"°F": "Fahrenheit"
|
||||
"°F": "Fahrenheit",
|
||||
"K": "Kelvin"
|
||||
}
|
||||
|
||||
function temperature(value, units){
|
||||
|
@ -54,7 +56,7 @@ function renderWeatherCard(context, data, units){
|
|||
if(data.result.warnings.length >= 1){
|
||||
for(const w of [data.result.warnings[0]]){
|
||||
if(description.includes(stringwrap(w.label, 50))) continue;
|
||||
description += `\n\n${icon("weather_warning_" + (w.icon || "generic").toLowerCase())} **${stringwrap(w.label, 50)}**\n-# ${stringwrap(w.source, 50)} • ${link(w.url, "Learn More", "Learn more about this alert")}`
|
||||
description += `\n\n${icon("weather_warning_" + (w.icon || "generic").toLowerCase())} **${stringwrap(w.label, 50)}**\n-# ${stringwrap(w.source, 50)} • ${link(w.url, "Learn More", "Learn more about this alert")}`
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,6 +90,15 @@ function renderWeatherCard(context, data, units){
|
|||
return e;
|
||||
}
|
||||
|
||||
let quickUnits = [
|
||||
{ value: "-f", units: "°F" },
|
||||
{ value: "-c", units: "°C" },
|
||||
{ value: "-k", units: "K" },
|
||||
{ value: "-fahrenheit", units: "°F" },
|
||||
{ value: "-celcius", units: "°C" },
|
||||
{ value: "-kelvin", units: "K" }
|
||||
]
|
||||
|
||||
module.exports = {
|
||||
name: 'weather',
|
||||
aliases: ['forecast'],
|
||||
|
@ -95,9 +106,9 @@ module.exports = {
|
|||
metadata: {
|
||||
description: 'Displays information about the weather.',
|
||||
description_short: 'Local weather information',
|
||||
examples: ['weather Otter, Germany -t f'],
|
||||
examples: ['weather Otter, Germany -t f','weather Mountain View -k'],
|
||||
category: 'utils',
|
||||
usage: 'weather <location> [-t <c|f>',
|
||||
usage: 'weather <location> [-t <c|f> OR -c, -f, -k]',
|
||||
slashCommand: "weather"
|
||||
},
|
||||
args: [
|
||||
|
@ -108,17 +119,25 @@ module.exports = {
|
|||
context.triggerTyping();
|
||||
if(!args.query) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (location).`))
|
||||
try{
|
||||
// Quick Units
|
||||
let units = ["°C", "°F"]
|
||||
if(["f","fahrenheit","°f"].includes(args.t.toLowerCase())) units = ["°F", "°C"]
|
||||
|
||||
for(const u of quickUnits){
|
||||
if(args.query.endsWith(u.value)){
|
||||
args.query = args.query.substr(0, args.query.length - 3)
|
||||
units = [u.units]
|
||||
}
|
||||
}
|
||||
|
||||
let data = await darksky(context, args.query)
|
||||
|
||||
data = data.response.body
|
||||
|
||||
let units = ["°C", "°F"]
|
||||
if(["f","fahrenheit","°f"].includes(args.t.toLowerCase())) units = ["°F", "°C"]
|
||||
|
||||
let pages = []
|
||||
pages.push(page(renderWeatherCard(context, data, units[0])))
|
||||
pages.push(page(renderWeatherCard(context, data, units[1])))
|
||||
for(const u of units) pages.push(page(renderWeatherCard(context, data, u)))
|
||||
|
||||
if(pages.length == 1) return editOrReply(context, pages[0])
|
||||
await paginator.createPaginator({
|
||||
context,
|
||||
pages,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue