chore: code formatting

This commit is contained in:
github-actions[bot]
2022-04-23 23:18:43 +00:00
parent 73cd43c18f
commit 4c98629bbc
130 changed files with 1839 additions and 1788 deletions

View File

@@ -11,19 +11,19 @@ export default async function({q, data, imports, account}, {enabled = false} = {
//Fortunes list
const fortunes = [
{chance:.06, color:"#F51C6A", text:"Reply hazy"},
{chance:.03, color:"#FD4D32", text:"Excellent Luck"},
{chance:.16, color:"#E7890C", text:"Good Luck"},
{chance:.24, color:"#BAC200", text:"Average Luck"},
{chance:.16, color:"#7FEC11", text:"Bad Luck"},
{chance:.06, color:"#43FD3B", text:"Good news will come to you by mail"},
{chance:.06, color:"#16F174", text:" ´_ゝ`)フーン "},
{chance:.06, color:"#00CBB0", text:"キタ━━━━━━(゚∀゚)━━━━━━ !!!!"},
{chance:.06, color:"#0893E1", text:"You will meet a dark handsome stranger"},
{chance:.06, color:"#2A56FB", text:"Better not tell you now"},
{chance:.06, color:"#6023F8", text:"Outlook good"},
{chance:.04, color:"#9D05DA", text:"Very Bad Luck"},
{chance:.01, color:"#D302A7", text:"Godly Luck"},
{chance: .06, color: "#F51C6A", text: "Reply hazy"},
{chance: .03, color: "#FD4D32", text: "Excellent Luck"},
{chance: .16, color: "#E7890C", text: "Good Luck"},
{chance: .24, color: "#BAC200", text: "Average Luck"},
{chance: .16, color: "#7FEC11", text: "Bad Luck"},
{chance: .06, color: "#43FD3B", text: "Good news will come to you by mail"},
{chance: .06, color: "#16F174", text: " ´_ゝ`)フーン "},
{chance: .06, color: "#00CBB0", text: "キタ━━━━━━(゚∀゚)━━━━━━ !!!!"},
{chance: .06, color: "#0893E1", text: "You will meet a dark handsome stranger"},
{chance: .06, color: "#2A56FB", text: "Better not tell you now"},
{chance: .06, color: "#6023F8", text: "Outlook good"},
{chance: .04, color: "#9D05DA", text: "Very Bad Luck"},
{chance: .01, color: "#D302A7", text: "Godly Luck"},
]
//Result
@@ -40,6 +40,6 @@ export default async function({q, data, imports, account}, {enabled = false} = {
}
//Handle errors
catch (error) {
throw {error:{message:"An error occured", instance:error}}
throw {error: {message: "An error occured", instance: error}}
}
}

View File

@@ -10,7 +10,7 @@ export default async function({q, imports, data, account}, {enabled = false} = {
let {url, datapoints, lowalert, highalert, urgentlowalert, urgenthighalert} = imports.metadata.plugins.nightscout.inputs({data, account, q})
if (!url || url === "https://example.herokuapp.com")
throw {error:{message:"Nightscout site URL isn't set!"}}
throw {error: {message: "Nightscout site URL isn't set!"}}
if (url.substring(url.length - 1) !== "/")
url += "/"
if (url.substring(0, 7) === "http://")
@@ -44,13 +44,13 @@ export default async function({q, imports, data, account}, {enabled = false} = {
resp.data[i].color = color
resp.data[i].alert = alertName
}
return {data:resp.data.reverse()}
return {data: resp.data.reverse()}
}
//Handle errors
catch (error) {
if (error.error?.message)
throw error
throw {error:{message:"An error occured", instance:error}}
throw {error: {message: "An error occured", instance: error}}
}
}

View File

@@ -7,10 +7,10 @@ export default async function({q, imports, data, account}, {enabled = false, tok
return null
if (!token)
return {poops:[], days:7}
return {poops: [], days: 7}
const {days} = imports.metadata.plugins.poopmap.inputs({data, account, q})
const {data:{poops}} = await imports.axios.get(`https://api.poopmap.net/api/v1/public_links/${token}`)
const {data: {poops}} = await imports.axios.get(`https://api.poopmap.net/api/v1/public_links/${token}`)
const filteredPoops = poops.filter(poop => {
const createdAt = new Date(poop.created_at)
@@ -18,7 +18,7 @@ export default async function({q, imports, data, account}, {enabled = false, tok
return createdAt > new Date().getTime() - days * 24 * 60 * 60 * 1000
})
const hours = {max:0}
const hours = {max: 0}
for (let i = 0; i < filteredPoops.length; i++) {
const poop = filteredPoops[i]
const hour = new Date(poop.created_at).getHours()
@@ -28,10 +28,10 @@ export default async function({q, imports, data, account}, {enabled = false, tok
}
//Results
return {poops:hours, days}
return {poops: hours, days}
}
//Handle errors
catch (error) {
throw {error:{message:"An error occured", instance:error}}
throw {error: {message: "An error occured", instance: error}}
}
}

View File

@@ -9,14 +9,14 @@ export default async function({login, q, imports, data, account}, {enabled = fal
//Load inputs
let {url, selector, title, background} = imports.metadata.plugins.screenshot.inputs({data, account, q})
if (!url)
throw {error:{message:"An url is required"}}
throw {error: {message: "An url is required"}}
//Start puppeteer and navigate to page
console.debug(`metrics/compute/${login}/plugins > screenshot > starting browser`)
const browser = await imports.puppeteer.launch()
console.debug(`metrics/compute/${login}/plugins > screenshot > started ${await browser.version()}`)
const page = await browser.newPage()
await page.setViewport({width:1280, height:1280})
await page.setViewport({width: 1280, height: 1280})
console.debug(`metrics/compute/${login}/plugins > screenshot > loading ${url}`)
await page.goto(url)
@@ -27,17 +27,17 @@ export default async function({login, q, imports, data, account}, {enabled = fal
return {x, y, width, height}
}, selector)
console.debug(`metrics/compute/${login}/plugins > screenshot > coordinates ${JSON.stringify(clip)}`)
const [buffer] = await imports.record({page, ...clip, frames:1, background})
const [buffer] = await imports.record({page, ...clip, frames: 1, background})
const screenshot = await (await imports.jimp.read(Buffer.from(buffer.split(",").pop(), "base64"))).resize(Math.min(454 * (1 + data.large), clip.width), imports.jimp.AUTO)
await browser.close()
//Results
return {image:await screenshot.getBase64Async("image/png"), title, height:screenshot.bitmap.height, width:screenshot.bitmap.width, url}
return {image: await screenshot.getBase64Async("image/png"), title, height: screenshot.bitmap.height, width: screenshot.bitmap.width, url}
}
//Handle errors
catch (error) {
if (error.error?.message)
throw error
throw {title:"Screenshot error", error:{message:"An error occured", instance:error}}
throw {title: "Screenshot error", error: {message: "An error occured", instance: error}}
}
}

View File

@@ -9,42 +9,42 @@ export default async function({login, q, imports, data, account}, {enabled = fal
//Load inputs
let {symbol, interval, duration} = imports.metadata.plugins.stock.inputs({data, account, q})
if (!token)
throw {error:{message:"A token is required"}}
throw {error: {message: "A token is required"}}
if (!symbol)
throw {error:{message:"A company stock symbol is required"}}
throw {error: {message: "A company stock symbol is required"}}
symbol = symbol.toLocaleUpperCase()
//Query API for company informations
console.debug(`metrics/compute/${login}/plugins > stock > querying api for company`)
const {data:{quoteType:{shortName:company}}} = await imports.axios.get("https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-profile", {
params:{symbol, region:"US"},
headers:{"x-rapidapi-key":token},
const {data: {quoteType: {shortName: company}}} = await imports.axios.get("https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-profile", {
params: {symbol, region: "US"},
headers: {"x-rapidapi-key": token},
})
//Query API for sotck charts
console.debug(`metrics/compute/${login}/plugins > stock > querying api for stock`)
const {data:{chart:{result:[{meta, timestamp, indicators:{quote:[{close}]}}]}}} = await imports.axios.get("https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-chart", {
params:{interval, symbol, range:duration, region:"US"},
headers:{"x-rapidapi-key":token},
const {data: {chart: {result: [{meta, timestamp, indicators: {quote: [{close}]}}]}}} = await imports.axios.get("https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-chart", {
params: {interval, symbol, range: duration, region: "US"},
headers: {"x-rapidapi-key": token},
})
const {currency, regularMarketPrice:price, previousClose:previous} = meta
const {currency, regularMarketPrice: price, previousClose: previous} = meta
//Generating chart
console.debug(`metrics/compute/${login}/plugins > stock > generating chart`)
const chart = await imports.chartist("line", {
width:480 * (1 + data.large),
height:160,
showPoint:false,
axisX:{showGrid:false, labelInterpolationFnc:(value, index) => index % Math.floor(close.length / 4) === 0 ? value : null},
axisY:{scaleMinSpace:20},
showArea:true,
width: 480 * (1 + data.large),
height: 160,
showPoint: false,
axisX: {showGrid: false, labelInterpolationFnc: (value, index) => index % Math.floor(close.length / 4) === 0 ? value : null},
axisY: {scaleMinSpace: 20},
showArea: true,
}, {
labels:timestamp.map(timestamp => new Intl.DateTimeFormat("en-GB", {month:"2-digit", day:"2-digit", hour:"2-digit", minute:"2-digit"}).format(new Date(timestamp * 1000))),
series:[close],
labels: timestamp.map(timestamp => new Intl.DateTimeFormat("en-GB", {month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit"}).format(new Date(timestamp * 1000))),
series: [close],
})
//Results
return {chart, currency, price, previous, delta:price - previous, symbol, company, interval, duration}
return {chart, currency, price, previous, delta: price - previous, symbol, company, interval, duration}
}
//Handle errors
catch (error) {
@@ -55,6 +55,6 @@ export default async function({login, q, imports, data, account}, {enabled = fal
message = `API returned ${status}${description ? ` (${description})` : ""}`
error = error.response?.data ?? null
}
throw {error:{message, instance:error}}
throw {error: {message, instance: error}}
}
}