-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathjsonAssign.ts
More file actions
45 lines (42 loc) · 1.31 KB
/
jsonAssign.ts
File metadata and controls
45 lines (42 loc) · 1.31 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
/*
* SPDX-License-Identifier: LGPL-3.0-or-later
* Copyright © 2026 BotForge
*/
import { ArgType, NativeFunction } from "../../structures/@internal/NativeFunction"
export default new NativeFunction({
name: "$jsonAssign",
version: "2.6.0",
description: "Combines multiple JSON objects into a single JSON object",
brackets: true,
unwrap: true,
args: [
{
name: "variable",
description: "The variable that holds the target object",
required: true,
type: ArgType.String,
rest: false
},
{
name: "other variable",
description: "The variable to load the result to, leave empty to return output",
type: ArgType.String,
rest: false
},
{
name: "objects",
description: "The objects from which to copy properties",
type: ArgType.Json,
required: true,
rest: true
}
],
output: ArgType.Json,
execute(ctx, [ var1, var2, objects ]) {
const json = ctx.getEnvironmentKey(var1)
if (!json) return this.success()
const obj = Object.assign(json, ...objects)
if (var2) return this.success(void ctx.setEnvironmentKey(var2, obj))
else return this.successJSON(obj)
}
})