mirror of
https://github.com/nelsbrock/disbahn.git
synced 2026-08-14 22:26:49 +02:00
Compare commits
4
Commits
ec707ec4a3
...
b5a058420e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5a058420e
|
||
|
|
dbae6cedf9
|
||
|
|
72b8ef06d0
|
||
|
|
2967e385e5
|
Generated
+710
-608
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -7,7 +7,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rss = "2.0.12"
|
rss = "2.0.12"
|
||||||
reqwest = {version = "0.12.22", default-features = false, features = ["rustls-tls"]}
|
reqwest = "0.13.4"
|
||||||
tokio = {version = "1.47.0", features = ["rt-multi-thread", "signal"]}
|
tokio = {version = "1.47.0", features = ["rt-multi-thread", "signal"]}
|
||||||
lazy-regex = "3.4.1"
|
lazy-regex = "3.4.1"
|
||||||
chrono = "0.4.41"
|
chrono = "0.4.41"
|
||||||
|
|||||||
+14
-15
@@ -1,5 +1,7 @@
|
|||||||
pub mod database;
|
pub mod database;
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use crate::database::models::{NewPost, Post};
|
use crate::database::models::{NewPost, Post};
|
||||||
use crate::database::schema::posts::dsl::posts;
|
use crate::database::schema::posts::dsl::posts;
|
||||||
use crate::database::Database;
|
use crate::database::Database;
|
||||||
@@ -9,7 +11,9 @@ use diesel::{ExpressionMethods, OptionalExtension, QueryDsl, RunQueryDsl};
|
|||||||
use lazy_regex::{regex, Lazy, Regex};
|
use lazy_regex::{regex, Lazy, 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::all::{
|
||||||
|
CreateEmbed, CreateEmbedAuthor, CreateEmbedFooter, EditWebhookMessage, ExecuteWebhook,
|
||||||
|
};
|
||||||
use serenity::http::Http;
|
use serenity::http::Http;
|
||||||
use serenity::model::webhook::Webhook;
|
use serenity::model::webhook::Webhook;
|
||||||
|
|
||||||
@@ -46,7 +50,7 @@ impl DisbahnClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn html_to_discord_markdown(input: &str) -> String {
|
fn html_to_discord_markdown(input: &str) -> String {
|
||||||
static RE_TIMES: &Lazy<Regex> = regex!(r#"^.*<br\s*/>\s*<br\s*/>"#i);
|
static RE_TIMES: &Lazy<Regex> = regex!(r#"^.*?<br\s*/>\s*<br\s*/>"#i);
|
||||||
static RE_BOLD: &Lazy<Regex> = regex!(r#"<b\s*>((.|\n)*?)</b\s*>"#i);
|
static RE_BOLD: &Lazy<Regex> = regex!(r#"<b\s*>((.|\n)*?)</b\s*>"#i);
|
||||||
static RE_ITALIC: &Lazy<Regex> = regex!(r#"<i\s*>((.|\n)*?)</i\s*>"#i);
|
static RE_ITALIC: &Lazy<Regex> = regex!(r#"<i\s*>((.|\n)*?)</i\s*>"#i);
|
||||||
static RE_STRIKETHROUGH: &Lazy<Regex> = regex!(r#"<s\s*>((.|\n)*?)</s\s*>"#i);
|
static RE_STRIKETHROUGH: &Lazy<Regex> = regex!(r#"<s\s*>((.|\n)*?)</s\s*>"#i);
|
||||||
@@ -60,12 +64,12 @@ impl DisbahnClient {
|
|||||||
input.to_string()
|
input.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn icon_name_to_url(name: &str) -> &str {
|
fn icon_name_to_tag(name: &str) -> Cow<'static, str> {
|
||||||
match name {
|
match name {
|
||||||
"HIM1" => "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Zeichen_123_-_Arbeitsstelle%2C_StVO_2013.svg/273px-Zeichen_123_-_Arbeitsstelle%2C_StVO_2013.svg.png",
|
"HIM1" => "\u{1F6A7} Bauarbeiten".into(),
|
||||||
"HIM2" => "https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/Zeichen_101_-_Gefahrstelle%2C_StVO_1970.svg/273px-Zeichen_101_-_Gefahrstelle%2C_StVO_1970.svg.png",
|
"HIM2" => "\u{26A0}\u{FE0F} Störung".into(),
|
||||||
"HIM3" => "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Strike_worker.svg/314px-Strike_worker.svg.png",
|
"HIM3" => "\u{270A} Streik".into(),
|
||||||
_ => "https://upload.wikimedia.org/wikipedia/commons/thumb/5/56/Zeichen_365-61_-_Informationsstelle%2C_StVO_2013.svg/240px-Zeichen_365-61_-_Informationsstelle%2C_StVO_2013.svg.png",
|
other => format!("\u{2139}\u{FE0F} Information ({other})").into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +107,7 @@ impl DisbahnClient {
|
|||||||
.iter()
|
.iter()
|
||||||
.find(|c| c.domain() == Some("icon"))
|
.find(|c| c.domain() == Some("icon"))
|
||||||
.map_or("", |c| c.name());
|
.map_or("", |c| c.name());
|
||||||
let icon_url = Self::icon_name_to_url(icon);
|
let tag = Self::icon_name_to_tag(icon);
|
||||||
|
|
||||||
let description = Self::html_to_discord_markdown(
|
let description = Self::html_to_discord_markdown(
|
||||||
item.description().ok_or(anyhow!("Missing description"))?,
|
item.description().ok_or(anyhow!("Missing description"))?,
|
||||||
@@ -118,18 +122,13 @@ impl DisbahnClient {
|
|||||||
let embed = CreateEmbed::new()
|
let embed = CreateEmbed::new()
|
||||||
.title(title)
|
.title(title)
|
||||||
.url(link)
|
.url(link)
|
||||||
.thumbnail(icon_url)
|
.author(CreateEmbedAuthor::new(tag))
|
||||||
.colour(Self::icon_name_to_colour(icon))
|
.colour(Self::icon_name_to_colour(icon))
|
||||||
.description(description)
|
.description(description)
|
||||||
.field("Beginn:", format!("<t:{validity_begin}:f>"), true)
|
.field("Beginn:", format!("<t:{validity_begin}:f>"), true)
|
||||||
.field("Ende:", format!("<t:{validity_end}:f>"), true)
|
.field("Ende:", format!("<t:{validity_end}:f>"), true)
|
||||||
.timestamp(pub_datetime)
|
.timestamp(pub_datetime)
|
||||||
.footer(
|
.footer(CreateEmbedFooter::new("zuginfo.nrw").icon_url(FOOTER_ICON_URL));
|
||||||
CreateEmbedFooter::new(
|
|
||||||
"Quelle: zuginfo.nrw \u{2013} Alle Angaben ohne Gewehr \u{1F52B}",
|
|
||||||
)
|
|
||||||
.icon_url(FOOTER_ICON_URL),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(embed)
|
Ok(embed)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user