initial commit (leaked api keys last time 💀)
This commit is contained in:
commit
6cc62a000c
4 changed files with 2155 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
.env
|
2097
Cargo.lock
generated
Normal file
2097
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "announcement_bot"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
dateparser = "0.2.1"
|
||||||
|
discord-webhook-rs = "1.0.4"
|
||||||
|
dotenvy = "0.15.7"
|
||||||
|
regex = "1.11.1"
|
||||||
|
reqwest = { version = "0.12.15", features = ["blocking"] }
|
||||||
|
time = { version = "0.3.41", features = ["parsing", "macros"] }
|
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