upgrade dependencies

This commit is contained in:
2024-05-26 13:14:12 +02:00
parent f2acf36b77
commit 8508640b83
5 changed files with 679 additions and 216 deletions
Generated
+641 -178
View File
File diff suppressed because it is too large Load Diff
+11 -11
View File
@@ -7,20 +7,20 @@ edition = "2021"
[dependencies] [dependencies]
rss = "2.0" rss = "2.0"
reqwest = {version = "0.11", default-features = false, features = ["rustls"]} reqwest = {version = "0.12", default-features = false, features = ["rustls-tls"]}
tokio = {version = "1.28", features = ["rt-multi-thread", "signal"]} tokio = {version = "1.37", features = ["rt-multi-thread", "signal"]}
lazy-regex = "3.0.2" lazy-regex = "3.1.0"
chrono = "0.4.25" chrono = "0.4.38"
chrono-tz = "0.8.2" chrono-tz = "0.9.0"
anyhow = "1.0.71" anyhow = "1.0.86"
log = "0.4.18" log = "0.4.21"
env_logger = "0.10.0" env_logger = "0.11.3"
dotenvy = "0.15.7" dotenvy = "0.15.7"
diesel = { version = "2.1.3", features = ["sqlite", "chrono"] } diesel = { version = "2.1.6", features = ["sqlite", "chrono"] }
diesel_migrations = "2.1.0" diesel_migrations = "2.1.0"
getset = "0.1.2" getset = "0.1.2"
[dependencies.serenity] [dependencies.serenity]
version = "0.11" version = "0.12"
default-features = false default-features = false
features = ["builder", "cache", "client", "gateway", "http", "model", "utils", "rustls_backend"] features = ["builder", "cache", "chrono", "client", "gateway", "http", "model", "utils", "rustls_backend"]
+1 -1
View File
@@ -34,7 +34,7 @@ async fn main() -> anyhow::Result<()> {
None => false, None => false,
}; };
if let Some(_) = args.next() { if args.next().is_some() {
return Err(anyhow!("too many arguments")); return Err(anyhow!("too many arguments"));
} }
+4 -4
View File
@@ -17,11 +17,11 @@ pub struct Post {
impl Post { impl Post {
pub fn webhook_id(&self) -> WebhookId { pub fn webhook_id(&self) -> WebhookId {
WebhookId(u64::from_le_bytes(self.webhook_id.to_le_bytes())) WebhookId::new(u64::from_le_bytes(self.webhook_id.to_le_bytes()))
} }
pub fn message_id(&self) -> MessageId { pub fn message_id(&self) -> MessageId {
MessageId(u64::from_le_bytes(self.message_id.to_le_bytes())) MessageId::new(u64::from_le_bytes(self.message_id.to_le_bytes()))
} }
} }
@@ -43,8 +43,8 @@ impl<'a> NewPost<'a> {
) -> Self { ) -> Self {
Self { Self {
announcement_id: announcement_id.into(), announcement_id: announcement_id.into(),
webhook_id: i64::from_le_bytes(webhook_id.0.to_le_bytes()), webhook_id: i64::from_le_bytes(webhook_id.get().to_le_bytes()),
message_id: i64::from_le_bytes(message_id.0.to_le_bytes()), message_id: i64::from_le_bytes(message_id.get().to_le_bytes()),
last_updated, last_updated,
} }
} }
+22 -22
View File
@@ -9,9 +9,8 @@ use diesel::{ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl};
use lazy_regex::regex; use lazy_regex::regex;
use log::{debug, error, info}; use log::{debug, error, info};
use reqwest::IntoUrl; use reqwest::IntoUrl;
use serenity::all::{CreateEmbed, CreateEmbedFooter, EditWebhookMessage, ExecuteWebhook};
use serenity::http::Http; use serenity::http::Http;
use serenity::json::Value;
use serenity::model::channel::Embed;
use serenity::model::webhook::Webhook; use serenity::model::webhook::Webhook;
pub struct DisbahnClient { pub struct DisbahnClient {
@@ -78,7 +77,7 @@ impl DisbahnClient {
} }
} }
fn item_to_embed(item: &rss::Item) -> anyhow::Result<Value> { fn item_to_embed(item: &rss::Item) -> anyhow::Result<CreateEmbed> {
const FOOTER_ICON_URL: &str = "https://www.zuginfo.nrw/img/customer/apple-touch-icon.png"; const FOOTER_ICON_URL: &str = "https://www.zuginfo.nrw/img/customer/apple-touch-icon.png";
let categories = item.categories(); let categories = item.categories();
@@ -117,11 +116,8 @@ impl DisbahnClient {
.naive_utc() .naive_utc()
.and_utc(); .and_utc();
let pub_timestamp = pub_datetime.to_rfc3339_opts(chrono::SecondsFormat::Secs, true); let embed = CreateEmbed::new()
.title(title)
let embed =
Embed::fake(|e| {
e.title(title)
.url(link) .url(link)
.thumbnail(icon_url) .thumbnail(icon_url)
.colour(Self::icon_name_to_colour(icon)) .colour(Self::icon_name_to_colour(icon))
@@ -129,12 +125,13 @@ impl DisbahnClient {
.field("Beginn:", format!("<t:{}:F>", validity_begin), true) .field("Beginn:", format!("<t:{}:F>", validity_begin), true)
.field("Ende:", format!("<t:{}:F>", validity_end), true) .field("Ende:", format!("<t:{}:F>", validity_end), true)
.field("Hinweis:", include_str!("hint.txt"), false) .field("Hinweis:", include_str!("hint.txt"), false)
.timestamp(pub_timestamp) .timestamp(pub_datetime)
.footer(|f| { .footer(
f.text("Quelle: https://zuginfo.nrw/ \u{2013} Alle Angaben ohne Gewehr \u{1F52B}") CreateEmbedFooter::new(
.icon_url(FOOTER_ICON_URL) "Quelle: https://zuginfo.nrw/ \u{2013} Alle Angaben ohne Gewehr \u{1F52B}",
}) )
}); .icon_url(FOOTER_ICON_URL),
);
Ok(embed) Ok(embed)
} }
@@ -169,7 +166,7 @@ impl DisbahnClient {
.and_utc(); .and_utc();
let existing_post: Option<Post> = posts let existing_post: Option<Post> = posts
.filter(dsl::webhook_id.eq(i64::from_le_bytes(self.webhook.id.0.to_le_bytes()))) .filter(dsl::webhook_id.eq(i64::from_le_bytes(self.webhook.id.get().to_le_bytes())))
.filter(dsl::announcement_id.eq(guid)) .filter(dsl::announcement_id.eq(guid))
.first(self.database.conn()) .first(self.database.conn())
.optional() .optional()
@@ -180,15 +177,18 @@ impl DisbahnClient {
info!("Updated item: {guid}"); info!("Updated item: {guid}");
let embed = Self::item_to_embed(item)?; let embed = Self::item_to_embed(item)?;
self.webhook self.webhook
.edit_message(&self.http, existing_post.message_id(), |w| { .edit_message(
w.embeds(vec![embed]) &self.http,
}) existing_post.message_id(),
EditWebhookMessage::new().add_embed(embed),
)
.await .await
.with_context(|| "Failed to edit message")?; .with_context(|| "Failed to edit message")?;
diesel::update( diesel::update(posts.find((
posts.find((guid, i64::from_le_bytes(self.webhook.id.0.to_le_bytes()))), guid,
) i64::from_le_bytes(self.webhook.id.get().to_le_bytes()),
)))
.set(dsl::last_updated.eq(pub_datetime.naive_utc())) .set(dsl::last_updated.eq(pub_datetime.naive_utc()))
.execute(self.database.conn()) .execute(self.database.conn())
.with_context(|| "Error updating post in database")?; .with_context(|| "Error updating post in database")?;
@@ -198,7 +198,7 @@ impl DisbahnClient {
let embed = Self::item_to_embed(item)?; let embed = Self::item_to_embed(item)?;
let message = self let message = self
.webhook .webhook
.execute(&self.http, true, |w| w.embeds(vec![embed])) .execute(&self.http, true, ExecuteWebhook::new().embed(embed))
.await .await
.with_context(|| "Failed to send message")? .with_context(|| "Failed to send message")?
.with_context(|| "Discord did not return a message id")?; .with_context(|| "Discord did not return a message id")?;