Skip to content

Commit

Permalink
Add 1KV online/offline notification setting to the Telegram bot setti…
Browse files Browse the repository at this point in the history
…ngs menu. Correct the 1KV online status change notification generator logic.
  • Loading branch information
kukabi committed Apr 29, 2022
1 parent 22c743c commit 6599d52
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion _template/email/chain_validator_offline_offence.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<strong>{{ validator_display }}</strong>
🆘 was found to be <strong>offline</strong> at the end of the session{% if notification_period_type %} in the last {% if notification_period > 1 %}{{ notification_period }} {% endif %}{{ notification_period_type }}{% if notification_period > 1 %}s{% endif %}{% endif %}!
This is going to cause the involuntary chilling of the validator.
This is going to cause the involuntary chilling of the validator if it hasn't been chilled already.
You may view the corresponding on-chain event <a href="https://{{ chain }}.subscan.io/block/{{ block_hash }}?tab=event">here</a>.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{ validator_display }}
🆘 was found to be offline at the end of the session{% if notification_period_type %} in the last {% if notification_period > 1 %}{{ notification_period }} {% endif %}{{ notification_period_type }}{% if notification_period > 1 %}s{% endif %}{% endif %}!
This is going to cause the involuntary chilling of the validator.
This is going to cause the involuntary chilling of the validator if it hasn't been chilled already.
2 changes: 1 addition & 1 deletion _template/telegram/chain_validator_offline_offence.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<strong>{{ validator_display }}</strong>
🆘 was found to be <strong>offline</strong> at the end of the session{% if notification_period_type %} in the last {% if notification_period > 1 %}{{ notification_period }} {% endif %}{{ notification_period_type }}{% if notification_period > 1 %}s{% endif %}{% endif %}!
This is going to cause the involuntary chilling of the validator.
This is going to cause the involuntary chilling of the validator if it hasn't been chilled already.
You may view the corresponding on-chain event <a href="https://{{ chain }}.subscan.io/block/{{ block_hash }}?tab=event">here</a>.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% if is_on %}🟢{% else %}⚪️{% endif %} Online / Offline
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl NotificationGenerator {
),
_ => return Ok(()),
};
if current_online_since != last_online_since || current_offline_since != last_offline_since
if (current_online_since > 0 && last_online_since == 0)
|| (current_offline_since > 0 && last_offline_since == 0)
{
log::debug!(
"1KV online status (online_since, offline_since) of {} changed from {:?} to {:?}.",
Expand Down
8 changes: 8 additions & 0 deletions subvt-telegram-bot/src/messenger/keyboard/settings/onekv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ impl Messenger {
)? {
rows.push(item);
}
if let Some(item) = self.get_notification_on_off_button(
NotificationTypeCode::OneKVValidatorOnlineStatusChange,
"settings_item_onekv_online_status_change.html",
SettingsEditQueryType::OneKVOnlineStatusChange,
notification_rules,
)? {
rows.push(item);
}
if let Some(item) = self.get_notification_on_off_button(
NotificationTypeCode::OneKVValidatorRankChange,
"settings_item_onekv_rank_change.html",
Expand Down
2 changes: 2 additions & 0 deletions subvt-telegram-bot/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,6 @@ pub enum SettingsEditQueryType {
OneKVValidityChange,
#[serde(rename = "OKVL")]
OneKVLocationChange,
#[serde(rename = "OKVO")]
OneKVOnlineStatusChange,
}
9 changes: 9 additions & 0 deletions subvt-telegram-bot/src/query/process/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ impl TelegramBot {
.await?;
SettingsSubSection::OneKV
}
SettingsEditQueryType::OneKVOnlineStatusChange => {
self.process_notification_on_off_setting_query(
user_id,
query,
NotificationTypeCode::OneKVValidatorOnlineStatusChange,
)
.await?;
SettingsSubSection::OneKV
}
};
let notification_rules = self
.app_postgres
Expand Down

0 comments on commit 6599d52

Please sign in to comment.