angela-sdk 0.2.0 → 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/dist/cjs/index.js +114 -1
- package/dist/esm/index.js +111 -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 +4 -1
- package/dist/types/permissions.d.ts +16 -0
- package/dist/types/timer.d.ts +8 -0
- package/package.json +1 -1
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;
|
|
@@ -1127,6 +1231,9 @@ var Context = class {
|
|
|
1127
1231
|
http;
|
|
1128
1232
|
discord;
|
|
1129
1233
|
storage;
|
|
1234
|
+
channel;
|
|
1235
|
+
perms;
|
|
1236
|
+
timer;
|
|
1130
1237
|
constructor(rawEvent = {}) {
|
|
1131
1238
|
this.rawEvent = rawEvent;
|
|
1132
1239
|
this.eventType = String(rawEvent.event_type ?? "COMMAND");
|
|
@@ -1151,6 +1258,9 @@ var Context = class {
|
|
|
1151
1258
|
this.http = new HTTPContext(this);
|
|
1152
1259
|
this.discord = new DiscordContext(this);
|
|
1153
1260
|
this.storage = new StorageContext(this);
|
|
1261
|
+
this.channel = new ChannelContext(this);
|
|
1262
|
+
this.perms = new PermissionsContext(this);
|
|
1263
|
+
this.timer = new TimerContext(this);
|
|
1154
1264
|
}
|
|
1155
1265
|
get hostId() {
|
|
1156
1266
|
if (this.session.participants.length > 0) {
|
|
@@ -1362,7 +1472,7 @@ function dispatch(handler, event) {
|
|
|
1362
1472
|
}
|
|
1363
1473
|
|
|
1364
1474
|
// src/index.ts
|
|
1365
|
-
var VERSION = "0.
|
|
1475
|
+
var VERSION = "0.3.0";
|
|
1366
1476
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1367
1477
|
0 && (module.exports = {
|
|
1368
1478
|
AIContext,
|
|
@@ -1372,6 +1482,7 @@ var VERSION = "0.2.0";
|
|
|
1372
1482
|
CanvasContext,
|
|
1373
1483
|
CanvasLayer,
|
|
1374
1484
|
CanvasScene,
|
|
1485
|
+
ChannelContext,
|
|
1375
1486
|
Container,
|
|
1376
1487
|
Context,
|
|
1377
1488
|
DiscordContext,
|
|
@@ -1384,6 +1495,7 @@ var VERSION = "0.2.0";
|
|
|
1384
1495
|
LobbyContext,
|
|
1385
1496
|
MediaContext,
|
|
1386
1497
|
MediaGallery,
|
|
1498
|
+
PermissionsContext,
|
|
1387
1499
|
Section,
|
|
1388
1500
|
Select,
|
|
1389
1501
|
SelectOption,
|
|
@@ -1393,6 +1505,7 @@ var VERSION = "0.2.0";
|
|
|
1393
1505
|
TextDisplay,
|
|
1394
1506
|
TextInput,
|
|
1395
1507
|
Thumbnail,
|
|
1508
|
+
TimerContext,
|
|
1396
1509
|
UIContext,
|
|
1397
1510
|
User,
|
|
1398
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;
|
|
@@ -1070,6 +1171,9 @@ var Context = class {
|
|
|
1070
1171
|
http;
|
|
1071
1172
|
discord;
|
|
1072
1173
|
storage;
|
|
1174
|
+
channel;
|
|
1175
|
+
perms;
|
|
1176
|
+
timer;
|
|
1073
1177
|
constructor(rawEvent = {}) {
|
|
1074
1178
|
this.rawEvent = rawEvent;
|
|
1075
1179
|
this.eventType = String(rawEvent.event_type ?? "COMMAND");
|
|
@@ -1094,6 +1198,9 @@ var Context = class {
|
|
|
1094
1198
|
this.http = new HTTPContext(this);
|
|
1095
1199
|
this.discord = new DiscordContext(this);
|
|
1096
1200
|
this.storage = new StorageContext(this);
|
|
1201
|
+
this.channel = new ChannelContext(this);
|
|
1202
|
+
this.perms = new PermissionsContext(this);
|
|
1203
|
+
this.timer = new TimerContext(this);
|
|
1097
1204
|
}
|
|
1098
1205
|
get hostId() {
|
|
1099
1206
|
if (this.session.participants.length > 0) {
|
|
@@ -1305,7 +1412,7 @@ function dispatch(handler, event) {
|
|
|
1305
1412
|
}
|
|
1306
1413
|
|
|
1307
1414
|
// src/index.ts
|
|
1308
|
-
var VERSION = "0.
|
|
1415
|
+
var VERSION = "0.3.0";
|
|
1309
1416
|
export {
|
|
1310
1417
|
AIContext,
|
|
1311
1418
|
ActionRow,
|
|
@@ -1314,6 +1421,7 @@ export {
|
|
|
1314
1421
|
CanvasContext,
|
|
1315
1422
|
CanvasLayer,
|
|
1316
1423
|
CanvasScene,
|
|
1424
|
+
ChannelContext,
|
|
1317
1425
|
Container,
|
|
1318
1426
|
Context,
|
|
1319
1427
|
DiscordContext,
|
|
@@ -1326,6 +1434,7 @@ export {
|
|
|
1326
1434
|
LobbyContext,
|
|
1327
1435
|
MediaContext,
|
|
1328
1436
|
MediaGallery,
|
|
1437
|
+
PermissionsContext,
|
|
1329
1438
|
Section,
|
|
1330
1439
|
Select,
|
|
1331
1440
|
SelectOption,
|
|
@@ -1335,6 +1444,7 @@ export {
|
|
|
1335
1444
|
TextDisplay,
|
|
1336
1445
|
TextInput,
|
|
1337
1446
|
Thumbnail,
|
|
1447
|
+
TimerContext,
|
|
1338
1448
|
UIContext,
|
|
1339
1449
|
User,
|
|
1340
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
|
@@ -4,6 +4,7 @@
|
|
|
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
|
+
}
|