-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
178 lines (161 loc) · 4.09 KB
/
config.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//
// If we failed to load a config from roon.load_config we will populate our
// settings object with these values
//
DefaultConfig = {
bottoken: "",
channelid: "",
announcetracks: false,
commandprefix: "!",
setpresence: true,
voicechannelid: "",
streamerid: "",
streamingzone: { output_id: "", name: "" },
localzone: { output_id: "", name: "" },
debug: false
};
var current = {};
function load(roon) {
console.log("Loading configuration cache");
current = roon.load_config("settings") || DefaultConfig;
console.log("Debugging output is " + current.debug);
}
function get(_key) {
return current[_key];
}
function set(_key, value) {
current[_key] = value;
if (current["debug"]) {
console.log("set config value for '%s' with '%s'", _key, current[_key]);
}
}
function flag(_key) {
_val = current[_key];
switch (typeof _val) {
case "boolean":
return _val;
break;
case "string":
switch (_val) {
case "true":
case "on":
case "yes":
case "1":
return true;
case "default":
return false;
}
default:
console.log(
"Unknown flag type " + _val + " (" + typeof _val + ")"
);
return false;
}
}
function update(_settings) {
console.log("Updating configuration cache");
current = _settings;
console.log("Debugging output is " + current.debug);
}
function all() {
return current;
}
// https://community.roonlabs.com/t/settings-api-can-make-a-remote-crash/35899/4?u=nugget
const fakeBoolean = [
{ title: "On", value: true },
{ title: "Off", value: false }
];
function layout(settings) {
var l = {
values: settings,
layout: [],
has_error: false
};
l.layout.push({
type: "group",
title: "Discord Server",
items: [
{
type: "string",
title: "Discord Bot Token",
setting: "bottoken"
},
{
type: "string",
title: "Text Channel ID",
setting: "channelid"
},
{
type: "dropdown",
title: "Announce plays",
values: fakeBoolean,
setting: "announcetracks"
},
{
type: "dropdown",
title: "Update Presence",
values: fakeBoolean,
setting: "setpresence"
},
{
type: "string",
title: "Command Prefix",
setting: "commandprefix"
},
]
});
l.layout.push({
type: "group",
title: "Streaming Settings",
collapsable: true,
items: [
{
type: "string",
title: "Voice Channel ID",
setting: "voicechannelid"
},
{
type: "string",
title: "Streamer User ID",
setting: "streamerid"
},
{
type: "dropdown",
title: "Link Zones",
values: fakeBoolean,
setting: "linkzones"
},
{
type: "zone",
title: "Streaming Zone",
setting: "streamingzone"
},
{
type: "zone",
title: "Local Zone",
setting: "localzone"
}
]
});
l.layout.push({
type: "group",
title: "Developer Settings",
collapsable: true,
items: [
{
type: "dropdown",
values: fakeBoolean,
title: "Debug Output",
setting: "debug"
}
]
});
return l;
}
exports.load = load;
exports.layout = layout;
exports.get = get;
exports.set = set;
exports.update = update;
exports.all = all;
exports.flag = flag;