-
Notifications
You must be signed in to change notification settings - Fork 124
/
setVar.js
44 lines (37 loc) · 1.22 KB
/
setVar.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
module.exports = async (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);
let [varname, value, table = d.client.db.tables[0]] = data.inside.splits;
value = value.addBrackets();
if (!d.client.variableManager.has(varname.addBrackets(), table))
return d.aoiError.fnError(
d,
"custom",
{},
`Variable ${varname.addBrackets()} Not Found!`,
);
const variable = d.client.variableManager.get(varname, table);
if (!variable.checkType(value))
return d.aoiError.fnError(
d,
"custom",
{inside: data.inside},
`Variable "${varname.addBrackets()}" Needs Value Of Type "${
variable.type
}". Provided Wrong Type In`,
);
value = d.client.variableManager.parseData(value, variable.type);
try {
await d.client.db.set(table, varname.addBrackets(), undefined, value);
} catch (e) {
d.aoiError.fnError(
d,
"custom",
{},
`Failed To Set Value To The Variable: "${varname.addBrackets()}" With Reason: ${e}`,
);
}
return {
code: d.util.setCode(data),
};
};