Create databases for cf

This commit is contained in:
Natsu Kagami 2020-02-09 12:01:48 -05:00
parent 4b5dcfd072
commit 5b64d1e535
Signed by: nki
GPG key ID: 73376E117CD20735
5 changed files with 45 additions and 1 deletions

View file

@ -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" }

26
youmubot-cf/src/db.rs Normal file
View file

@ -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<HashMap<UserId, CfUser>>;
/// A saved Codeforces user.
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
pub struct CfUser {
pub handle: String,
pub last_update: DateTime<Utc>,
pub rating: Option<i64>,
}
impl Default for CfUser {
fn default() -> Self {
Self {
handle: "".to_owned(),
last_update: Utc::now(),
rating: None,
}
}
}

View file

@ -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"]