diff --git a/Cargo.lock b/Cargo.lock index 9746240..4a2e7ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1718,6 +1718,7 @@ name = "youmubot-cf" version = "0.1.0" dependencies = [ "Inflector 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "codeforces 0.1.0 (git+https://github.com/natsukagami/rust-codeforces-api)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1725,6 +1726,7 @@ dependencies = [ "reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serenity 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "youmubot-db 0.1.0", "youmubot-prelude 0.1.0", ] diff --git a/youmubot-cf/Cargo.toml b/youmubot-cf/Cargo.toml index aafd64c..a2d0583 100644 --- a/youmubot-cf/Cargo.toml +++ b/youmubot-cf/Cargo.toml @@ -14,5 +14,7 @@ codeforces = { git = "https://github.com/natsukagami/rust-codeforces-api" } regex = "1" lazy_static = "1" rayon = "1" +chrono = { version = "0.4", features = ["serde"] } youmubot-prelude = { path = "../youmubot-prelude" } +youmubot-db = { path = "../youmubot-db" } diff --git a/youmubot-cf/src/db.rs b/youmubot-cf/src/db.rs new file mode 100644 index 0000000..62404f8 --- /dev/null +++ b/youmubot-cf/src/db.rs @@ -0,0 +1,26 @@ +use chrono::{DateTime, Utc}; +use serenity::model::id::UserId; +use std::collections::HashMap; +use youmubot_db::DB; +use youmubot_prelude::*; + +/// A database map that stores an user with the respective handle. +pub type CfSavedUsers = DB>; + +/// A saved Codeforces user. +#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)] +pub struct CfUser { + pub handle: String, + pub last_update: DateTime, + pub rating: Option, +} + +impl Default for CfUser { + fn default() -> Self { + Self { + handle: "".to_owned(), + last_update: Utc::now(), + rating: None, + } + } +} diff --git a/youmubot-cf/src/lib.rs b/youmubot-cf/src/lib.rs index 53f9604..7271ea2 100644 --- a/youmubot-cf/src/lib.rs +++ b/youmubot-cf/src/lib.rs @@ -3,15 +3,26 @@ use serenity::{ macros::{command, group}, Args, CommandResult, }, - model::{channel::Message, id::UserId}, + model::channel::Message, }; use youmubot_prelude::*; +mod db; mod embed; mod hook; +// /// Live-commentating a Codeforces round. +// pub mod live; + +pub use db::CfSavedUsers; pub use hook::codeforces_info_hook; +/// Sets up the CF databases. +pub fn setup(path: &std::path::Path, data: &mut ShareMap) { + CfSavedUsers::insert_into(data, path.join("cf_saved_users.yaml")) + .expect("Must be able to set up DB") +} + #[group] #[prefix = "cf"] #[description = "Codeforces-related commands"] diff --git a/youmubot/src/main.rs b/youmubot/src/main.rs index 8f372bc..20a31ae 100644 --- a/youmubot/src/main.rs +++ b/youmubot/src/main.rs @@ -81,6 +81,9 @@ fn main() { // osu! #[cfg(feature = "osu")] youmubot_osu::discord::setup(&db_path, &client, &mut data).expect("osu! is initialized"); + // codeforces + #[cfg(feature = "codeforces")] + youmubot_cf::setup(&db_path, &mut data); } #[cfg(feature = "core")]