Skip to content

Commit

Permalink
Fixed sending messages from notification-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
crycode-de committed Sep 4, 2023
1 parent fb13a18 commit 0c25233
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
18 changes: 12 additions & 6 deletions build/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build/main.js.map

Large diffs are not rendered by default.

19 changes: 12 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2782,11 +2782,11 @@ class DiscordAdapter extends Adapter {

if (!this.config.sendNotificationsTo) {
this.log.debug(`New notification received from ${obj.from}, but sending notifications is not enabled in adapter config`);
this.sendTo(obj.from, obj.command, { send: false }, obj.callback);
this.sendTo(obj.from, obj.command, { sent: false }, obj.callback);
return;
}

this.log.info(`New notification received from ${obj.from}`);
this.log.info(`New notification received from ${obj.from.replace(/^system\.adapter\./, '')}`);

let target: User | TextChannel | undefined = undefined;

Expand All @@ -2804,7 +2804,7 @@ class DiscordAdapter extends Adapter {

if (!target) {
this.log.error(`Cannot send notification because the configured target is invalid!`);
this.sendTo(obj.from, obj.command, { send: false }, obj.callback);
this.sendTo(obj.from, obj.command, { sent: false }, obj.callback);
return;
}

Expand All @@ -2813,7 +2813,7 @@ class DiscordAdapter extends Adapter {
// check the message object
if (!message?.category?.instances || !message.category.name) {
this.log.warn(`Cannot send notification because the received message object is invalid`);
this.sendTo(obj.from, obj.command, { send: false }, obj.callback);
this.sendTo(obj.from, obj.command, { sent: false }, obj.callback);
return;
}

Expand Down Expand Up @@ -2841,9 +2841,14 @@ ${message.category.description ?? ''}
${message.host}:
${readableInstances.join('\n')}`;

await target.send(text);

this.sendTo(obj.from, obj.command, { send: true }, obj.callback);
try {
const msg = await target.send(text);
this.log.debug(`Sent message from notification-manager adapter with message ID ${msg.id}`);
this.sendTo(obj.from, obj.command, { sent: true }, obj.callback);
} catch (err) {
this.log.warn(`Error sending message from notification-manager adapter: ${err}`);
this.sendTo(obj.from, obj.command, { sent: false }, obj.callback);
}

break;

Expand Down

0 comments on commit 0c25233

Please sign in to comment.