@open-discord-bots/framework 0.3.2 → 0.3.4

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.
@@ -372,8 +372,8 @@ export class ODCommandResponderInstance extends ODBaseResponderInstance {
372
372
  cmd;
373
373
  /**The type/source of instance. (from text or slash command) */
374
374
  type;
375
- /**Did a worker already reply to this instance/interaction? */
376
- didReply = false;
375
+ /**Switches to `true` when a worker replies, edits or defers interaction. Will stop the timeout error from being shown. */
376
+ ignoreResponderTimeout = false;
377
377
  /**The manager for all options of this command. */
378
378
  options;
379
379
  /**The user who triggered this command. */
@@ -397,27 +397,27 @@ export class ODCommandResponderInstance extends ODBaseResponderInstance {
397
397
  this.guild = interaction.guild;
398
398
  this.channel = interaction.channel;
399
399
  setTimeout(async () => {
400
- if (!this.didReply) {
401
- try {
402
- if (!errorCallback) {
403
- this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
404
- content: ":x: **Something went wrong while replying to this command!**"
405
- } });
406
- }
407
- else {
408
- const errorResponse = await errorCallback(this, (this.type == "interaction") ? "slash" : "text");
409
- //auto-delete timeout error message after 5sec when text-based
410
- if (errorResponse.success && this.type == "message")
411
- setTimeout(() => {
412
- if (errorResponse.message?.deletable)
413
- errorResponse.message?.delete();
414
- }, 5000);
415
- }
400
+ if (this.ignoreResponderTimeout)
401
+ return;
402
+ try {
403
+ if (!errorCallback) {
404
+ this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
405
+ content: ":x: **Something went wrong while replying to this command!**"
406
+ } });
416
407
  }
417
- catch (err) {
418
- process.emit("uncaughtException", err);
408
+ else {
409
+ const errorResponse = await errorCallback(this, (this.type == "interaction") ? "slash" : "text");
410
+ //auto-delete timeout error message after 5sec when text-based
411
+ if (errorResponse.success && this.type == "message")
412
+ setTimeout(() => {
413
+ if (errorResponse.message?.deletable)
414
+ errorResponse.message?.delete();
415
+ }, 5000);
419
416
  }
420
417
  }
418
+ catch (err) {
419
+ process.emit("uncaughtException", err);
420
+ }
421
421
  }, timeoutMs ?? 2500);
422
422
  }
423
423
  /**Reply to this command. */
@@ -427,46 +427,46 @@ export class ODCommandResponderInstance extends ODBaseResponderInstance {
427
427
  if (this.type == "interaction" && this.interaction instanceof discord.ChatInputCommandInteraction) {
428
428
  if (this.interaction.replied || this.interaction.deferred) {
429
429
  const sent = await this.interaction.editReply(finalMessage);
430
- this.didReply = true;
430
+ this.ignoreResponderTimeout = true;
431
431
  return { success: true, message: sent };
432
432
  }
433
433
  else {
434
434
  const sent = await this.interaction.reply(finalMessage);
435
- this.didReply = true;
435
+ this.ignoreResponderTimeout = true;
436
436
  return { success: true, message: await sent.fetch() };
437
437
  }
438
438
  }
439
439
  else if (this.type == "message" && this.interaction instanceof discord.Message && this.interaction.channel.type != discord.ChannelType.GroupDM) {
440
440
  const sent = await this.interaction.channel.send(finalMessage);
441
- this.didReply = true;
441
+ this.ignoreResponderTimeout = true;
442
442
  return { success: true, message: sent };
443
443
  }
444
444
  else
445
- return { success: false, message: null };
445
+ return { success: false };
446
446
  }
447
447
  catch {
448
- return { success: false, message: null };
448
+ return { success: false };
449
449
  }
450
450
  }
451
451
  /**Defer this command. */
452
452
  async defer(ephemeral) {
453
+ this.ignoreResponderTimeout = true;
453
454
  if (this.type != "interaction" || !(this.interaction instanceof discord.ChatInputCommandInteraction))
454
455
  return false;
455
456
  if (this.interaction.deferred || this.interaction.replied)
456
457
  return false;
457
458
  const msgFlags = ephemeral ? [discord.MessageFlags.Ephemeral] : [];
458
459
  await this.interaction.deferReply({ flags: msgFlags });
459
- this.didReply = true;
460
460
  return true;
461
461
  }
462
462
  /**Show a modal as reply to this command. */
463
463
  async modal(modal) {
464
+ this.ignoreResponderTimeout = true;
464
465
  if (this.type != "interaction" || !(this.interaction instanceof discord.ChatInputCommandInteraction))
465
466
  return false;
466
467
  if (this.interaction.deferred || this.interaction.replied)
467
468
  return false;
468
469
  await this.interaction.showModal(modal.modal);
469
- this.didReply = true;
470
470
  return true;
471
471
  }
472
472
  }
@@ -553,8 +553,8 @@ export class ODButtonResponderManager extends ODManager {
553
553
  export class ODButtonResponderInstance extends ODBaseResponderInstance {
554
554
  /**The interaction which is the source of this instance. */
555
555
  interaction;
556
- /**Did a worker already reply to this instance/interaction? */
557
- didReply = false;
556
+ /**Switches to `true` when a worker replies, edits or defers interaction. Will stop the timeout error from being shown. */
557
+ ignoreResponderTimeout = false;
558
558
  /**The user who triggered this button. */
559
559
  user;
560
560
  /**The guild member who triggered this button. */
@@ -576,21 +576,21 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
576
576
  this.channel = interaction.channel;
577
577
  this.message = interaction.message;
578
578
  setTimeout(async () => {
579
- if (!this.didReply) {
580
- try {
581
- if (!errorCallback) {
582
- this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
583
- content: ":x: **Something went wrong while replying to this button!**"
584
- } });
585
- }
586
- else {
587
- await errorCallback(this, "button");
588
- }
579
+ if (this.ignoreResponderTimeout)
580
+ return;
581
+ try {
582
+ if (!errorCallback) {
583
+ this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
584
+ content: ":x: **Something went wrong while replying to this button!**"
585
+ } });
589
586
  }
590
- catch (err) {
591
- process.emit("uncaughtException", err);
587
+ else {
588
+ await errorCallback(this, "button");
592
589
  }
593
590
  }
591
+ catch (err) {
592
+ process.emit("uncaughtException", err);
593
+ }
594
594
  }, timeoutMs ?? 2500);
595
595
  }
596
596
  /**Reply to this button. */
@@ -599,17 +599,17 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
599
599
  const finalMessage = this.getMessageFromBuildResult(build, "interaction");
600
600
  if (this.interaction.replied || this.interaction.deferred) {
601
601
  const sent = await this.interaction.editReply(finalMessage);
602
- this.didReply = true;
602
+ this.ignoreResponderTimeout = true;
603
603
  return { success: true, message: sent };
604
604
  }
605
605
  else {
606
606
  const sent = await this.interaction.reply(finalMessage);
607
- this.didReply = true;
607
+ this.ignoreResponderTimeout = true;
608
608
  return { success: true, message: await sent.fetch() };
609
609
  }
610
610
  }
611
611
  catch {
612
- return { success: false, message: null };
612
+ return { success: false };
613
613
  }
614
614
  }
615
615
  /**Update the message of this button. */
@@ -618,21 +618,22 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
618
618
  const finalMessage = this.getMessageFromBuildResult(build, "interaction");
619
619
  if (this.interaction.replied || this.interaction.deferred) {
620
620
  const sent = await this.interaction.editReply(finalMessage);
621
- this.didReply = true;
621
+ this.ignoreResponderTimeout = true;
622
622
  return { success: true, message: await sent.fetch() };
623
623
  }
624
624
  else {
625
625
  const sent = await this.interaction.update(finalMessage);
626
- this.didReply = true;
626
+ this.ignoreResponderTimeout = true;
627
627
  return { success: true, message: await sent.fetch() };
628
628
  }
629
629
  }
630
630
  catch {
631
- return { success: false, message: null };
631
+ return { success: false };
632
632
  }
633
633
  }
634
634
  /**Defer this button. */
635
635
  async defer(type, ephemeral) {
636
+ this.ignoreResponderTimeout = true;
636
637
  if (this.interaction.deferred || this.interaction.replied)
637
638
  return false;
638
639
  if (type == "reply") {
@@ -642,15 +643,14 @@ export class ODButtonResponderInstance extends ODBaseResponderInstance {
642
643
  else {
643
644
  await this.interaction.deferUpdate();
644
645
  }
645
- this.didReply = true;
646
646
  return true;
647
647
  }
648
648
  /**Show a modal as reply to this button. */
649
649
  async modal(modal) {
650
+ this.ignoreResponderTimeout = true;
650
651
  if (this.interaction.deferred || this.interaction.replied)
651
652
  return false;
652
653
  await this.interaction.showModal(modal.modal);
653
- this.didReply = true;
654
654
  return true;
655
655
  }
656
656
  getMessageComponent(type, id) {
@@ -839,8 +839,8 @@ export class ODDropdownResponderInstanceValues {
839
839
  export class ODDropdownResponderInstance extends ODBaseResponderInstance {
840
840
  /**The interaction which is the source of this instance. */
841
841
  interaction;
842
- /**Did a worker already reply to this instance/interaction? */
843
- didReply = false;
842
+ /**Switches to `true` when a worker replies, edits or defers interaction. Will stop the timeout error from being shown. */
843
+ ignoreResponderTimeout = false;
844
844
  /**The dropdown type. */
845
845
  type;
846
846
  /**The manager for all values of this dropdown. */
@@ -884,21 +884,21 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
884
884
  this.channel = interaction.channel;
885
885
  this.message = interaction.message;
886
886
  setTimeout(async () => {
887
- if (!this.didReply) {
888
- try {
889
- if (!errorCallback) {
890
- this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
891
- content: ":x: **Something went wrong while replying to this dropdown!**"
892
- } });
893
- }
894
- else {
895
- await errorCallback(this, "dropdown");
896
- }
887
+ if (this.ignoreResponderTimeout)
888
+ return;
889
+ try {
890
+ if (!errorCallback) {
891
+ this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
892
+ content: ":x: **Something went wrong while replying to this dropdown!**"
893
+ } });
897
894
  }
898
- catch (err) {
899
- process.emit("uncaughtException", err);
895
+ else {
896
+ await errorCallback(this, "dropdown");
900
897
  }
901
898
  }
899
+ catch (err) {
900
+ process.emit("uncaughtException", err);
901
+ }
902
902
  }, timeoutMs ?? 2500);
903
903
  }
904
904
  /**Reply to this dropdown. */
@@ -907,17 +907,17 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
907
907
  const finalMessage = this.getMessageFromBuildResult(build, "interaction");
908
908
  if (this.interaction.replied || this.interaction.deferred) {
909
909
  const sent = await this.interaction.editReply(finalMessage);
910
- this.didReply = true;
910
+ this.ignoreResponderTimeout = true;
911
911
  return { success: true, message: sent };
912
912
  }
913
913
  else {
914
914
  const sent = await this.interaction.reply(finalMessage);
915
- this.didReply = true;
915
+ this.ignoreResponderTimeout = true;
916
916
  return { success: true, message: await sent.fetch() };
917
917
  }
918
918
  }
919
919
  catch {
920
- return { success: false, message: null };
920
+ return { success: false };
921
921
  }
922
922
  }
923
923
  /**Update the message of this dropdown. */
@@ -926,21 +926,22 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
926
926
  const finalMessage = this.getMessageFromBuildResult(build, "interaction");
927
927
  if (this.interaction.replied || this.interaction.deferred) {
928
928
  const sent = await this.interaction.editReply(finalMessage);
929
- this.didReply = true;
929
+ this.ignoreResponderTimeout = true;
930
930
  return { success: true, message: await sent.fetch() };
931
931
  }
932
932
  else {
933
933
  const sent = await this.interaction.update(finalMessage);
934
- this.didReply = true;
934
+ this.ignoreResponderTimeout = true;
935
935
  return { success: true, message: await sent.fetch() };
936
936
  }
937
937
  }
938
938
  catch {
939
- return { success: false, message: null };
939
+ return { success: false };
940
940
  }
941
941
  }
942
942
  /**Defer this dropdown. */
943
943
  async defer(type, ephemeral) {
944
+ this.ignoreResponderTimeout = true;
944
945
  if (this.interaction.deferred || this.interaction.replied)
945
946
  return false;
946
947
  if (type == "reply") {
@@ -950,15 +951,14 @@ export class ODDropdownResponderInstance extends ODBaseResponderInstance {
950
951
  else {
951
952
  await this.interaction.deferUpdate();
952
953
  }
953
- this.didReply = true;
954
954
  return true;
955
955
  }
956
956
  /**Show a modal as reply to this dropdown. */
957
957
  async modal(modal) {
958
+ this.ignoreResponderTimeout = true;
958
959
  if (this.interaction.deferred || this.interaction.replied)
959
960
  return false;
960
961
  await this.interaction.showModal(modal.modal);
961
- this.didReply = true;
962
962
  return true;
963
963
  }
964
964
  getMessageComponent(type, id) {
@@ -1088,8 +1088,8 @@ export class ODModalResponderInstanceValues {
1088
1088
  export class ODModalResponderInstance extends ODBaseResponderInstance {
1089
1089
  /**The interaction which is the source of this instance. */
1090
1090
  interaction;
1091
- /**Did a worker already reply to this instance/interaction? */
1092
- didReply = false;
1091
+ /**Switches to `true` when a worker replies, edits or defers interaction. Will stop the timeout error from being shown. */
1092
+ ignoreResponderTimeout = false;
1093
1093
  /**The manager for all fields of this modal. */
1094
1094
  values;
1095
1095
  /**The user who triggered this modal. */
@@ -1109,21 +1109,21 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1109
1109
  this.guild = interaction.guild;
1110
1110
  this.channel = interaction.channel;
1111
1111
  setTimeout(async () => {
1112
- if (!this.didReply) {
1113
- try {
1114
- if (!errorCallback) {
1115
- this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
1116
- content: ":x: **Something went wrong while replying to this modal!**"
1117
- } });
1118
- }
1119
- else {
1120
- await errorCallback(this, "modal");
1121
- }
1112
+ if (this.ignoreResponderTimeout)
1113
+ return;
1114
+ try {
1115
+ if (!errorCallback) {
1116
+ this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
1117
+ content: ":x: **Something went wrong while replying to this modal!**"
1118
+ } });
1122
1119
  }
1123
- catch (err) {
1124
- process.emit("uncaughtException", err);
1120
+ else {
1121
+ await errorCallback(this, "modal");
1125
1122
  }
1126
1123
  }
1124
+ catch (err) {
1125
+ process.emit("uncaughtException", err);
1126
+ }
1127
1127
  }, timeoutMs ?? 2500);
1128
1128
  }
1129
1129
  /**Reply to this modal. */
@@ -1131,11 +1131,11 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1131
1131
  try {
1132
1132
  const finalMessage = this.getMessageFromBuildResult(build, "interaction");
1133
1133
  const sent = await this.interaction.followUp(finalMessage);
1134
- this.didReply = true;
1134
+ this.ignoreResponderTimeout = true;
1135
1135
  return { success: true, message: sent };
1136
1136
  }
1137
1137
  catch {
1138
- return { success: false, message: null };
1138
+ return { success: false };
1139
1139
  }
1140
1140
  }
1141
1141
  /**Update the message of this modal. */
@@ -1144,21 +1144,22 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1144
1144
  const finalMessage = this.getMessageFromBuildResult(build, "interaction");
1145
1145
  if (this.interaction.replied || this.interaction.deferred) {
1146
1146
  const sent = await this.interaction.editReply(finalMessage);
1147
- this.didReply = true;
1147
+ this.ignoreResponderTimeout = true;
1148
1148
  return { success: true, message: await sent.fetch() };
1149
1149
  }
1150
1150
  else {
1151
1151
  const sent = await this.interaction.reply(finalMessage);
1152
- this.didReply = true;
1152
+ this.ignoreResponderTimeout = true;
1153
1153
  return { success: true, message: await sent.fetch() };
1154
1154
  }
1155
1155
  }
1156
1156
  catch {
1157
- return { success: false, message: null };
1157
+ return { success: false };
1158
1158
  }
1159
1159
  }
1160
1160
  /**Defer this modal. */
1161
1161
  async defer(type, ephemeral) {
1162
+ this.ignoreResponderTimeout = true;
1162
1163
  if (this.interaction.deferred || this.interaction.replied)
1163
1164
  return false;
1164
1165
  if (type == "reply") {
@@ -1168,7 +1169,6 @@ export class ODModalResponderInstance extends ODBaseResponderInstance {
1168
1169
  else {
1169
1170
  await this.interaction.deferUpdate();
1170
1171
  }
1171
- this.didReply = true;
1172
1172
  return true;
1173
1173
  }
1174
1174
  }
@@ -1241,8 +1241,8 @@ export class ODContextMenuResponderManager extends ODManager {
1241
1241
  export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1242
1242
  /**The interaction which is the source of this instance. */
1243
1243
  interaction;
1244
- /**Did a worker already reply to this instance/interaction? */
1245
- didReply = false;
1244
+ /**Switches to `true` when a worker replies, edits or defers interaction. Will stop the timeout error from being shown. */
1245
+ ignoreResponderTimeout = false;
1246
1246
  /**The context menu wich is the source of this instance. */
1247
1247
  menu;
1248
1248
  /**The user who triggered this context menu. */
@@ -1272,21 +1272,21 @@ export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1272
1272
  else
1273
1273
  throw new ODSystemError("ODContextMenuResponderInstance: Invalid context menu type. Should be of the type User/Message!");
1274
1274
  setTimeout(async () => {
1275
- if (!this.didReply) {
1276
- try {
1277
- if (!errorCallback) {
1278
- this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
1279
- content: ":x: **Something went wrong while replying to this context menu!**"
1280
- } });
1281
- }
1282
- else {
1283
- await errorCallback(this, "context-menu");
1284
- }
1275
+ if (this.ignoreResponderTimeout)
1276
+ return;
1277
+ try {
1278
+ if (!errorCallback) {
1279
+ this.reply({ id: new ODId("opendiscord:unknown-error"), ephemeral: true, message: {
1280
+ content: ":x: **Something went wrong while replying to this context menu!**"
1281
+ } });
1285
1282
  }
1286
- catch (err) {
1287
- process.emit("uncaughtException", err);
1283
+ else {
1284
+ await errorCallback(this, "context-menu");
1288
1285
  }
1289
1286
  }
1287
+ catch (err) {
1288
+ process.emit("uncaughtException", err);
1289
+ }
1290
1290
  }, timeoutMs ?? 2500);
1291
1291
  }
1292
1292
  /**Reply to this context menu. */
@@ -1295,17 +1295,17 @@ export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1295
1295
  const finalMessage = this.getMessageFromBuildResult(build, "interaction");
1296
1296
  if (this.interaction.replied || this.interaction.deferred) {
1297
1297
  const sent = await this.interaction.editReply(finalMessage);
1298
- this.didReply = true;
1298
+ this.ignoreResponderTimeout = true;
1299
1299
  return { success: true, message: sent };
1300
1300
  }
1301
1301
  else {
1302
1302
  const sent = await this.interaction.reply(finalMessage);
1303
- this.didReply = true;
1303
+ this.ignoreResponderTimeout = true;
1304
1304
  return { success: true, message: await sent.fetch() };
1305
1305
  }
1306
1306
  }
1307
1307
  catch {
1308
- return { success: false, message: null };
1308
+ return { success: false };
1309
1309
  }
1310
1310
  }
1311
1311
  /**Update the message of this context menu. */
@@ -1314,33 +1314,33 @@ export class ODContextMenuResponderInstance extends ODBaseResponderInstance {
1314
1314
  const finalMessage = this.getMessageFromBuildResult(build, "interaction");
1315
1315
  if (this.interaction.replied || this.interaction.deferred) {
1316
1316
  const sent = await this.interaction.editReply(finalMessage);
1317
- this.didReply = true;
1317
+ this.ignoreResponderTimeout = true;
1318
1318
  return { success: true, message: await sent.fetch() };
1319
1319
  }
1320
1320
  else
1321
1321
  throw new ODSystemError("Unable to update context menu interaction!");
1322
1322
  }
1323
1323
  catch {
1324
- return { success: false, message: null };
1324
+ return { success: false };
1325
1325
  }
1326
1326
  }
1327
1327
  /**Defer this context menu. */
1328
1328
  async defer(type, ephemeral) {
1329
+ this.ignoreResponderTimeout = true;
1329
1330
  if (this.interaction.deferred || this.interaction.replied)
1330
1331
  return false;
1331
1332
  if (type == "reply") {
1332
1333
  const msgFlags = ephemeral ? [discord.MessageFlags.Ephemeral] : [];
1333
1334
  await this.interaction.deferReply({ flags: msgFlags });
1334
1335
  }
1335
- this.didReply = true;
1336
1336
  return true;
1337
1337
  }
1338
1338
  /**Show a modal as reply to this context menu. */
1339
1339
  async modal(modal) {
1340
+ this.ignoreResponderTimeout = true;
1340
1341
  if (this.interaction.deferred || this.interaction.replied)
1341
1342
  return false;
1342
1343
  await this.interaction.showModal(modal.modal);
1343
- this.didReply = true;
1344
1344
  return true;
1345
1345
  }
1346
1346
  }
@@ -0,0 +1,126 @@
1
+ import { ODManager, ODValidId, ODManagerData, ODNoGeneric } from "./base.js";
2
+ import { ODClientManager } from "./client.js";
3
+ import { ODDebugger } from "./console.js";
4
+ import { ODDatabase, ODDatabaseIdConstraint } from "./database.js";
5
+ import * as discord from "discord.js";
6
+ /**## ODStateKey `type`
7
+ * The key template for message states.
8
+ */
9
+ export interface ODStateKey {
10
+ /**A valid discord server/guild ID or instance. */
11
+ guild?: discord.Guild | string | null;
12
+ /**A valid discord channel ID or instance. */
13
+ channel: discord.Channel | string;
14
+ /**A valid discord message ID or instance. */
15
+ message: discord.Message | string;
16
+ /**A valid discord user ID or instance. */
17
+ user?: discord.User | discord.GuildMember | string | null;
18
+ }
19
+ /**## ODStateData `type`
20
+ * The raw data template for message states used for storing in the database.
21
+ */
22
+ export interface ODStateData<StateData extends any> {
23
+ /**The linked Guild ID of this message state. */
24
+ guildId: string | null;
25
+ /**The linked Channel ID of this message state. */
26
+ channelId: string;
27
+ /**The linked Message ID of this message state. */
28
+ messageId: string;
29
+ /**The linked User ID of this message state. */
30
+ userId: string | null;
31
+ /**The creation date of this state (UNIX TIMESTAMP). */
32
+ createdDate: number;
33
+ /**The modified date of this state (UNIX TIMESTAMP). */
34
+ modifiedDate: number;
35
+ /**Optional date after which this state should be regarded as expired (UNIX TIMESTAMP). */
36
+ deleteAfterDate: number | null;
37
+ /**The state data. */
38
+ data: StateData;
39
+ }
40
+ /**## ODStateSettings `type`
41
+ * Configurable settings for an ODState.
42
+ */
43
+ export interface ODStateSettings {
44
+ /**(Default: `false`) Completely disable autodelete of message states. (unless manually activated using other settings) */
45
+ disableAutodelete: boolean;
46
+ /**(Default: `true`) Delete state on channel deletion. */
47
+ autodeleteOnChannelDelete: boolean;
48
+ /**(Default: `true`) Delete state on message deletion. */
49
+ autodeleteOnMessageDelete: boolean;
50
+ /**(Default: `true`) Delete state when the user leaves the guild/server. */
51
+ autodeleteOnUserLeave: boolean;
52
+ /**(Default: `false`) Delete state on bot restart. */
53
+ autodeleteOnRestart: boolean;
54
+ /**(Default: `true`) Delete state after 1 hour of an ephemeral message being sent. */
55
+ autodeleteOnEphemeral: boolean;
56
+ /**(Default: `null`) Delete state when unmodified/inactive for more than.... */
57
+ autodeleteAfterTimeout: null | {
58
+ time: number;
59
+ unit: "seconds" | "minutes" | "hours" | "days";
60
+ };
61
+ }
62
+ /**## ODState `class`
63
+ * An Open Discord state is a system for storing additional chunks of metadata for Discord messages.
64
+ * A system for tracking messages or linking metadata, states or progress to Discord messages (ID-based).
65
+ *
66
+ * Features automatic garbage collection to clear expired states.
67
+ */
68
+ export declare class ODState<StateData extends any> extends ODManagerData {
69
+ /**Alias to Open Discord message states database. */
70
+ protected database: ODDatabase<ODDatabaseIdConstraint>;
71
+ /**Alias to Open Discord client manager. */
72
+ protected client: ODClientManager;
73
+ /**Alias to Open Discord debugger. */
74
+ protected debug: ODDebugger | null;
75
+ /**The settings of this state. */
76
+ settings: ODStateSettings;
77
+ constructor(id: ODValidId, client: ODClientManager, database: ODDatabase<ODDatabaseIdConstraint>, settings: Partial<ODStateSettings>);
78
+ /**Use the Open Discord debugger in this manager for logs. */
79
+ useDebug(debug?: ODDebugger | null): void;
80
+ /**Init the state and start autodeleting. The client must already be logged-in for this to work. */
81
+ init(): Promise<void>;
82
+ /**Purge all expired message states that reached a timeout or ephemeral. */
83
+ protected purgeExpiredStates(): Promise<void>;
84
+ /**Transform the object-based message state key contents to a string. */
85
+ protected transformKey(key: ODStateKey): string;
86
+ /**Transform the message state data contents for storage in the database. */
87
+ protected transformData(key: ODStateKey, data: StateData, isEphemeral: boolean, keepCreatedDate?: number): ODStateData<StateData>;
88
+ /**Calculate milliseconds from a time + unit. */
89
+ protected timeoutToUnixTime(): number | null;
90
+ /**Set a message state using guild, channel & message id as key. Returns `true` when overwritten. */
91
+ setMsgState(key: ODStateKey, data: StateData, isEphemeral: boolean): Promise<boolean>;
92
+ /**Get a message state using guild, channel & message id as key. */
93
+ getMsgState(key: ODStateKey): Promise<ODStateData<StateData> | null>;
94
+ /**Delete a message state using guild, channel & message id as key. Returns `true` when deleted. */
95
+ deleteMsgState(key: ODStateKey): Promise<boolean>;
96
+ /**List all message states of this `ODState`. */
97
+ listMsgStates(): Promise<{
98
+ key: string;
99
+ value: ODStateData<StateData>;
100
+ }[]>;
101
+ /**Delete all message states from this ODState. */
102
+ clearAllMsgStates(): Promise<void>;
103
+ /**Delete a message state using the raw key. Returns `true` when deleted. */
104
+ protected deleteMsgStateWithRawKey(rawKey: string): Promise<boolean>;
105
+ }
106
+ /**## ODStateManagerIdConstraint `type`
107
+ * The constraint/layout for id mappings/interfaces of the `ODStateManager` class.
108
+ */
109
+ export type ODStateManagerIdConstraint = Record<string, ODState<any>>;
110
+ /**## ODStateManager `class`
111
+ * The Open Discord state manager is a system for tracking messages or linking metadata, states or progress to Discord messages (ID-based).
112
+ *
113
+ * Features automatic garbage collection to clear expired states.
114
+ */
115
+ export declare class ODStateManager<IdList extends ODStateManagerIdConstraint = ODStateManagerIdConstraint> extends ODManager<ODState<any>> {
116
+ constructor(debug: ODDebugger);
117
+ /**Init all states. */
118
+ init(): Promise<void>;
119
+ add(data: ODState<any>, overwrite?: boolean): boolean;
120
+ get<StateId extends keyof ODNoGeneric<IdList>>(id: StateId): IdList[StateId];
121
+ get(id: ODValidId): ODState<any> | null;
122
+ remove<StateId extends keyof ODNoGeneric<IdList>>(id: StateId): IdList[StateId];
123
+ remove(id: ODValidId): ODState<any> | null;
124
+ exists(id: keyof ODNoGeneric<IdList>): boolean;
125
+ exists(id: ODValidId): boolean;
126
+ }