Skip to content

Commit

Permalink
(simatec) Bugfix System-Message
Browse files Browse the repository at this point in the history
  • Loading branch information
simatec committed Aug 15, 2023
1 parent 13307cd commit e59a1c7
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 42 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ When the adapter crashes or another Code error happens, this error message that
<!-- ### **WORK IN PROGRESS** -->
### **WORK IN PROGRESS**
* (simatec) small Sentry fixes
* (simatec) Bugfix System-Message

### 2.7.0 (2023-08-14)
* (simatec) dependencies updated
Expand Down
141 changes: 101 additions & 40 deletions lib/systemCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,67 +39,128 @@ async function storageSizeCheck(options, adapterName, log) {
});
}

function systemMessage(options, sendTo, sysMessage) {
if (options.notificationEnabled) {
switch (options.notificationsType) {
function systemMessage(options, sysMessage) {
if (options.config.notificationEnabled) {
switch (options.config.notificationsType) {
case 'Telegram':
if (options.telegramUser && options.telegramUser === 'allTelegramUsers' && options.telegramInstance) {
sendTo(options.telegramInstance, 'send', { text: 'BackItUp:\n' + sysMessage, disable_notification: options.telegramSilentNotice });
} else if (options.telegramInstance) {
sendTo(options.telegramInstance, 'send', { user: options.telegramUser, text: 'BackItUp:\n' + sysMessage, disable_notification: options.telegramSilentNotice });
if (options.config.telegramUser && options.config.telegramUser === 'allTelegramUsers' && options.config.telegramInstance) {
try {
options.sendTo(options.config.telegramInstance, 'send', {
text: `BackItUp:\n${sysMessage}`,
disable_notification: options.config.telegramSilentNotice
});
} catch (err) {
log.warn(`Error sending Telegram message: ${err}`)
}
} else if (options.config.telegramInstance) {
try {
options.sendTo(options.config.telegramInstance, 'send', {
user: options.config.telegramUser,
text: `BackItUp:\n${sysMessage}`,
disable_notification: options.config.telegramSilentNotice
});
} catch (err) {
log.warn(`Error sending Telegram message: ${err}`)
}
}
break;
case 'E-Mail':
if (options.emailInstance && options.emailReceiver && options.emailSender) {
sendTo(options.emailInstance, 'send', { text: 'BackItUp:\n' + sysMessage, to: options.emailReceiver, subject: 'Backitup', from: options.emailSender });
if (options.config.emailInstance && options.config.emailReceiver && options.config.emailSender) {
try {
options.sendTo(options.config.emailInstance, 'send', {
text: `BackItUp:\n${sysMessage}`,
to: options.config.emailReceiver,
subject: 'Backitup',
from: options.config.emailSender
});
} catch (err) {
log.warn(`Error sending E-Mail message: ${err}`)
}
}
break;
case 'Pushover':
if ((options.pushoverSilentNotice === 'true' || options.pushoverSilentNotice === true) && options.pushoverInstance && options.pushoverDeviceID) {
sendTo(options.pushoverInstance, 'send', { message: 'BackItUp:\n' + sysMessage, sound: '', priority: -1, title: 'Backitup', device: options.pushoverDeviceID });
} else if (options.pushoverInstance && options.pushoverDeviceID) {
sendTo(options.pushoverInstance, 'send', { message: 'BackItUp:\n' + sysMessage, sound: '', title: 'Backitup', device: options.pushoverDeviceID });
if ((options.config.pushoverSilentNotice === 'true' || options.config.pushoverSilentNotice === true) && options.config.pushoverInstance && options.config.pushoverDeviceID) {
try {
options.sendTo(options.config.pushoverInstance, 'send', {
message: `BackItUp:\n${sysMessage}`,
sound: '',
priority: -1,
title: 'Backitup',
device: options.config.pushoverDeviceID
});
} catch (err) {
log.warn(`Error sending Pushover message: ${err}`)
}
} else if (options.config.pushoverInstance && options.config.pushoverDeviceID) {
try {
options.sendTo(options.config.pushoverInstance, 'send', {
message: `BackItUp:\n${sysMessage}`,
sound: '',
title: 'Backitup',
device: options.config.pushoverDeviceID
});
} catch (err) {
log.warn(`Error sending Pushover message: ${err}`)
}
}
break;
case 'WhatsApp':
if (options.whatsappInstance) {
sendTo(options.whatsappInstance, 'send', { text: 'BackItUp:\n' + sysMessage });
if (options.config.whatsappInstance) {
try {
options.sendTo(options.config.whatsappInstance, 'send', {
text: `BackItUp:\n${sysMessage}`
});
} catch (err) {
log.warn(`Error sending WhatsApp message: ${err}`)
}
}
break;
case 'Signal':
if (options.signalInstance) {
sendTo(options.signalInstance, 'send', { text: 'BackItUp:\n' + sysMessage });
if (options.config.signalInstance) {
try {
options.sendTo(options.config.signalInstance, 'send', {
text: `BackItUp:\n${sysMessage}`
});
} catch (err) {
log.warn(`Error sending Signal message: ${err}`)
}
}
break;
case 'Matrix':
if (options.matrixInstance) {
sendTo(options.matrixInstance, 'BackItUp:\n' + sysMessage);
if (options.config.matrixInstance) {
try {
options.sendTo(options.config.matrixInstance, {
text: `BackItUp:\n${sysMessage}`
});
} catch (err) {
log.warn(`Error sending Matrix message: ${err}`)
}
}
break;
case 'Discord':
if (options.discordInstance && options.discordTarget) {
if (options.discordTarget.match(/^\d+$/)) {
if (options.config.discordInstance && options.config.discordTarget) {
if (options.config.discordTarget.match(/^\d+$/)) {
// send to a single user
sendTo(options.discordInstance, 'sendMessage', {
userId: options.discordTarget,
content: '**BackItUp**:\n' + sysMessage,
}, (ret) => {
if (ret.err) {
log.warn(`Error sending Discord message: ${ret.err}`);
}
});
} else if (options.discordTarget.match(/^\d+\/\d+$/)) {
try {
options.sendTo(options.config.discordInstance, 'sendMessage', {
userId: options.config.discordTarget,
content: `BackItUp:\n${sysMessage}`,
});
} catch (err) {
log.warn(`Error sending Discord message: ${err}`)
}
} else if (options.config.discordTarget.match(/^\d+\/\d+$/)) {
// send to a server channel
const [ serverId, channelId ] = options.discordTarget.split('/');
sendTo(options.discordInstance, 'sendMessage', {
serverId,
channelId,
content: '**BackItUp**:\n' + sysMessage,
}, (ret) => {
if (ret.err) {
log.warn(`Error sending Discord message: ${ret.err}`);
}
});
const [serverId, channelId] = options.config.discordTarget.split('/');
try {
options.sendTo(options.config.discordInstance, 'sendMessage', {
serverId,
channelId,
content: `BackItUp:\n${sysMessage}`,
});
} catch (err) {
log.warn(`Error sending Discord message: ${err}`)
}
}
}
break;
Expand Down
4 changes: 2 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function startAdapter(options) {
});
} else {
adapter.log.error(`A local backup is currently not possible. The storage space is currently only ${sysCheck && sysCheck.diskFree ? sysCheck.diskFree : null} MB`);
systemCheck.systemMessage(adapter.config, adapter.sendTo, tools._('A local backup is currently not possible. Please check your System!', systemLang));
systemCheck.systemMessage(adapter, tools._('A local backup is currently not possible. Please check your System!', systemLang));
adapter.setState('oneClick.' + type, false, true);
adapter.setState('output.line', `[EXIT] ${tools._('A local backup is currently not possible. Please check your System!', systemLang)}`, true);
}
Expand Down Expand Up @@ -565,7 +565,7 @@ function createBackupSchedule() {
});
} else {
adapter.log.error(`A local backup is currently not possible. The storage space is currently only ${sysCheck && sysCheck.diskFree ? sysCheck.diskFree : null} MB`);
systemCheck.systemMessage(adapter.config, adapter.sendTo, tools._('A local backup is currently not possible. Please check your System!', systemLang));
systemCheck.systemMessage(adapter, tools._('A local backup is currently not possible. Please check your System!', systemLang));
}
});

Expand Down

0 comments on commit e59a1c7

Please sign in to comment.