initial commit (leaked api keys last time 💀)
This commit is contained in:
commit
6cc62a000c
4 changed files with 2155 additions and 0 deletions
44
src/main.rs
Normal file
44
src/main.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
use discord_webhook_rs::Webhook;
|
||||
use regex::Regex;
|
||||
use std::env;
|
||||
use time::macros::format_description;
|
||||
use time::{Date, OffsetDateTime};
|
||||
|
||||
fn main() {
|
||||
dotenvy::dotenv().expect("Need a .env file");
|
||||
|
||||
let doc_url = env::var("DOC_URL").expect("Missing DOC_URL in .env");
|
||||
let webhook = env::var("WEBHOOK_URL").expect("Missing WEBHOOK_URL in .env");
|
||||
|
||||
let body = reqwest::blocking::get(doc_url + "/export?gid=0&format=txt")
|
||||
.unwrap()
|
||||
.text()
|
||||
.expect("Google doc download failed!");
|
||||
|
||||
let announcement_matcher = Regex::new(r"(\w+day,? \w+ \d+) *((?:.|\n)+?)\n\w+day").unwrap();
|
||||
|
||||
let last_announcement = announcement_matcher.captures_iter(&body).next().unwrap();
|
||||
|
||||
let date = last_announcement.get(1).unwrap().as_str().replace(",", "");
|
||||
|
||||
let announcements = last_announcement
|
||||
.get(2)
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.trim()
|
||||
.replace("\n\n", "\n");
|
||||
|
||||
let description = &format_description!("[weekday] [month repr:long] [day] [year]");
|
||||
let parsed_date = Date::parse(&format!("{} 2025", date), description).unwrap();
|
||||
println!("Date: {:}", parsed_date);
|
||||
|
||||
if OffsetDateTime::now_utc().date() != parsed_date {
|
||||
println!("Last date is not today!");
|
||||
return;
|
||||
}
|
||||
|
||||
Webhook::new(webhook)
|
||||
.content(&format!("## {}:\n{}", date, announcements))
|
||||
.send()
|
||||
.unwrap();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue