-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
94 lines (79 loc) · 2.38 KB
/
test.js
File metadata and controls
94 lines (79 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const builtin = bimport("builtin")
let OPTIONS = {
"1️⃣": 0,
"2️⃣": 1,
"3️⃣": 2,
"4️⃣": 3,
"5️⃣": 4,
};
function create_pie(ctx, labels, data) {
let label_txt =String( "[");
let data_txt = String("[");
labels = Array(labels)
data = Array(data)
labels.forEach(function (value) {
label_txt += "'" + value + "'" + ",";
});
data.forEach(function (value) {
data_txt += value.toString() + ",";
});
label_txt =String.slice(label_txt,0, -1) + "]";
data_txt = String.slice(data_txt,0, -1) + "]";
let text =
"https://quickchart.io/chart?c={type:'pie',data:{labels:" +
label_txt +
",datasets:[{label:'Users',data:" +
data_txt +
"}]}}";
return text;
}
function create_pool(ctx, labels) {
labels = Array(labels);
let options = {};
let pool = {};
labels.forEach(function (value) {
Object.setitem(pool, value, 1);
});
let limit = labels.length;
let x = 0;
OPTIONS_ = Array(Object.keys(OPTIONS))
OPTIONS_.forEach(function (value) {
if (x < limit) {
Object.setitem(options, value,labels[x])
}
x++;
});
let chart_message = await(
ctx.send(
create_pie(ctx, Array(Object.keys(pool)), Array(Object.values(pool)))
)
);
function wait_vote(reaction, user) {
nol = false
if (reaction.message.id === chart_message.id && !user.bot) {
if (reaction.emoji == "❌" && user.id == ctx.user.id) {
nol = true;
} else if ((opt = options.get(reaction.emoji))) {
let reactions = Array(reaction.message.reactions)
reactions.forEach(function (value) {
if(value.emoji!="❌"){
Object.setitem(pool,Object.getitem(options,value.emoji),Number(value.count));
}
});
let pie = create_pie(ctx, Array(Object.keys(pool)), Array(Object.values(pool)))
await(chart_message.edit(builtin.KeywordArguments({content:pie})))
} else {
await(chart_message.remove_reaction(reaction.emoji, user));
}
}
return nol;
}
options_ = Array(Object.keys(options))
options_.forEach(function (value) {
await(chart_message.add_reaction(value));
});
await(chart_message.add_reaction("❌"));
result = await(bot.wait_for("reaction_add",builtin.KeywordArguments({check:wait_vote})));
await(chart_message.clear_reactions());
}
Exports.export_functions({ chart: create_pool });