Better error handling if pinning/unpinning the announcement message fails
This commit is contained in:
34
src/bot.rs
34
src/bot.rs
@@ -163,6 +163,24 @@ pub async fn fetch_and_announce_appointment(
|
||||
)
|
||||
.await?;
|
||||
|
||||
if let Some(pinned_message_id) = entry.pinned_message_id {
|
||||
let mut unpin_message = bot.unpin_chat_message(ChatId(chat_info.id));
|
||||
unpin_message.message_id = Some(MessageId(pinned_message_id));
|
||||
_ = unpin_message.await;
|
||||
}
|
||||
|
||||
let mut pin_message = bot.pin_chat_message(announcement.chat.id, announcement.id);
|
||||
pin_message.disable_notification = Some(false);
|
||||
let pin_sucessful = pin_message.await.is_ok();
|
||||
|
||||
chat_info.next_appointment = Some(appointment.clone());
|
||||
chat_info.last_reminder = Some(now);
|
||||
chat_info.pinned_message_id = if pin_sucessful {
|
||||
Some(announcement.id.0)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
db.lock().await.transaction(|db| {
|
||||
use schema::chat::dsl::*;
|
||||
diesel::update(chat.filter(telegram_id.eq(chat_info.id)))
|
||||
@@ -170,24 +188,10 @@ pub async fn fetch_and_announce_appointment(
|
||||
next_appointment_start.eq(appointment.start.timestamp()),
|
||||
next_appointment_end.eq(appointment.end.timestamp()),
|
||||
last_reminder.eq(now.timestamp()),
|
||||
pinned_message_id.eq(announcement.id.0),
|
||||
pinned_message_id.eq(chat_info.pinned_message_id),
|
||||
))
|
||||
.execute(db)
|
||||
})?;
|
||||
|
||||
chat_info.next_appointment = Some(appointment);
|
||||
chat_info.last_reminder = Some(now);
|
||||
chat_info.pinned_message_id = Some(announcement.id.0);
|
||||
|
||||
if let Some(pinned_message_id) = entry.pinned_message_id {
|
||||
let mut unpin_message = bot.unpin_chat_message(ChatId(chat_info.id));
|
||||
unpin_message.message_id = Some(MessageId(pinned_message_id));
|
||||
unpin_message.await?;
|
||||
}
|
||||
|
||||
let mut pin_message = bot.pin_chat_message(announcement.chat.id, announcement.id);
|
||||
pin_message.disable_notification = Some(false);
|
||||
pin_message.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user