Save osu users with last update timestamp

This commit is contained in:
Natsu Kagami 2020-01-16 02:07:08 -05:00
parent ce09a76dc7
commit 0939543bd3
2 changed files with 17 additions and 4 deletions

View file

@ -1,4 +1,4 @@
use crate::db::{DBWriteGuard, OsuSavedUsers}; use crate::db::{DBWriteGuard, OsuSavedUsers, OsuUser};
use crate::http; use crate::http;
use serenity::{ use serenity::{
framework::standard::{ framework::standard::{
@ -103,7 +103,13 @@ pub fn save(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
.into(); .into();
let mut db = db.borrow_mut()?; let mut db = db.borrow_mut()?;
db.insert(msg.author.id, u.id); db.insert(
msg.author.id,
OsuUser {
id: u.id,
last_update: chrono::Utc::now(),
},
);
msg.reply( msg.reply(
&ctx, &ctx,
MessageBuilder::new() MessageBuilder::new()
@ -157,7 +163,7 @@ impl UsernameArg {
let db = db.borrow()?; let db = db.borrow()?;
db.get(&id) db.get(&id)
.cloned() .cloned()
.map(UserID::ID) .map(|u| UserID::ID(u.id))
.ok_or(Error::from("No saved account found")) .ok_or(Error::from("No saved account found"))
} }
} }

View file

@ -37,7 +37,7 @@ where
pub type SoftBans = DB<GuildMap<ServerSoftBans>>; pub type SoftBans = DB<GuildMap<ServerSoftBans>>;
/// Save the user IDs. /// Save the user IDs.
pub type OsuSavedUsers = DB<HashMap<UserId, u64>>; pub type OsuSavedUsers = DB<HashMap<UserId, OsuUser>>;
/// Save each channel's last requested beatmap. /// Save each channel's last requested beatmap.
pub type OsuLastBeatmap = DB<HashMap<ChannelId, (Beatmap, Mode)>>; pub type OsuLastBeatmap = DB<HashMap<ChannelId, (Beatmap, Mode)>>;
@ -118,3 +118,10 @@ pub struct ImplementedSoftBans {
/// List of all to-unban people. /// List of all to-unban people.
pub periodical_bans: HashMap<UserId, DateTime<Utc>>, pub periodical_bans: HashMap<UserId, DateTime<Utc>>,
} }
/// An osu! saved user.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct OsuUser {
pub id: u64,
pub last_update: DateTime<Utc>,
}