mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-18 16:28:55 +00:00
Create databases for cf
This commit is contained in:
parent
4b5dcfd072
commit
5b64d1e535
5 changed files with 45 additions and 1 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -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",
|
||||
]
|
||||
|
||||
|
|
|
@ -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
26
youmubot-cf/src/db.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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"]
|
||||
|
|
|
@ -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")]
|
||||
|
|
Loading…
Add table
Reference in a new issue