angela-sdk 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -11
- package/dist/cjs/index.js +141 -1
- package/dist/esm/index.js +138 -1
- package/dist/types/channel.d.ts +13 -0
- package/dist/types/context.d.ts +6 -0
- package/dist/types/http.d.ts +2 -0
- package/dist/types/index.d.ts +5 -2
- package/dist/types/permissions.d.ts +16 -0
- package/dist/types/timer.d.ts +8 -0
- package/dist/types/ui.d.ts +44 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ Zero external production dependencies. Requires Node 18+ for local tooling.
|
|
|
57
57
|
In `src/index.ts`:
|
|
58
58
|
|
|
59
59
|
```typescript
|
|
60
|
-
import { Game, Button, type Context } from "
|
|
60
|
+
import { Game, Button, type Context } from "angela-sdk";
|
|
61
61
|
|
|
62
62
|
const game = new Game("dice_game");
|
|
63
63
|
|
|
@@ -122,7 +122,7 @@ export function handle(eventStr: string): string {
|
|
|
122
122
|
In `main.js`:
|
|
123
123
|
|
|
124
124
|
```javascript
|
|
125
|
-
const { Game, Button } = require("
|
|
125
|
+
const { Game, Button } = require("angela-sdk");
|
|
126
126
|
|
|
127
127
|
const game = new Game("coin_toss");
|
|
128
128
|
|
|
@@ -373,7 +373,7 @@ ctx.inventory.removeSubItem(ctx.user.id, "sapphire_sardine", 1);
|
|
|
373
373
|
`ctx.ui.render()` compiles your layout automatically into the mode configured by the server (`AUTO`, `CV2`, or `CLASSIC_EMBED`):
|
|
374
374
|
|
|
375
375
|
```typescript
|
|
376
|
-
import { Button } from "
|
|
376
|
+
import { Button } from "angela-sdk";
|
|
377
377
|
|
|
378
378
|
ctx.ui.render({
|
|
379
379
|
title: "⚔️ Boss Raid: Abyssal Hydra",
|
|
@@ -405,7 +405,7 @@ import {
|
|
|
405
405
|
Separator,
|
|
406
406
|
ActionRow,
|
|
407
407
|
Button
|
|
408
|
-
} from "
|
|
408
|
+
} from "angela-sdk";
|
|
409
409
|
|
|
410
410
|
const container = new Container({ accentColor: "#5865F2" })
|
|
411
411
|
.add(
|
|
@@ -431,7 +431,7 @@ ctx.ui.renderCv2(container);
|
|
|
431
431
|
### Classic Embeds
|
|
432
432
|
|
|
433
433
|
```typescript
|
|
434
|
-
import { Embed, Button } from "
|
|
434
|
+
import { Embed, Button } from "angela-sdk";
|
|
435
435
|
|
|
436
436
|
const embed = new Embed({
|
|
437
437
|
title: "🎣 Catch of the Day",
|
|
@@ -450,7 +450,7 @@ ctx.ui.renderEmbed(embed, [
|
|
|
450
450
|
### Modals & Ephemeral Feedback
|
|
451
451
|
|
|
452
452
|
```typescript
|
|
453
|
-
import { TextInput } from "
|
|
453
|
+
import { TextInput } from "angela-sdk";
|
|
454
454
|
|
|
455
455
|
// Open modal
|
|
456
456
|
game.onButton("open_wager", (ctx) => {
|
|
@@ -473,6 +473,33 @@ game.onModal("wager_submitted", (ctx) => {
|
|
|
473
473
|
});
|
|
474
474
|
```
|
|
475
475
|
|
|
476
|
+
### Public Chat Delivery (`sendChat` vs `EDIT_MAIN`)
|
|
477
|
+
|
|
478
|
+
By default, games edit the existing game message (`target: "EDIT_MAIN"`). This keeps card tables, boards, and casino wheels compact without spamming Discord channels.
|
|
479
|
+
|
|
480
|
+
For games that announce new rounds, post trivia questions, or announce server-wide events, use `ctx.ui.sendChat(...)` or set `target: "NEW_MESSAGE"`:
|
|
481
|
+
|
|
482
|
+
```typescript
|
|
483
|
+
// Helper: sends a brand new public message to the channel
|
|
484
|
+
ctx.ui.sendChat({
|
|
485
|
+
title: "🧠 Trivia Round 1",
|
|
486
|
+
text: "What is the capital of Australia?",
|
|
487
|
+
buttons: [
|
|
488
|
+
new Button({ customId: "ans_canberra", label: "Canberra", style: "primary" }),
|
|
489
|
+
new Button({ customId: "ans_sydney", label: "Sydney", style: "secondary" }),
|
|
490
|
+
]
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
// Or using string shorthand:
|
|
494
|
+
ctx.ui.sendChat("⚔️ The boss has spawned! Click below to join the raid!");
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
| Method / Target | Visibility | Replaces Previous? | Best Used For |
|
|
498
|
+
|---|---|---|---|
|
|
499
|
+
| `target: "EDIT_MAIN"` (Default) | Public | Yes (Edits main message) | Lobbies, boards, scoreboards, casino wheels |
|
|
500
|
+
| `ctx.ui.sendChat(...)` / `target: "NEW_MESSAGE"` | Public | No (Sends new message) | Trivia rounds, event announcements, elimination logs |
|
|
501
|
+
| `ctx.ui.replyEphemeral(...)` | Only Clicker | No (Private reply) | Secret hands, balance checks, validation errors |
|
|
502
|
+
|
|
476
503
|
---
|
|
477
504
|
|
|
478
505
|
## 2D Canvas Graphics Engine
|
|
@@ -495,7 +522,7 @@ const scene = ctx.canvas.create({
|
|
|
495
522
|
Setting a `cacheKey` on static background layers caches the rendered graphic on disk — future turns skip all background pixel rendering and composite dynamic elements directly on top:
|
|
496
523
|
|
|
497
524
|
```typescript
|
|
498
|
-
import { Button } from "
|
|
525
|
+
import { Button } from "angela-sdk";
|
|
499
526
|
|
|
500
527
|
// Static background layer (cached on disk)
|
|
501
528
|
const bg = scene.layer("background", "ocean_base_v1");
|
|
@@ -626,18 +653,56 @@ ctx.media.searchGif("victory celebration", "on_gif_found");
|
|
|
626
653
|
|
|
627
654
|
---
|
|
628
655
|
|
|
629
|
-
## HTTP &
|
|
656
|
+
## HTTP & Safe Network Access
|
|
657
|
+
|
|
658
|
+
### Safe Outbound HTTP (`ctx.http.get` / `ctx.http.post`)
|
|
630
659
|
|
|
631
|
-
|
|
660
|
+
Angela games execute inside a secure WebAssembly (WASM) sandbox. Because the sandbox **does not possess raw POSIX OS sockets**, synchronous network calls (such as `fetch`, `axios`, `got`, or `node:http`) **cannot run** and will fail.
|
|
661
|
+
|
|
662
|
+
All network requests must be requested through Angela's host-mediated **two-phase HTTP gateway**:
|
|
663
|
+
1. **Phase 1 (Request)**: Your cartridge registers an intent via `ctx.http.get(url, { callback: "handler_name" })`.
|
|
664
|
+
2. **Phase 2 (Callback)**: Angela's host verifies SSRF policy, queries the API safely, and delivers parsed JSON to `ctx.args.callbackData`.
|
|
632
665
|
|
|
633
666
|
```typescript
|
|
634
667
|
game.onCommand("trivia", (ctx) => {
|
|
635
|
-
|
|
668
|
+
// Phase 1: Request data via host proxy
|
|
669
|
+
ctx.http.get("https://the-trivia-api.com/v2/questions?limit=1", {
|
|
636
670
|
callback: "on_trivia_received"
|
|
637
671
|
});
|
|
638
672
|
});
|
|
673
|
+
|
|
674
|
+
game.onCallback("on_trivia_received", (ctx) => {
|
|
675
|
+
// Phase 2: Host delivers payload
|
|
676
|
+
const questions = ctx.args.callbackData as any[];
|
|
677
|
+
if (questions && questions.length > 0) {
|
|
678
|
+
const q = questions[0];
|
|
679
|
+
ctx.ui.sendChat({
|
|
680
|
+
title: "🧠 Question Time!",
|
|
681
|
+
text: q.question.text,
|
|
682
|
+
buttons: [
|
|
683
|
+
new Button({ customId: "ans_correct", label: q.correctAnswer, style: "primary" }),
|
|
684
|
+
new Button({ customId: "ans_wrong", label: q.incorrectAnswers[0], style: "secondary" }),
|
|
685
|
+
]
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
});
|
|
639
689
|
```
|
|
640
690
|
|
|
691
|
+
---
|
|
692
|
+
|
|
693
|
+
## Sandboxing & Dependency Constraints
|
|
694
|
+
|
|
695
|
+
To guarantee zero latency spikes, airtight security, and deterministic runs across all Discord nodes:
|
|
696
|
+
|
|
697
|
+
1. **Pure JavaScript / TypeScript**: Cartridges must use standard JS built-ins (Arrays, Maps, Math, JSON, Date, RegExp).
|
|
698
|
+
2. **No Native C/C++ Addons**: Node addons (`.node` binaries) or packages relying on libuv/native OS handles (`fs`, `net`, `child_process`) are not supported in WASM.
|
|
699
|
+
3. **Official SDK Only**: Only import `angela-sdk`. All interactions with Discord, player balances, inventory, and network go through `ctx`.
|
|
700
|
+
4. **State Persistence**: Cartridges cannot write to local disk. State across turns is stored in `ctx.state` or `ctx.storage`.
|
|
701
|
+
|
|
702
|
+
---
|
|
703
|
+
|
|
704
|
+
## Discord Utilities
|
|
705
|
+
|
|
641
706
|
### Channel Management & Chat Listening
|
|
642
707
|
|
|
643
708
|
```typescript
|
|
@@ -665,7 +730,7 @@ my_game/
|
|
|
665
730
|
├── manifest.json # Game metadata, config schema, target slot
|
|
666
731
|
├── src/
|
|
667
732
|
│ └── index.ts # TypeScript entry script exporting handle
|
|
668
|
-
├── package.json # Dependencies (devDependencies:
|
|
733
|
+
├── package.json # Dependencies (devDependencies: angela-sdk, typescript)
|
|
669
734
|
└── assets/ # Game sprites referenced by ctx.canvas.sprite()
|
|
670
735
|
├── boss.png
|
|
671
736
|
└── coin.png
|
package/dist/cjs/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
CanvasContext: () => CanvasContext,
|
|
28
28
|
CanvasLayer: () => CanvasLayer,
|
|
29
29
|
CanvasScene: () => CanvasScene,
|
|
30
|
+
ChannelContext: () => ChannelContext,
|
|
30
31
|
Container: () => Container,
|
|
31
32
|
Context: () => Context,
|
|
32
33
|
DiscordContext: () => DiscordContext,
|
|
@@ -39,6 +40,7 @@ __export(index_exports, {
|
|
|
39
40
|
LobbyContext: () => LobbyContext,
|
|
40
41
|
MediaContext: () => MediaContext,
|
|
41
42
|
MediaGallery: () => MediaGallery,
|
|
43
|
+
PermissionsContext: () => PermissionsContext,
|
|
42
44
|
Section: () => Section,
|
|
43
45
|
Select: () => Select,
|
|
44
46
|
SelectOption: () => SelectOption,
|
|
@@ -48,6 +50,7 @@ __export(index_exports, {
|
|
|
48
50
|
TextDisplay: () => TextDisplay,
|
|
49
51
|
TextInput: () => TextInput,
|
|
50
52
|
Thumbnail: () => Thumbnail,
|
|
53
|
+
TimerContext: () => TimerContext,
|
|
51
54
|
UIContext: () => UIContext,
|
|
52
55
|
User: () => User,
|
|
53
56
|
VERSION: () => VERSION,
|
|
@@ -327,6 +330,35 @@ var CanvasContext = class {
|
|
|
327
330
|
}
|
|
328
331
|
};
|
|
329
332
|
|
|
333
|
+
// src/channel.ts
|
|
334
|
+
var ChannelContext = class {
|
|
335
|
+
constructor(ctx) {
|
|
336
|
+
this.ctx = ctx;
|
|
337
|
+
}
|
|
338
|
+
ctx;
|
|
339
|
+
create(options) {
|
|
340
|
+
const intent = {
|
|
341
|
+
op: "CHANNEL_OP",
|
|
342
|
+
action: "CREATE",
|
|
343
|
+
name: String(options.name).slice(0, 32),
|
|
344
|
+
category_id: options.categoryId ? Number(options.categoryId) : void 0,
|
|
345
|
+
max_ttl_minutes: options.ttlMinutes ?? 60,
|
|
346
|
+
callback_event_id: options.callback
|
|
347
|
+
};
|
|
348
|
+
this.ctx.addIntent(intent);
|
|
349
|
+
return intent;
|
|
350
|
+
}
|
|
351
|
+
delete(channelId) {
|
|
352
|
+
const intent = {
|
|
353
|
+
op: "CHANNEL_OP",
|
|
354
|
+
action: "DELETE",
|
|
355
|
+
channel_id: channelId ? Number(channelId) : this.ctx.channelId
|
|
356
|
+
};
|
|
357
|
+
this.ctx.addIntent(intent);
|
|
358
|
+
return intent;
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
|
|
330
362
|
// src/http.ts
|
|
331
363
|
var HTTPContext = class {
|
|
332
364
|
constructor(ctx) {
|
|
@@ -399,7 +431,19 @@ var StorageContext = class {
|
|
|
399
431
|
this.ctx.addIntent(intent);
|
|
400
432
|
return intent;
|
|
401
433
|
}
|
|
434
|
+
recordStat(userId, key, delta = 1) {
|
|
435
|
+
const intent = {
|
|
436
|
+
op: "STORAGE_MUTATE",
|
|
437
|
+
action: "RECORD_STAT",
|
|
438
|
+
user_id: Number(userId),
|
|
439
|
+
key: String(key).slice(0, 48),
|
|
440
|
+
delta: Math.floor(delta)
|
|
441
|
+
};
|
|
442
|
+
this.ctx.addIntent(intent);
|
|
443
|
+
return intent;
|
|
444
|
+
}
|
|
402
445
|
set_cooldown = this.setCooldown.bind(this);
|
|
446
|
+
record_stat = this.recordStat.bind(this);
|
|
403
447
|
};
|
|
404
448
|
|
|
405
449
|
// src/economy.ts
|
|
@@ -695,6 +739,66 @@ var Session = class {
|
|
|
695
739
|
}
|
|
696
740
|
};
|
|
697
741
|
|
|
742
|
+
// src/permissions.ts
|
|
743
|
+
var PermissionsContext = class {
|
|
744
|
+
constructor(ctx) {
|
|
745
|
+
this.ctx = ctx;
|
|
746
|
+
}
|
|
747
|
+
ctx;
|
|
748
|
+
set(options) {
|
|
749
|
+
const targetStr = String(options.target).trim();
|
|
750
|
+
const isEveryone = targetStr === "@everyone" || targetStr === "0" || targetStr.toLowerCase() === "everyone";
|
|
751
|
+
const targetType = isEveryone || !/^\d+$/.test(targetStr) ? "ROLE" : "USER";
|
|
752
|
+
const targetId = isEveryone ? 0 : Number(options.target);
|
|
753
|
+
const intent = {
|
|
754
|
+
op: "PERMISSION_OVERWRITE",
|
|
755
|
+
channel_id: options.channelId ? Number(options.channelId) : this.ctx.channelId,
|
|
756
|
+
target_type: targetType,
|
|
757
|
+
target_id: targetId,
|
|
758
|
+
allow: options.allow ?? [],
|
|
759
|
+
deny: options.deny ?? [],
|
|
760
|
+
duration_seconds: options.durationSeconds,
|
|
761
|
+
reason: options.reason ?? "Game Permission Overwrite"
|
|
762
|
+
};
|
|
763
|
+
this.ctx.addIntent(intent);
|
|
764
|
+
return intent;
|
|
765
|
+
}
|
|
766
|
+
lockChannel(durationSeconds = 20, channelId) {
|
|
767
|
+
return this.set({
|
|
768
|
+
target: 0,
|
|
769
|
+
deny: ["SEND_MESSAGES"],
|
|
770
|
+
channelId,
|
|
771
|
+
durationSeconds,
|
|
772
|
+
reason: "Channel Lock"
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
lock_channel = this.lockChannel.bind(this);
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
// src/timer.ts
|
|
779
|
+
var TimerContext = class {
|
|
780
|
+
constructor(ctx) {
|
|
781
|
+
this.ctx = ctx;
|
|
782
|
+
}
|
|
783
|
+
ctx;
|
|
784
|
+
schedule(delaySeconds, callback = "on_wake") {
|
|
785
|
+
const intent = {
|
|
786
|
+
op: "SCHEDULE_WAKE",
|
|
787
|
+
delay_seconds: Number(delaySeconds),
|
|
788
|
+
callback_event_id: String(callback)
|
|
789
|
+
};
|
|
790
|
+
this.ctx.addIntent(intent);
|
|
791
|
+
return intent;
|
|
792
|
+
}
|
|
793
|
+
cancel() {
|
|
794
|
+
const intent = {
|
|
795
|
+
op: "TIMER_CANCEL"
|
|
796
|
+
};
|
|
797
|
+
this.ctx.addIntent(intent);
|
|
798
|
+
return intent;
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
|
|
698
802
|
// src/ui.ts
|
|
699
803
|
var Button = class {
|
|
700
804
|
customId;
|
|
@@ -1067,11 +1171,38 @@ var UIContext = class {
|
|
|
1067
1171
|
this.ctx.addIntent(intent);
|
|
1068
1172
|
return intent;
|
|
1069
1173
|
}
|
|
1174
|
+
sendChat(textOrOptions) {
|
|
1175
|
+
if (typeof textOrOptions === "string") {
|
|
1176
|
+
return this.render({ bodyLines: [textOrOptions], ephemeral: false, target: "NEW_MESSAGE" });
|
|
1177
|
+
}
|
|
1178
|
+
if (textOrOptions.embed) {
|
|
1179
|
+
return this.renderEmbed(textOrOptions.embed, {
|
|
1180
|
+
components: textOrOptions.buttons,
|
|
1181
|
+
ephemeral: false,
|
|
1182
|
+
target: "NEW_MESSAGE"
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
return this.render({
|
|
1186
|
+
title: textOrOptions.title,
|
|
1187
|
+
subtitle: textOrOptions.subtitle,
|
|
1188
|
+
bodyLines: textOrOptions.text ? [textOrOptions.text] : [],
|
|
1189
|
+
buttons: textOrOptions.buttons,
|
|
1190
|
+
selects: textOrOptions.selects,
|
|
1191
|
+
image: textOrOptions.image,
|
|
1192
|
+
thumbnail: textOrOptions.thumbnail,
|
|
1193
|
+
accentColor: textOrOptions.accentColor,
|
|
1194
|
+
ephemeral: false,
|
|
1195
|
+
target: "NEW_MESSAGE"
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
sendMessage = this.sendChat.bind(this);
|
|
1070
1199
|
// Snake_case aliases
|
|
1071
1200
|
render_cv2 = this.renderCv2.bind(this);
|
|
1072
1201
|
render_embed = this.renderEmbed.bind(this);
|
|
1073
1202
|
reply_ephemeral = this.replyEphemeral.bind(this);
|
|
1074
1203
|
open_modal = this.openModal.bind(this);
|
|
1204
|
+
send_chat = this.sendChat.bind(this);
|
|
1205
|
+
send_message = this.sendMessage.bind(this);
|
|
1075
1206
|
};
|
|
1076
1207
|
|
|
1077
1208
|
// src/context.ts
|
|
@@ -1100,6 +1231,9 @@ var Context = class {
|
|
|
1100
1231
|
http;
|
|
1101
1232
|
discord;
|
|
1102
1233
|
storage;
|
|
1234
|
+
channel;
|
|
1235
|
+
perms;
|
|
1236
|
+
timer;
|
|
1103
1237
|
constructor(rawEvent = {}) {
|
|
1104
1238
|
this.rawEvent = rawEvent;
|
|
1105
1239
|
this.eventType = String(rawEvent.event_type ?? "COMMAND");
|
|
@@ -1124,6 +1258,9 @@ var Context = class {
|
|
|
1124
1258
|
this.http = new HTTPContext(this);
|
|
1125
1259
|
this.discord = new DiscordContext(this);
|
|
1126
1260
|
this.storage = new StorageContext(this);
|
|
1261
|
+
this.channel = new ChannelContext(this);
|
|
1262
|
+
this.perms = new PermissionsContext(this);
|
|
1263
|
+
this.timer = new TimerContext(this);
|
|
1127
1264
|
}
|
|
1128
1265
|
get hostId() {
|
|
1129
1266
|
if (this.session.participants.length > 0) {
|
|
@@ -1335,7 +1472,7 @@ function dispatch(handler, event) {
|
|
|
1335
1472
|
}
|
|
1336
1473
|
|
|
1337
1474
|
// src/index.ts
|
|
1338
|
-
var VERSION = "0.
|
|
1475
|
+
var VERSION = "0.3.0";
|
|
1339
1476
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1340
1477
|
0 && (module.exports = {
|
|
1341
1478
|
AIContext,
|
|
@@ -1345,6 +1482,7 @@ var VERSION = "0.1.0";
|
|
|
1345
1482
|
CanvasContext,
|
|
1346
1483
|
CanvasLayer,
|
|
1347
1484
|
CanvasScene,
|
|
1485
|
+
ChannelContext,
|
|
1348
1486
|
Container,
|
|
1349
1487
|
Context,
|
|
1350
1488
|
DiscordContext,
|
|
@@ -1357,6 +1495,7 @@ var VERSION = "0.1.0";
|
|
|
1357
1495
|
LobbyContext,
|
|
1358
1496
|
MediaContext,
|
|
1359
1497
|
MediaGallery,
|
|
1498
|
+
PermissionsContext,
|
|
1360
1499
|
Section,
|
|
1361
1500
|
Select,
|
|
1362
1501
|
SelectOption,
|
|
@@ -1366,6 +1505,7 @@ var VERSION = "0.1.0";
|
|
|
1366
1505
|
TextDisplay,
|
|
1367
1506
|
TextInput,
|
|
1368
1507
|
Thumbnail,
|
|
1508
|
+
TimerContext,
|
|
1369
1509
|
UIContext,
|
|
1370
1510
|
User,
|
|
1371
1511
|
VERSION,
|
package/dist/esm/index.js
CHANGED
|
@@ -270,6 +270,35 @@ var CanvasContext = class {
|
|
|
270
270
|
}
|
|
271
271
|
};
|
|
272
272
|
|
|
273
|
+
// src/channel.ts
|
|
274
|
+
var ChannelContext = class {
|
|
275
|
+
constructor(ctx) {
|
|
276
|
+
this.ctx = ctx;
|
|
277
|
+
}
|
|
278
|
+
ctx;
|
|
279
|
+
create(options) {
|
|
280
|
+
const intent = {
|
|
281
|
+
op: "CHANNEL_OP",
|
|
282
|
+
action: "CREATE",
|
|
283
|
+
name: String(options.name).slice(0, 32),
|
|
284
|
+
category_id: options.categoryId ? Number(options.categoryId) : void 0,
|
|
285
|
+
max_ttl_minutes: options.ttlMinutes ?? 60,
|
|
286
|
+
callback_event_id: options.callback
|
|
287
|
+
};
|
|
288
|
+
this.ctx.addIntent(intent);
|
|
289
|
+
return intent;
|
|
290
|
+
}
|
|
291
|
+
delete(channelId) {
|
|
292
|
+
const intent = {
|
|
293
|
+
op: "CHANNEL_OP",
|
|
294
|
+
action: "DELETE",
|
|
295
|
+
channel_id: channelId ? Number(channelId) : this.ctx.channelId
|
|
296
|
+
};
|
|
297
|
+
this.ctx.addIntent(intent);
|
|
298
|
+
return intent;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
273
302
|
// src/http.ts
|
|
274
303
|
var HTTPContext = class {
|
|
275
304
|
constructor(ctx) {
|
|
@@ -342,7 +371,19 @@ var StorageContext = class {
|
|
|
342
371
|
this.ctx.addIntent(intent);
|
|
343
372
|
return intent;
|
|
344
373
|
}
|
|
374
|
+
recordStat(userId, key, delta = 1) {
|
|
375
|
+
const intent = {
|
|
376
|
+
op: "STORAGE_MUTATE",
|
|
377
|
+
action: "RECORD_STAT",
|
|
378
|
+
user_id: Number(userId),
|
|
379
|
+
key: String(key).slice(0, 48),
|
|
380
|
+
delta: Math.floor(delta)
|
|
381
|
+
};
|
|
382
|
+
this.ctx.addIntent(intent);
|
|
383
|
+
return intent;
|
|
384
|
+
}
|
|
345
385
|
set_cooldown = this.setCooldown.bind(this);
|
|
386
|
+
record_stat = this.recordStat.bind(this);
|
|
346
387
|
};
|
|
347
388
|
|
|
348
389
|
// src/economy.ts
|
|
@@ -638,6 +679,66 @@ var Session = class {
|
|
|
638
679
|
}
|
|
639
680
|
};
|
|
640
681
|
|
|
682
|
+
// src/permissions.ts
|
|
683
|
+
var PermissionsContext = class {
|
|
684
|
+
constructor(ctx) {
|
|
685
|
+
this.ctx = ctx;
|
|
686
|
+
}
|
|
687
|
+
ctx;
|
|
688
|
+
set(options) {
|
|
689
|
+
const targetStr = String(options.target).trim();
|
|
690
|
+
const isEveryone = targetStr === "@everyone" || targetStr === "0" || targetStr.toLowerCase() === "everyone";
|
|
691
|
+
const targetType = isEveryone || !/^\d+$/.test(targetStr) ? "ROLE" : "USER";
|
|
692
|
+
const targetId = isEveryone ? 0 : Number(options.target);
|
|
693
|
+
const intent = {
|
|
694
|
+
op: "PERMISSION_OVERWRITE",
|
|
695
|
+
channel_id: options.channelId ? Number(options.channelId) : this.ctx.channelId,
|
|
696
|
+
target_type: targetType,
|
|
697
|
+
target_id: targetId,
|
|
698
|
+
allow: options.allow ?? [],
|
|
699
|
+
deny: options.deny ?? [],
|
|
700
|
+
duration_seconds: options.durationSeconds,
|
|
701
|
+
reason: options.reason ?? "Game Permission Overwrite"
|
|
702
|
+
};
|
|
703
|
+
this.ctx.addIntent(intent);
|
|
704
|
+
return intent;
|
|
705
|
+
}
|
|
706
|
+
lockChannel(durationSeconds = 20, channelId) {
|
|
707
|
+
return this.set({
|
|
708
|
+
target: 0,
|
|
709
|
+
deny: ["SEND_MESSAGES"],
|
|
710
|
+
channelId,
|
|
711
|
+
durationSeconds,
|
|
712
|
+
reason: "Channel Lock"
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
lock_channel = this.lockChannel.bind(this);
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
// src/timer.ts
|
|
719
|
+
var TimerContext = class {
|
|
720
|
+
constructor(ctx) {
|
|
721
|
+
this.ctx = ctx;
|
|
722
|
+
}
|
|
723
|
+
ctx;
|
|
724
|
+
schedule(delaySeconds, callback = "on_wake") {
|
|
725
|
+
const intent = {
|
|
726
|
+
op: "SCHEDULE_WAKE",
|
|
727
|
+
delay_seconds: Number(delaySeconds),
|
|
728
|
+
callback_event_id: String(callback)
|
|
729
|
+
};
|
|
730
|
+
this.ctx.addIntent(intent);
|
|
731
|
+
return intent;
|
|
732
|
+
}
|
|
733
|
+
cancel() {
|
|
734
|
+
const intent = {
|
|
735
|
+
op: "TIMER_CANCEL"
|
|
736
|
+
};
|
|
737
|
+
this.ctx.addIntent(intent);
|
|
738
|
+
return intent;
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
|
|
641
742
|
// src/ui.ts
|
|
642
743
|
var Button = class {
|
|
643
744
|
customId;
|
|
@@ -1010,11 +1111,38 @@ var UIContext = class {
|
|
|
1010
1111
|
this.ctx.addIntent(intent);
|
|
1011
1112
|
return intent;
|
|
1012
1113
|
}
|
|
1114
|
+
sendChat(textOrOptions) {
|
|
1115
|
+
if (typeof textOrOptions === "string") {
|
|
1116
|
+
return this.render({ bodyLines: [textOrOptions], ephemeral: false, target: "NEW_MESSAGE" });
|
|
1117
|
+
}
|
|
1118
|
+
if (textOrOptions.embed) {
|
|
1119
|
+
return this.renderEmbed(textOrOptions.embed, {
|
|
1120
|
+
components: textOrOptions.buttons,
|
|
1121
|
+
ephemeral: false,
|
|
1122
|
+
target: "NEW_MESSAGE"
|
|
1123
|
+
});
|
|
1124
|
+
}
|
|
1125
|
+
return this.render({
|
|
1126
|
+
title: textOrOptions.title,
|
|
1127
|
+
subtitle: textOrOptions.subtitle,
|
|
1128
|
+
bodyLines: textOrOptions.text ? [textOrOptions.text] : [],
|
|
1129
|
+
buttons: textOrOptions.buttons,
|
|
1130
|
+
selects: textOrOptions.selects,
|
|
1131
|
+
image: textOrOptions.image,
|
|
1132
|
+
thumbnail: textOrOptions.thumbnail,
|
|
1133
|
+
accentColor: textOrOptions.accentColor,
|
|
1134
|
+
ephemeral: false,
|
|
1135
|
+
target: "NEW_MESSAGE"
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
sendMessage = this.sendChat.bind(this);
|
|
1013
1139
|
// Snake_case aliases
|
|
1014
1140
|
render_cv2 = this.renderCv2.bind(this);
|
|
1015
1141
|
render_embed = this.renderEmbed.bind(this);
|
|
1016
1142
|
reply_ephemeral = this.replyEphemeral.bind(this);
|
|
1017
1143
|
open_modal = this.openModal.bind(this);
|
|
1144
|
+
send_chat = this.sendChat.bind(this);
|
|
1145
|
+
send_message = this.sendMessage.bind(this);
|
|
1018
1146
|
};
|
|
1019
1147
|
|
|
1020
1148
|
// src/context.ts
|
|
@@ -1043,6 +1171,9 @@ var Context = class {
|
|
|
1043
1171
|
http;
|
|
1044
1172
|
discord;
|
|
1045
1173
|
storage;
|
|
1174
|
+
channel;
|
|
1175
|
+
perms;
|
|
1176
|
+
timer;
|
|
1046
1177
|
constructor(rawEvent = {}) {
|
|
1047
1178
|
this.rawEvent = rawEvent;
|
|
1048
1179
|
this.eventType = String(rawEvent.event_type ?? "COMMAND");
|
|
@@ -1067,6 +1198,9 @@ var Context = class {
|
|
|
1067
1198
|
this.http = new HTTPContext(this);
|
|
1068
1199
|
this.discord = new DiscordContext(this);
|
|
1069
1200
|
this.storage = new StorageContext(this);
|
|
1201
|
+
this.channel = new ChannelContext(this);
|
|
1202
|
+
this.perms = new PermissionsContext(this);
|
|
1203
|
+
this.timer = new TimerContext(this);
|
|
1070
1204
|
}
|
|
1071
1205
|
get hostId() {
|
|
1072
1206
|
if (this.session.participants.length > 0) {
|
|
@@ -1278,7 +1412,7 @@ function dispatch(handler, event) {
|
|
|
1278
1412
|
}
|
|
1279
1413
|
|
|
1280
1414
|
// src/index.ts
|
|
1281
|
-
var VERSION = "0.
|
|
1415
|
+
var VERSION = "0.3.0";
|
|
1282
1416
|
export {
|
|
1283
1417
|
AIContext,
|
|
1284
1418
|
ActionRow,
|
|
@@ -1287,6 +1421,7 @@ export {
|
|
|
1287
1421
|
CanvasContext,
|
|
1288
1422
|
CanvasLayer,
|
|
1289
1423
|
CanvasScene,
|
|
1424
|
+
ChannelContext,
|
|
1290
1425
|
Container,
|
|
1291
1426
|
Context,
|
|
1292
1427
|
DiscordContext,
|
|
@@ -1299,6 +1434,7 @@ export {
|
|
|
1299
1434
|
LobbyContext,
|
|
1300
1435
|
MediaContext,
|
|
1301
1436
|
MediaGallery,
|
|
1437
|
+
PermissionsContext,
|
|
1302
1438
|
Section,
|
|
1303
1439
|
Select,
|
|
1304
1440
|
SelectOption,
|
|
@@ -1308,6 +1444,7 @@ export {
|
|
|
1308
1444
|
TextDisplay,
|
|
1309
1445
|
TextInput,
|
|
1310
1446
|
Thumbnail,
|
|
1447
|
+
TimerContext,
|
|
1311
1448
|
UIContext,
|
|
1312
1449
|
User,
|
|
1313
1450
|
VERSION,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Context } from "./context.js";
|
|
2
|
+
import type { Intent } from "./models.js";
|
|
3
|
+
export declare class ChannelContext {
|
|
4
|
+
private ctx;
|
|
5
|
+
constructor(ctx: Context);
|
|
6
|
+
create(options: {
|
|
7
|
+
name: string;
|
|
8
|
+
categoryId?: number | string | null;
|
|
9
|
+
ttlMinutes?: number;
|
|
10
|
+
callback?: string;
|
|
11
|
+
}): Intent;
|
|
12
|
+
delete(channelId?: number | string): Intent;
|
|
13
|
+
}
|
package/dist/types/context.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { AIContext, MediaContext } from "./ai.js";
|
|
2
2
|
import { CanvasContext } from "./canvas.js";
|
|
3
|
+
import { ChannelContext } from "./channel.js";
|
|
3
4
|
import { DiscordContext, HTTPContext, StorageContext } from "./http.js";
|
|
4
5
|
import { EconomyContext } from "./economy.js";
|
|
5
6
|
import { InventoryContext } from "./inventory.js";
|
|
6
7
|
import { LobbyContext } from "./lobby.js";
|
|
7
8
|
import { Args, type ArgsData, type Intent, Session, type SessionData, User, type UserData } from "./models.js";
|
|
9
|
+
import { PermissionsContext } from "./permissions.js";
|
|
10
|
+
import { TimerContext } from "./timer.js";
|
|
8
11
|
import { UIContext } from "./ui.js";
|
|
9
12
|
export interface EventPayload {
|
|
10
13
|
event_type?: string;
|
|
@@ -42,6 +45,9 @@ export declare class Context {
|
|
|
42
45
|
http: HTTPContext;
|
|
43
46
|
discord: DiscordContext;
|
|
44
47
|
storage: StorageContext;
|
|
48
|
+
channel: ChannelContext;
|
|
49
|
+
perms: PermissionsContext;
|
|
50
|
+
timer: TimerContext;
|
|
45
51
|
constructor(rawEvent?: EventPayload);
|
|
46
52
|
get hostId(): number;
|
|
47
53
|
get event_type(): string;
|
package/dist/types/http.d.ts
CHANGED
|
@@ -37,5 +37,7 @@ export declare class StorageContext {
|
|
|
37
37
|
get<T = unknown>(key: string, defaultValue?: T): T | undefined;
|
|
38
38
|
set(key: string, value: unknown): void;
|
|
39
39
|
setCooldown(userId: number | string, seconds: number): Intent;
|
|
40
|
+
recordStat(userId: number | string, key: string, delta?: number): Intent;
|
|
40
41
|
set_cooldown: (userId: number | string, seconds: number) => Intent;
|
|
42
|
+
record_stat: (userId: number | string, key: string, delta?: number) => Intent;
|
|
41
43
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Angela TypeScript & JavaScript SDK (
|
|
2
|
+
* Angela TypeScript & JavaScript SDK (angela-sdk)
|
|
3
3
|
* The official developer kit for Angela Games Ecosystem cartridges.
|
|
4
4
|
*/
|
|
5
5
|
export * from "./ai.js";
|
|
6
6
|
export * from "./canvas.js";
|
|
7
|
+
export * from "./channel.js";
|
|
7
8
|
export * from "./context.js";
|
|
8
9
|
export * from "./economy.js";
|
|
9
10
|
export * from "./game.js";
|
|
@@ -11,5 +12,7 @@ export * from "./http.js";
|
|
|
11
12
|
export * from "./inventory.js";
|
|
12
13
|
export * from "./lobby.js";
|
|
13
14
|
export * from "./models.js";
|
|
15
|
+
export * from "./permissions.js";
|
|
16
|
+
export * from "./timer.js";
|
|
14
17
|
export * from "./ui.js";
|
|
15
|
-
export declare const VERSION = "0.
|
|
18
|
+
export declare const VERSION = "0.3.0";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Context } from "./context.js";
|
|
2
|
+
import type { Intent } from "./models.js";
|
|
3
|
+
export declare class PermissionsContext {
|
|
4
|
+
private ctx;
|
|
5
|
+
constructor(ctx: Context);
|
|
6
|
+
set(options: {
|
|
7
|
+
target: number | string;
|
|
8
|
+
allow?: string[];
|
|
9
|
+
deny?: string[];
|
|
10
|
+
channelId?: number | string;
|
|
11
|
+
durationSeconds?: number;
|
|
12
|
+
reason?: string;
|
|
13
|
+
}): Intent;
|
|
14
|
+
lockChannel(durationSeconds?: number, channelId?: number | string): Intent;
|
|
15
|
+
lock_channel: (durationSeconds?: number, channelId?: number | string) => Intent;
|
|
16
|
+
}
|
package/dist/types/ui.d.ts
CHANGED
|
@@ -196,6 +196,28 @@ export declare class UIContext {
|
|
|
196
196
|
container?: Container;
|
|
197
197
|
}): Intent;
|
|
198
198
|
openModal(title: string, inputs: (TextInput | Record<string, unknown>)[], callbackId: string): Intent;
|
|
199
|
+
sendChat(textOrOptions: string | {
|
|
200
|
+
text?: string;
|
|
201
|
+
title?: string;
|
|
202
|
+
subtitle?: string;
|
|
203
|
+
buttons?: (Button | Record<string, unknown>)[];
|
|
204
|
+
selects?: (Select | Record<string, unknown>)[];
|
|
205
|
+
embed?: Embed | Record<string, unknown>;
|
|
206
|
+
image?: string | CanvasScene;
|
|
207
|
+
thumbnail?: string;
|
|
208
|
+
accentColor?: string | number;
|
|
209
|
+
}): Intent;
|
|
210
|
+
sendMessage: (textOrOptions: string | {
|
|
211
|
+
text?: string;
|
|
212
|
+
title?: string;
|
|
213
|
+
subtitle?: string;
|
|
214
|
+
buttons?: (Button | Record<string, unknown>)[];
|
|
215
|
+
selects?: (Select | Record<string, unknown>)[];
|
|
216
|
+
embed?: Embed | Record<string, unknown>;
|
|
217
|
+
image?: string | CanvasScene;
|
|
218
|
+
thumbnail?: string;
|
|
219
|
+
accentColor?: string | number;
|
|
220
|
+
}) => Intent;
|
|
199
221
|
render_cv2: (container: Container | Record<string, unknown>, options?: {
|
|
200
222
|
ephemeral?: boolean;
|
|
201
223
|
target?: string;
|
|
@@ -213,4 +235,26 @@ export declare class UIContext {
|
|
|
213
235
|
container?: Container;
|
|
214
236
|
}) => Intent;
|
|
215
237
|
open_modal: (title: string, inputs: (TextInput | Record<string, unknown>)[], callbackId: string) => Intent;
|
|
238
|
+
send_chat: (textOrOptions: string | {
|
|
239
|
+
text?: string;
|
|
240
|
+
title?: string;
|
|
241
|
+
subtitle?: string;
|
|
242
|
+
buttons?: (Button | Record<string, unknown>)[];
|
|
243
|
+
selects?: (Select | Record<string, unknown>)[];
|
|
244
|
+
embed?: Embed | Record<string, unknown>;
|
|
245
|
+
image?: string | CanvasScene;
|
|
246
|
+
thumbnail?: string;
|
|
247
|
+
accentColor?: string | number;
|
|
248
|
+
}) => Intent;
|
|
249
|
+
send_message: (textOrOptions: string | {
|
|
250
|
+
text?: string;
|
|
251
|
+
title?: string;
|
|
252
|
+
subtitle?: string;
|
|
253
|
+
buttons?: (Button | Record<string, unknown>)[];
|
|
254
|
+
selects?: (Select | Record<string, unknown>)[];
|
|
255
|
+
embed?: Embed | Record<string, unknown>;
|
|
256
|
+
image?: string | CanvasScene;
|
|
257
|
+
thumbnail?: string;
|
|
258
|
+
accentColor?: string | number;
|
|
259
|
+
}) => Intent;
|
|
216
260
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "angela-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Official TypeScript & JavaScript SDK for Angela Games Ecosystem cartridges",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"keywords": [
|
|
42
42
|
"angela",
|
|
43
43
|
"discord",
|
|
44
|
+
"custom",
|
|
44
45
|
"games",
|
|
45
46
|
"sdk",
|
|
46
47
|
"wasm",
|