feat(plugins/community/fortune): add plugin (#815)

This commit is contained in:
Simon Lecoq
2022-01-26 02:47:35 +01:00
committed by GitHub
parent ce5101a43f
commit 47499b95d5
6 changed files with 106 additions and 1 deletions

View File

@@ -0,0 +1,12 @@
<!--header-->
<!--/header-->
## ➡️ Available options
<!--options-->
<!--/options-->
## Examples workflows
<!--examples-->
<!--/examples-->

View File

@@ -0,0 +1,9 @@
- name: Fortune
uses: lowlighter/metrics@latest
with:
filename: metrics.plugin.fortune.svg
token: NOT_NEEDED
base: ""
plugin_fortune: yes
prod:
skip: true

View File

@@ -0,0 +1,45 @@
//Setup
export default async function({q, data, imports, account}, {enabled = false} = {}) {
//Plugin execution
try {
//Check if plugin is enabled and requirements are met
if ((!enabled)||(!q.fortune))
return null
//Load inputs
imports.metadata.plugins.fortune.inputs({data, account, q})
//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"},
]
//Result
let [fortune] = fortunes
const x = Math.random()
for (let i = 0, r = 0; i < fortunes.length; i++) {
if (x <= r) {
fortune = fortunes[i]
break
}
r += fortunes[i].chance
}
return {...fortune}
}
//Handle errors
catch (error) {
throw {error:{message:"An error occured", instance:error}}
}
}

View File

@@ -0,0 +1,16 @@
name: "🥠 Fortune"
category: community
description: This plugins displays a random fortune message
examples:
default: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.fortune.svg
authors:
- lowlighter
supports:
- user
scopes: []
inputs:
plugin_fortune:
description: Enable fortune plugin
type: boolean
default: no

View File

@@ -35,5 +35,6 @@
"screenshot", "screenshot",
"code", "code",
"sponsors", "sponsors",
"poopmap" "poopmap",
"fortune"
] ]

View File

@@ -0,0 +1,22 @@
<% if (plugins.fortune) { %>
<section>
<h2 class="field">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M9.598 1.591a.75.75 0 01.785-.175 7 7 0 11-8.967 8.967.75.75 0 01.961-.96 5.5 5.5 0 007.046-7.046.75.75 0 01.175-.786zm1.616 1.945a7 7 0 01-7.678 7.678 5.5 5.5 0 107.678-7.678z"></path></svg>
Fortune
</h2>
<div class="row">
<section class="largeable-column-fields">
<% if (plugins.fortune.error) { %>
<div class="field error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2.343 13.657A8 8 0 1113.657 2.343 8 8 0 012.343 13.657zM6.03 4.97a.75.75 0 00-1.06 1.06L6.94 8 4.97 9.97a.75.75 0 101.06 1.06L8 9.06l1.97 1.97a.75.75 0 101.06-1.06L9.06 8l1.97-1.97a.75.75 0 10-1.06-1.06L8 6.94 6.03 4.97z"></path></svg>
<%= plugins.fortune.error.message %>
</div>
<% } else { %>
<div class="field" style="padding-left: 31px">
<b style="color: <%= plugins.fortune.color %>">Your fortune: <%= plugins.fortune.text %></b>
</div>
<% } %>
</section>
</div>
</section>
<% } %>