@p-sw/brainbox 0.1.2-alpha.6 → 0.1.2-alpha.7

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.
Files changed (2) hide show
  1. package/dist/index.js +15 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3356,7 +3356,7 @@ class BaseChannel {
3356
3356
  }, callback);
3357
3357
  }
3358
3358
  getRegisteredCrons() {
3359
- return scheduledJobs.filter((c) => c.name && c.name.startsWith(this.resolveCronPrefix())).map((c) => c.name);
3359
+ return scheduledJobs.filter((c) => c.name && c.name.startsWith(this.resolveCronPrefix()));
3360
3360
  }
3361
3361
  pauseCron(key) {
3362
3362
  const job = scheduledJobs.find((c) => c.name === this.resolveCronName(key));
@@ -3447,6 +3447,13 @@ class BaseChannel {
3447
3447
  this.isChattingDebounce = null;
3448
3448
  }, IS_CHATTING_DEBOUNCE_MS);
3449
3449
  }
3450
+ async initAvailability() {
3451
+ const current = await this.brain.getAvailability();
3452
+ this.previousAvailability = current.status;
3453
+ logger.debug(`initAvailability: ${current.status}`);
3454
+ await this.setAvailability(current.status);
3455
+ this.ensureAvailabilityWatcher();
3456
+ }
3450
3457
  ensureAvailabilityWatcher() {
3451
3458
  if (this.isCronStarted(AVAILABILITY_WATCHER_KEY))
3452
3459
  return;
@@ -3456,6 +3463,9 @@ class BaseChannel {
3456
3463
  const prev = this.previousAvailability;
3457
3464
  this.previousAvailability = current.status;
3458
3465
  logger.debug(`availabilityWatcher: ${prev ?? "(initial)"} → ${current.status}`);
3466
+ if (prev !== current.status) {
3467
+ await this.setAvailability(current.status);
3468
+ }
3459
3469
  if (prev !== null && prev !== "online" && current.status === "online") {
3460
3470
  await this.flushDeferred();
3461
3471
  }
@@ -3516,8 +3526,8 @@ class BaseChannel {
3516
3526
  logger.debug(`shutdown: done`);
3517
3527
  }
3518
3528
  stopOwnCrons() {
3519
- for (const key of this.getRegisteredCrons()) {
3520
- this.removeCron(key);
3529
+ for (const cron of this.getRegisteredCrons()) {
3530
+ cron.stop();
3521
3531
  }
3522
3532
  }
3523
3533
  clearTimers() {
@@ -3627,6 +3637,7 @@ class DiscordChannel extends BaseChannel {
3627
3637
  logger.debug(`DiscordClientReady: resolving configured channel ${channelId}`);
3628
3638
  this.resolveConfiguredChannel(channelId);
3629
3639
  }
3640
+ this.initAvailability();
3630
3641
  });
3631
3642
  this.client.on(Events.MessageCreate, (msg) => {
3632
3643
  if (msg.author.bot)
@@ -3795,6 +3806,7 @@ class TelegramChannel extends BaseChannel {
3795
3806
  this.registerActive();
3796
3807
  this.bot.onStart(({ info }) => {
3797
3808
  logger.success(`Telegram ready as @${info.username}`);
3809
+ this.initAvailability();
3798
3810
  });
3799
3811
  this.bot.on("message", (ctx) => {
3800
3812
  if (ctx.from?.isBot())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@p-sw/brainbox",
3
- "version": "0.1.2-alpha.6",
3
+ "version": "0.1.2-alpha.7",
4
4
  "module": "dist/index.js",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",