mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-19 00:38:54 +00:00
Add forcesave command
This commit is contained in:
parent
ecab57f31a
commit
3034f8e809
2 changed files with 61 additions and 28 deletions
|
@ -3,7 +3,10 @@ use poise::CreateReply;
|
||||||
use serenity::all::User;
|
use serenity::all::User;
|
||||||
|
|
||||||
/// osu!-related command group.
|
/// 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<U: HasOsuEnv>(_ctx: CmdContext<'_, U>) -> Result<()> {
|
pub async fn osu<U: HasOsuEnv>(_ctx: CmdContext<'_, U>) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -254,6 +257,40 @@ pub async fn save<U: HasOsuEnv>(
|
||||||
Ok(())
|
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<U: HasOsuEnv>(
|
||||||
|
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(
|
fn arg_from_username_or_discord(
|
||||||
username: Option<String>,
|
username: Option<String>,
|
||||||
discord_name: Option<User>,
|
discord_name: Option<User>,
|
||||||
|
|
|
@ -407,40 +407,36 @@ pub(crate) async fn handle_save_respond(
|
||||||
#[num_args(2)]
|
#[num_args(2)]
|
||||||
pub async fn forcesave(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
pub async fn forcesave(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
let env = ctx.data.read().await.get::<OsuEnv>().unwrap().clone();
|
let env = ctx.data.read().await.get::<OsuEnv>().unwrap().clone();
|
||||||
|
|
||||||
let osu_client = &env.client;
|
let osu_client = &env.client;
|
||||||
|
|
||||||
let target = args.single::<UserId>()?.0;
|
let target = args.single::<UserId>()?.0;
|
||||||
|
|
||||||
let username = args.quoted().trimmed().single::<String>()?;
|
let username = args.quoted().trimmed().single::<String>()?;
|
||||||
let user: Option<User> = osu_client
|
let Some(u) = osu_client
|
||||||
.user(&UserID::from_string(username.clone()), |f| f)
|
.user(&UserID::from_string(username.clone()), |f| f)
|
||||||
.await?;
|
.await?
|
||||||
match user {
|
else {
|
||||||
Some(u) => {
|
msg.reply(&ctx, "user not found...").await?;
|
||||||
add_user(target, &u, &env).await?;
|
return Ok(());
|
||||||
let ex = UserExtras::from_user(&env, &u, u.preferred_mode).await?;
|
};
|
||||||
msg.channel_id
|
add_user(target, &u, &env).await?;
|
||||||
.send_message(
|
let ex = UserExtras::from_user(&env, &u, u.preferred_mode).await?;
|
||||||
&ctx,
|
msg.channel_id
|
||||||
CreateMessage::new()
|
.send_message(
|
||||||
.reference_message(msg)
|
&ctx,
|
||||||
.content(
|
CreateMessage::new()
|
||||||
MessageBuilder::new()
|
.reference_message(msg)
|
||||||
.push("Youmu is now tracking user ")
|
.content(
|
||||||
.push(target.mention().to_string())
|
MessageBuilder::new()
|
||||||
.push(" with osu! account ")
|
.push("Youmu is now tracking user ")
|
||||||
.push_bold_safe(username)
|
.push(target.mention().to_string())
|
||||||
.build(),
|
.push(" with osu! account ")
|
||||||
)
|
.push_bold_safe(username)
|
||||||
.embed(user_embed(u, ex)),
|
.build(),
|
||||||
)
|
)
|
||||||
.await?;
|
.embed(user_embed(u, ex)),
|
||||||
}
|
)
|
||||||
None => {
|
.await?;
|
||||||
msg.reply(&ctx, "user not found...").await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue