adjusted for changes in model

This commit is contained in:
Ash Vollmer 2026-08-05 21:16:36 +02:00
parent c2c83ff66f
commit bb745c9595

View file

@ -6,27 +6,25 @@ use dotenv::dotenv;
use models::Notice;
use serenity::{
all::{
Colour, Context, CreateAttachment, CreateEmbed, CreateEmbedFooter, CreateMessage,
EventHandler, GatewayIntents, Message, Ready, Timestamp,
Colour, Context, CreateEmbed, CreateEmbedFooter, CreateMessage, EventHandler,
GatewayIntents, Message, Ready, Timestamp,
},
async_trait, Client,
};
use crate::models::get_line_color;
struct Handler;
#[async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, msg: Message) {
let new = Notice {
let mut new = Notice {
affected_lines: vec!(String::from("10")),
dest_1: String::from("Hannover/Wettbergen"),
dest_2: String::from("Hannover/Misburg"),
headline: String::from("Linie 7 fährt erst bzw. bis Haltestelle In den Sieben Stücken"),
detail: String::from("Die Stadtbahnlinie 7 fährt während der Baumaßnahme erst ab beziehungsweise bis zur Haltestelle In den Sieben Stücken. Dort besteht die Umsteigemöglichkeit vom bzw. in den Schienenersatzverkehr (SEV) und die Stadtbahnlinien 3 und 13. An der Haltestelle Buchholz/Betriebshof ist kein Zustieg bzw. Ausstieg möglich."),
from: 12,
to: 30,
from: None,
to: None,
last_modified: String::from("2026-07-24T13:37:00Z"),
};
if msg.content == "!hello" {
@ -42,24 +40,37 @@ impl EventHandler for Handler {
));
let timestamp: Timestamp = new.last_modified.parse().expect("Invalid timestamp!");
let color =
get_line_color(new.affected_lines.first().expect("No single line affected"));
let embed = CreateEmbed::new()
.title(new.headline)
.description(new.detail)
.color(Colour::from_rgb(color.0, color.1, color.2))
.timestamp(timestamp)
.fields(vec![
("Start", new.from.to_string(), true),
("Ende", new.to.to_string(), true),
])
.field(
"Fahrtrichtungen",
format!("{} & {}", new.dest_1, new.dest_2),
false,
)
.footer(footer);
let color = new.get_line_color();
new.get_validity_period();
let embed = if new.from.is_none() || new.to.is_none() {
CreateEmbed::new()
.title(new.headline)
.description(new.detail)
.color(Colour::from_rgb(color.0, color.1, color.2))
.timestamp(timestamp)
.field(
"Fahrtrichtungen",
format!("{} & {}", &new.dest_1, &new.dest_2),
false,
)
.footer(footer)
} else {
CreateEmbed::new()
.title(new.headline)
.description(new.detail)
.color(Colour::from_rgb(color.0, color.1, color.2))
.timestamp(timestamp)
.fields(vec![
("Start", new.from.unwrap().to_string(), true),
("Ende", new.to.unwrap().to_string(), true),
])
.field(
"Fahrtrichtungen",
format!("{} & {}", new.dest_1, new.dest_2),
false,
)
.footer(footer)
};
// let embed = CreateEmbed::new()
// .title("This is a title")