Skip to content

Commit 47499b9

Browse files
authored
feat(plugins/community/fortune): add plugin (lowlighter#815)
1 parent ce5101a commit 47499b9

File tree

6 files changed

+106
-1
lines changed

6 files changed

+106
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!--header-->
2+
<!--/header-->
3+
4+
## ➡️ Available options
5+
6+
<!--options-->
7+
<!--/options-->
8+
9+
## ℹ️ Examples workflows
10+
11+
<!--examples-->
12+
<!--/examples-->
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- name: Fortune
2+
uses: lowlighter/metrics@latest
3+
with:
4+
filename: metrics.plugin.fortune.svg
5+
token: NOT_NEEDED
6+
base: ""
7+
plugin_fortune: yes
8+
prod:
9+
skip: true
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//Setup
2+
export default async function({q, data, imports, account}, {enabled = false} = {}) {
3+
//Plugin execution
4+
try {
5+
//Check if plugin is enabled and requirements are met
6+
if ((!enabled)||(!q.fortune))
7+
return null
8+
9+
//Load inputs
10+
imports.metadata.plugins.fortune.inputs({data, account, q})
11+
12+
//Fortunes list
13+
const fortunes = [
14+
{chance:.06, color:"#F51C6A", text:"Reply hazy"},
15+
{chance:.03, color:"#FD4D32", text:"Excellent Luck"},
16+
{chance:.16, color:"#E7890C", text:"Good Luck"},
17+
{chance:.24, color:"#BAC200", text:"Average Luck"},
18+
{chance:.16, color:"#7FEC11", text:"Bad Luck"},
19+
{chance:.06, color:"#43FD3B", text:"Good news will come to you by mail"},
20+
{chance:.06, color:"#16F174", text:"( ´_ゝ`)フーン "},
21+
{chance:.06, color:"#00CBB0", text:"キタ━━━━━━(゚∀゚)━━━━━━ !!!!"},
22+
{chance:.06, color:"#0893E1", text:"You will meet a dark handsome stranger"},
23+
{chance:.06, color:"#2A56FB", text:"Better not tell you now"},
24+
{chance:.06, color:"#6023F8", text:"Outlook good"},
25+
{chance:.04, color:"#9D05DA", text:"Very Bad Luck"},
26+
{chance:.01, color:"#D302A7", text:"Godly Luck"},
27+
]
28+
29+
//Result
30+
let [fortune] = fortunes
31+
const x = Math.random()
32+
for (let i = 0, r = 0; i < fortunes.length; i++) {
33+
if (x <= r) {
34+
fortune = fortunes[i]
35+
break
36+
}
37+
r += fortunes[i].chance
38+
}
39+
return {...fortune}
40+
}
41+
//Handle errors
42+
catch (error) {
43+
throw {error:{message:"An error occured", instance:error}}
44+
}
45+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: "🥠 Fortune"
2+
category: community
3+
description: This plugins displays a random fortune message
4+
examples:
5+
default: https://github.com/lowlighter/metrics/blob/examples/metrics.plugin.fortune.svg
6+
authors:
7+
- lowlighter
8+
supports:
9+
- user
10+
scopes: []
11+
inputs:
12+
13+
plugin_fortune:
14+
description: Enable fortune plugin
15+
type: boolean
16+
default: no

source/templates/classic/partials/_.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
"screenshot",
3636
"code",
3737
"sponsors",
38-
"poopmap"
38+
"poopmap",
39+
"fortune"
3940
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<% if (plugins.fortune) { %>
2+
<section>
3+
<h2 class="field">
4+
<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>
5+
Fortune
6+
</h2>
7+
<div class="row">
8+
<section class="largeable-column-fields">
9+
<% if (plugins.fortune.error) { %>
10+
<div class="field error">
11+
<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>
12+
<%= plugins.fortune.error.message %>
13+
</div>
14+
<% } else { %>
15+
<div class="field" style="padding-left: 31px">
16+
<b style="color: <%= plugins.fortune.color %>">Your fortune: <%= plugins.fortune.text %></b>
17+
</div>
18+
<% } %>
19+
</section>
20+
</div>
21+
</section>
22+
<% } %>

0 commit comments

Comments
 (0)