diff --git a/youmubot-osu/src/discord/commands.rs b/youmubot-osu/src/discord/commands.rs index f091163..0e2fb99 100644 --- a/youmubot-osu/src/discord/commands.rs +++ b/youmubot-osu/src/discord/commands.rs @@ -3,7 +3,10 @@ use poise::CreateReply; use serenity::all::User; /// osu!-related command group. -#[poise::command(slash_command, subcommands("profile", "top", "recent", "save"))] +#[poise::command( + slash_command, + subcommands("profile", "top", "recent", "save", "forcesave") +)] pub async fn osu(_ctx: CmdContext<'_, U>) -> Result<()> { Ok(()) } @@ -254,6 +257,40 @@ pub async fn save( Ok(()) } +/// Force-save an osu! profile into Youmu's database for tracking and quick commands. +#[poise::command(slash_command, owners_only)] +pub async fn forcesave( + ctx: CmdContext<'_, U>, + #[description = "The osu! username to set to"] username: String, + #[description = "The discord user to assign to"] discord_name: User, +) -> Result<()> { + let env = ctx.data().osu_env(); + let osu_client = &env.client; + ctx.defer().await?; + let Some(u) = osu_client + .user(&UserID::from_string(username.clone()), |f| f) + .await? + else { + return Err(Error::msg("osu! user not found")); + }; + add_user(discord_name.id, &u, &env).await?; + let ex = UserExtras::from_user(&env, &u, u.preferred_mode).await?; + ctx.send( + CreateReply::default() + .content( + MessageBuilder::new() + .push("Youmu is now tracking user ") + .push(discord_name.mention().to_string()) + .push(" with osu! account ") + .push_bold_safe(username) + .build(), + ) + .embed(user_embed(u, ex)), + ) + .await?; + Ok(()) +} + fn arg_from_username_or_discord( username: Option, discord_name: Option, diff --git a/youmubot-osu/src/discord/mod.rs b/youmubot-osu/src/discord/mod.rs index f9eba37..7dbe116 100644 --- a/youmubot-osu/src/discord/mod.rs +++ b/youmubot-osu/src/discord/mod.rs @@ -407,40 +407,36 @@ pub(crate) async fn handle_save_respond( #[num_args(2)] pub async fn forcesave(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { let env = ctx.data.read().await.get::().unwrap().clone(); - let osu_client = &env.client; let target = args.single::()?.0; let username = args.quoted().trimmed().single::()?; - let user: Option = osu_client + let Some(u) = osu_client .user(&UserID::from_string(username.clone()), |f| f) - .await?; - match user { - Some(u) => { - add_user(target, &u, &env).await?; - let ex = UserExtras::from_user(&env, &u, u.preferred_mode).await?; - msg.channel_id - .send_message( - &ctx, - CreateMessage::new() - .reference_message(msg) - .content( - MessageBuilder::new() - .push("Youmu is now tracking user ") - .push(target.mention().to_string()) - .push(" with osu! account ") - .push_bold_safe(username) - .build(), - ) - .embed(user_embed(u, ex)), + .await? + else { + msg.reply(&ctx, "user not found...").await?; + return Ok(()); + }; + add_user(target, &u, &env).await?; + let ex = UserExtras::from_user(&env, &u, u.preferred_mode).await?; + msg.channel_id + .send_message( + &ctx, + CreateMessage::new() + .reference_message(msg) + .content( + MessageBuilder::new() + .push("Youmu is now tracking user ") + .push(target.mention().to_string()) + .push(" with osu! account ") + .push_bold_safe(username) + .build(), ) - .await?; - } - None => { - msg.reply(&ctx, "user not found...").await?; - } - } + .embed(user_embed(u, ex)), + ) + .await?; Ok(()) }