Skip to content

Commit

Permalink
Dependency updates: frankenstein and syn. Some minor template changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed May 11, 2022
1 parent ca8c6c3 commit 8000a58
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 68 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions _template/telegram/dialog/nomination_details.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% set list_limit = 20 %}<strong>{{ validator_display }}</strong>
👤 Self Stake: <strong>{{ self_stake }} {{ token_ticker }}</strong>
{% if active_nominations %}
<strong>▶️ ACTIVE {{ active_nomination_total}} {{ token_ticker }}</strong>{% for active_nomination in active_nominations | slice(end=list_limit) %}
<strong>🟢️️️ ACTIVE {{ active_nomination_total}} {{ token_ticker }}</strong>{% for active_nomination in active_nominations | slice(end=list_limit) %}
<pre>{{ active_nomination.1 }}</pre><pre>{{ active_nomination.0 | truncate(length=9) }}{% if active_nomination.2 %} (1KV){% endif %}</pre>{% endfor %}{% if active_nominations | length > list_limit %}
<i>...{{ active_nominations | length - list_limit }} more</i>
{% endif %}{% else %}▶️ No active nominations.{% endif %}
{% if inactive_nominations %}
<strong> INACTIVE {{ inactive_nomination_total}} {{ token_ticker }}</strong>{% for inactive_nomination in inactive_nominations | slice(end=list_limit) %}
<strong>⚪️ INACTIVE {{ inactive_nomination_total}} {{ token_ticker }}</strong>{% for inactive_nomination in inactive_nominations | slice(end=list_limit) %}
<pre>{{ inactive_nomination.1 }}</pre><pre>{{ inactive_nomination.0 | truncate(length=9) }}{% if inactive_nomination.2 %} (1KV){% endif %}</pre>{% endfor %}{% if inactive_nominations | length > list_limit %}
<i>...{{ inactive_nominations | length - list_limit }} more</i>
{% endif %}{% else %}⏸ No inactive nominations.{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion _template/telegram/dialog/nomination_summary.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<strong>{{ validator_display }}</strong>
👤 Self Stake: <strong>{{ self_stake }} {{ token_ticker }}</strong>
🟢️️️ Active: <strong>{{ active_nomination_total }} {{ token_ticker }}</strong>{% if active_nominator_count > 0 %} from <strong>{{ active_nominator_count }}</strong> {% if active_nominator_count == 1 %}nominator{% else %}nominators{% endif %} and self stake{% endif %}
🔴 Inactive: <strong>{{ inactive_nomination_total }} {{ token_ticker }}</strong>{% if inactive_nominator_count > 0 %} from <strong>{{ inactive_nominator_count }}</strong> {% if inactive_nominator_count == 1 %}nominator{% else %}nominators{% endif %}{% endif %}
⚪️ Inactive: <strong>{{ inactive_nomination_total }} {{ token_ticker }}</strong>{% if inactive_nominator_count > 0 %} from <strong>{{ inactive_nominator_count }}</strong> {% if inactive_nominator_count == 1 %}nominator{% else %}nominators{% endif %}{% endif %}
2 changes: 1 addition & 1 deletion _template/telegram/dialog/validators_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
⭐️ Paravalidator{% endif %}
👤 Self Stake: <strong>{{ validator_summary.self_stake_formatted }} {{ token_ticker }}</strong>
🟢️️ Active nom.s ({{ validator_summary.active_nominator_count }}): <strong>{{ validator_summary.active_nomination_formatted }} {{ token_ticker }}</strong>
🔴 Inactive nom.s ({{ validator_summary.inactive_nominator_count }}): <strong>{{ validator_summary.inactive_nomination_formatted }} {{ token_ticker }}</strong>{% if validator_summary.heartbeat_received %}
⚪️ Inactive nom.s ({{ validator_summary.inactive_nominator_count }}): <strong>{{ validator_summary.inactive_nomination_formatted }} {{ token_ticker }}</strong>{% if validator_summary.heartbeat_received %}
💌 Sent session heartbeat{% endif %}
🗳 {% if validator_summary.missing_referendum_votes | length == 0 %}No missing votes for open referenda{% else %}Hasn't voted for {% for missing_referendum_vote in validator_summary.missing_referendum_votes %}<a href="https://{{ chain }}.polkassembly.io/referendum/{{ missing_referendum_vote }}">{{ missing_referendum_vote }}</a>{% if not loop.last %}, {% endif %}{% endfor %}{% endif %}{% endfor %}{% endif %}
2 changes: 1 addition & 1 deletion subvt-proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ rust-version = "1.60.0"

[dependencies]
proc-macro2 = "1.0.38"
syn = "1.0.91"
syn = "1.0.93"
quote = "1.0.18"
2 changes: 1 addition & 1 deletion subvt-telegram-bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rust-version = "1.60.0"
anyhow = "1.0.57"
async-trait = "0.1.53"
chrono = "0.4.19"
frankenstein = { version = "0.13.0", default-features = false, features = ["async-telegram-trait"] }
frankenstein = { version = "0.15.0", default-features = false, features = ["async-telegram-trait"] }
hyper = "0.14.18"
hyper-multipart-rfc7578 = "0.8.0"
hyper-tls = "0.5.0"
Expand Down
129 changes: 71 additions & 58 deletions subvt-telegram-bot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,15 @@ impl Service for TelegramBot {

async fn run(&'static self) -> anyhow::Result<()> {
log::info!("Telegram bot has started.");

let mut update_params = GetUpdatesParams {
offset: None,
limit: None,
timeout: None,
allowed_updates: Some(vec!["message".to_string(), "callback_query".to_string()]),
allowed_updates: Some(vec![
frankenstein::AllowedUpdate::Message,
frankenstein::AllowedUpdate::CallbackQuery,
]),
};
self.update_metrics_chat_count().await?;
self.update_metrics_validator_count().await?;
Expand All @@ -492,67 +496,76 @@ impl Service for TelegramBot {
Ok(response) => {
for update in response.result {
update_params.offset = Some(update.update_id + 1);
if let Some(message) = update.message {
self.save_or_restore_chat(&message).await?;
tokio::spawn(async move {
if let Err(error) = self.process_message(&message).await {
log::error!(
"Error while processing message #{}: {:?}",
message.message_id,
error
);
let _ = self
.messenger
.send_message(
&self.app_postgres,
&self.network_postgres,
message.chat.id,
Box::new(MessageType::GenericError),
)
.await;
}
});
} else if let Some(callback_query) = update.callback_query {
if let Some(callback_data) = callback_query.data {
if let Some(message) = callback_query.message {
self.save_or_restore_chat(&message).await?;
tokio::spawn(async move {
let query: Query = if let Ok(query) =
serde_json::from_str(&callback_data)
{
query
} else {
// log and ignore unknown query
return log::error!("Unknown query: {}", callback_data);
};
if let Err(error) = tokio::try_join!(
self.reset_chat_state(message.chat.id),
self.process_query(
match update.content {
frankenstein::UpdateContent::Message(message) => {
self.save_or_restore_chat(&message).await?;
tokio::spawn(async move {
if let Err(error) = self.process_message(&message).await {
log::error!(
"Error while processing message #{}: {:?}",
message.message_id,
error
);
let _ = self
.messenger
.send_message(
&self.app_postgres,
&self.network_postgres,
message.chat.id,
Some(message.message_id),
&query
),
self.messenger
.answer_callback_query(&callback_query.id, None),
) {
log::error!(
"Error while processing message #{}: {:?}",
message.message_id,
error
);
let _ = self
.messenger
.send_message(
&self.app_postgres,
&self.network_postgres,
Box::new(MessageType::GenericError),
)
.await;
}
});
}
frankenstein::UpdateContent::CallbackQuery(callback_query) => {
if let Some(callback_data) = callback_query.data {
if let Some(message) = callback_query.message {
self.save_or_restore_chat(&message).await?;
tokio::spawn(async move {
let query: Query = if let Ok(query) =
serde_json::from_str(&callback_data)
{
query
} else {
// log and ignore unknown query
return log::error!(
"Unknown query: {}",
callback_data
);
};
if let Err(error) = tokio::try_join!(
self.reset_chat_state(message.chat.id),
self.process_query(
message.chat.id,
Box::new(MessageType::GenericError),
)
.await;
}
});
Some(message.message_id),
&query
),
self.messenger.answer_callback_query(
&callback_query.id,
None
),
) {
log::error!(
"Error while processing message #{}: {:?}",
message.message_id,
error
);
let _ = self
.messenger
.send_message(
&self.app_postgres,
&self.network_postgres,
message.chat.id,
Box::new(MessageType::GenericError),
)
.await;
}
});
}
}
}
_ => (),
}
}
}
Expand Down

0 comments on commit 8000a58

Please sign in to comment.