forked from RatWasHere/bmods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadMultipleChannelData_MOD.js
97 lines (88 loc) · 2.37 KB
/
loadMultipleChannelData_MOD.js
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
95
96
97
modVersion = "s.v1.0"
module.exports = {
data: {
name: "Get Channel Multiple Datas",
},
info: {
source: "https://github.com/slothyace/bmods-acedia/tree/main/Actions",
creator: "Acedia",
donate: "https://ko-fi.com/slothyacedia",
},
category: "Channel Data",
UI: [
{
element: "input",
storeAs: "label",
name: "Label (optional)",
},
"-",
{
element: "channelInput",
storeAs: "channel",
name: "Channel",
},
{
element: "input",
storeAs: "defaultval",
name: "Default Value",
},
"-",
{
element: "menu",
storeAs: "retrievelist",
name: "List of Channel Datas",
types: {
data: "datas",
},
max: 1000,
UItypes:{
data: {
data: {},
name: "Data Name:",
preview: "`${option.data.dataname}`",
UI: [
{
element: "input",
storeAs: "dataname",
name: "Data Name",
},
{
element: "store",
storeAs: "store",
name: "Store As",
},
],
},
},
},
{
element: "text",
text: modVersion,
}
],
subtitle: (values, constants) => {
return `Label: ${values.label}, Retrieve ${values.retrievelist.length} datas of ${constants.channel(values.channel)}.`
},
compatibility: ["Any"],
async run (values, message, client, bridge) {
let storedData = bridge.data.IO.get();
let defaultVal = values.defaultval ? bridge.transf(values.defaultval) : '';
let channel = await bridge.getChannel(values.channel)
for (let item of values.retrievelist) {
let channelData = defaultVal;
const dataName = item.data.dataname;
const storeLocation = item.data.store;
try {
const transformedDataName = bridge.transf(dataName);
if (storedData.channels && storedData.channels[channel.id] && storedData.channels[channel.id][transformedDataName]) {
channelData = storedData.channels[channel.id][transformedDataName];
}
}
catch (error) {
storedData.channels[channel.id] = {};
bridge.data.IO.write(storedData);
}
bridge.store(storeLocation, channelData);
}
}
}