Skip to content

Commit 6bd9a9f

Browse files
committed
add new ideas and move ideas to funding when 2/3+ leaders voted
1 parent c39c8de commit 6bd9a9f

7 files changed

+261
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
package-lock.json

ideas/andreigolemsky34_4992r6udnee.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Scottish tribal pipes & drums band Clanadonia playing "Ya Bassa" during St Andrew's Day event 2019
2+
## andreigolemsky34
3+
## https://d.tube/#!/v/andreigolemsky34/4992r6udnee
4+
5+
Scottish pipes and drums group Clanadonia, performing "Ya Bassa" from their first album 'Keepin' it tribal' during the 2019 St Andrew's Day celebrations in Perth City centre, Scotland.
6+
7+
Clanadonia, led by Tu-Bardh Stormcrow Wilson, with their high energy blend of tribal rhythms, bagpipes and mayhem have thrilled audiences across the world and their music has featured in Outlander. For more details or their music CDs and downloads please see their website: http://www.clanadonia.co.uk/
8+
9+
Voted by:
10+
0/11

ideas/firayumni99_qizc53n24fv.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# My First Time Watching NCT 127 Recent Release ~ Stiker
2+
## firayumni99
3+
## https://d.tube/#!/v/firayumni99/qizc53n24fv
4+
5+
What am I, i feel like we supposed to feel boug this fong
6+
7+
Voted by: dtube
8+
0/11

index.html

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>DTube Governance</title>
8+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/build/pure-min.css" integrity="sha384-Uu6IeWbM+gzNVXJcM9XV3SohHtmWE+3VGi496jvgX1jyvDTXfdK+rfZc8C1Aehk5" crossorigin="anonymous">
9+
</head>
10+
<body>
11+
<center>
12+
<h1>DTube Gov</h1>
13+
<div class="pure-menu pure-menu-horizontal pure-menu-scrollable">
14+
<ul class="pure-menu-list">
15+
<li class="pure-menu-item">
16+
<a href="#" class="pure-menu-link">All</a>
17+
</li>
18+
<li class="pure-menu-item">
19+
<a href="#ideas" class="pure-menu-link">Ideas</a>
20+
</li>
21+
<li class="pure-menu-item">
22+
<a href="#funding" class="pure-menu-link">Funding</a>
23+
</li>
24+
<li class="pure-menu-item">
25+
<a href="#progress" class="pure-menu-link">In progress</a>
26+
</li>
27+
<li class="pure-menu-item">
28+
<a href="#completed" class="pure-menu-link">Completed</a>
29+
</li>
30+
</ul>
31+
</div>
32+
33+
<table class="pure-table">
34+
<thead>
35+
<tr>
36+
<th>Category</th>
37+
<th>Author</th>
38+
<th>Proposal</th>
39+
<th>Progress</th>
40+
</tr>
41+
</thead>
42+
<tbody>
43+
##TBODY##
44+
</tbody>
45+
</table>
46+
</center>
47+
</body>
48+
</html>

index.js

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
const javalon = require('javalon')
2+
const fs = require('fs')
3+
const tag = 'music'
4+
let activeLeaders = []
5+
let two_third
6+
7+
// startup
8+
generateIndex()
9+
ideaToFunding(function() {
10+
addNewIdeas(function() {})
11+
})
12+
13+
// setInterval(generateIndex, 60000)
14+
// setInterval(ideaToFunding, 60000)
15+
// setInterval(addNewIdeas, 60000)
16+
17+
function generateIndex() {
18+
let scannedFolders = 0
19+
let folders = [
20+
'ideas',
21+
'funding',
22+
'progress',
23+
'complete'
24+
]
25+
let proposals = []
26+
27+
for (let i = 0; i < folders.length; i++) {
28+
let folder = folders[i]
29+
let files = fs.readdirSync(folder)
30+
for (let y = 0; y < files.length; y++) {
31+
let text = fs.readFileSync('./'+folder+'/'+files[y]).toString()
32+
let lastLine = text.split('\n')[text.split('\n').length-1]
33+
let progress = lastLine.split('/')[0] / lastLine.split('/')[1]
34+
progress = Math.round(progress*100)/100
35+
36+
proposals.push({
37+
id: files[y],
38+
author: text.split('\n')[1].split('## ')[1],
39+
title: text.split('\n')[0].split('# ')[1],
40+
progress: progress+'%',
41+
category: folder,
42+
})
43+
}
44+
}
45+
46+
let index = fs.readFileSync('index.html').toString()
47+
let tbody = ''
48+
for (let i = 0; i < proposals.length; i++) {
49+
tbody += '<tr>'
50+
tbody += '<td>'+proposals[i].category+'</td>'
51+
tbody += '<td>'+proposals[i].author+'</td>'
52+
tbody += '<td>'+proposals[i].title+'</td>'
53+
tbody += '<td>'+proposals[i].progress+'</td>'
54+
}
55+
index = index.replace('##TBODY##', tbody)
56+
fs.writeFileSync('./public/index.html', index)
57+
}
58+
59+
function ideaToFunding(cb) {
60+
javalon.getSchedule(function(err, leaders) {
61+
// list active leaders
62+
for (let i = 0; i < leaders.shuffle.length; i++)
63+
activeLeaders.push(leaders.shuffle[i].name)
64+
65+
// compute 2/3+ threshold
66+
two_third = Math.ceil(activeLeaders.length * 2 / 3)
67+
if (two_third == activeLeaders.length * 2 / 3)
68+
two_third++
69+
70+
// count leader votes for each current idea
71+
let files = fs.readdirSync('ideas')
72+
for (let i = 0; i < files.length; i++) {
73+
let filename = files[i]
74+
let text = fs.readFileSync('./ideas/'+files[i]).toString()
75+
let author = files[i].split('_')[0]
76+
let link = files[i].split('_')[1].split('.')[0]
77+
javalon.getContent(author, link, function(err, content) {
78+
let votedLeaders = []
79+
for (let y = 0; y < content.votes.length; y++)
80+
if (activeLeaders.indexOf(content.votes[y].u) > -1)
81+
votedLeaders.push(content.votes[y].u)
82+
83+
text = text.split('\n')
84+
text[text.length-2] = 'Voted by: '+votedLeaders.join(', ')
85+
text = text.join('\n')
86+
fs.writeFileSync('./ideas/'+files[i], text)
87+
88+
// if content passed the threshold, move it to funding
89+
if (votedLeaders.length >= two_third)
90+
fs.rename('./ideas/'+filename, './funding/'+filename)
91+
})
92+
}
93+
cb()
94+
})
95+
}
96+
97+
function addNewIdeas(cb) {
98+
if (!two_third) return
99+
let files = fs.readdirSync('ideas')
100+
javalon.getNewDiscussions(null, null, function(err, contents) {
101+
let newContents = []
102+
for (let i = 0; i < contents.length; i++) {
103+
if (contents[i].votes[0].tag === tag) {
104+
let newIdea = contents[i]
105+
let text = '# '
106+
text += newIdea.json.title+'\n'
107+
text += '## '+newIdea.author+'\n'
108+
text += '## https://d.tube/#!/v/'+newIdea.author+'/'+newIdea.link+'\n\n'
109+
text += newIdea.json.desc+'\n\n'
110+
text += 'Voted by: '+'\n'
111+
text += '0/'+two_third
112+
113+
let filename = newIdea.author+'_'+newIdea.link+'.md'
114+
115+
if (files.indexOf(filename) === -1)
116+
fs.writeFileSync('./ideas/'+filename, text)
117+
}
118+
}
119+
cb()
120+
})
121+
}

package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "governance",
3+
"version": "1.0.0",
4+
"description": "A community-powered governance system for DTube",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"gen": "node generate.js"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/dtube/governance.git"
13+
},
14+
"author": "Adrien M",
15+
"license": "MIT",
16+
"bugs": {
17+
"url": "https://github.com/dtube/governance/issues"
18+
},
19+
"homepage": "https://github.com/dtube/governance#readme",
20+
"dependencies": {
21+
"javalon": "^1.0.34",
22+
"secp256k1": "^4.0.2"
23+
}
24+
}

public/index.html

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>DTube Governance</title>
8+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/build/pure-min.css" integrity="sha384-Uu6IeWbM+gzNVXJcM9XV3SohHtmWE+3VGi496jvgX1jyvDTXfdK+rfZc8C1Aehk5" crossorigin="anonymous">
9+
</head>
10+
<body>
11+
<center>
12+
<h1>DTube Gov</h1>
13+
<div class="pure-menu pure-menu-horizontal pure-menu-scrollable">
14+
<ul class="pure-menu-list">
15+
<li class="pure-menu-item">
16+
<a href="#" class="pure-menu-link">All</a>
17+
</li>
18+
<li class="pure-menu-item">
19+
<a href="#ideas" class="pure-menu-link">Ideas</a>
20+
</li>
21+
<li class="pure-menu-item">
22+
<a href="#funding" class="pure-menu-link">Funding</a>
23+
</li>
24+
<li class="pure-menu-item">
25+
<a href="#progress" class="pure-menu-link">In progress</a>
26+
</li>
27+
<li class="pure-menu-item">
28+
<a href="#completed" class="pure-menu-link">Completed</a>
29+
</li>
30+
</ul>
31+
</div>
32+
33+
<table class="pure-table">
34+
<thead>
35+
<tr>
36+
<th>Category</th>
37+
<th>Author</th>
38+
<th>Proposal</th>
39+
<th>Progress</th>
40+
</tr>
41+
</thead>
42+
<tbody>
43+
<tr><td>ideas</td><td>andreigolemsky34</td><td>Scottish tribal pipes & drums band Clanadonia playing "Ya Bassa" during St Andrew's Day event 2019</td><td>0%</td><tr><td>ideas</td><td>firayumni99</td><td>My First Time Watching NCT 127 Recent Release ~ Stiker</td><td>0%</td>
44+
</tbody>
45+
</table>
46+
</center>
47+
</body>
48+
</html>

0 commit comments

Comments
 (0)