mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-24 01:00:49 +00:00
Core: asyncify fun commands
This commit is contained in:
parent
d607a0d701
commit
9e38f88e97
1 changed files with 57 additions and 43 deletions
|
@ -28,7 +28,7 @@ struct Fun;
|
||||||
#[max_args(2)]
|
#[max_args(2)]
|
||||||
#[usage = "[max-dice-faces = 6] / [message]"]
|
#[usage = "[max-dice-faces = 6] / [message]"]
|
||||||
#[example = "100 / What's my score?"]
|
#[example = "100 / What's my score?"]
|
||||||
fn roll(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
async fn roll(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
let dice = if args.is_empty() {
|
let dice = if args.is_empty() {
|
||||||
6
|
6
|
||||||
} else {
|
} else {
|
||||||
|
@ -36,7 +36,8 @@ fn roll(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
};
|
};
|
||||||
|
|
||||||
if dice == 0 {
|
if dice == 0 {
|
||||||
msg.reply(&ctx, "Give me a dice with 0 faces, what do you expect 😒")?;
|
msg.reply(&ctx, "Give me a dice with 0 faces, what do you expect 😒")
|
||||||
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,24 +48,30 @@ fn roll(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
};
|
};
|
||||||
|
|
||||||
match args.single_quoted::<String>() {
|
match args.single_quoted::<String>() {
|
||||||
Ok(s) => msg.reply(
|
Ok(s) => {
|
||||||
&ctx,
|
msg.reply(
|
||||||
MessageBuilder::new()
|
&ctx,
|
||||||
.push("you asked ")
|
MessageBuilder::new()
|
||||||
.push_bold_safe(s)
|
.push("you asked ")
|
||||||
.push(format!(
|
.push_bold_safe(s)
|
||||||
", so I rolled a 🎲 of **{}** faces, and got **{}**!",
|
.push(format!(
|
||||||
|
", so I rolled a 🎲 of **{}** faces, and got **{}**!",
|
||||||
|
dice, result
|
||||||
|
))
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
Err(_) if args.is_empty() => {
|
||||||
|
msg.reply(
|
||||||
|
&ctx,
|
||||||
|
format!(
|
||||||
|
"I rolled a 🎲 of **{}** faces, and got **{}**!",
|
||||||
dice, result
|
dice, result
|
||||||
))
|
),
|
||||||
.build(),
|
)
|
||||||
),
|
.await
|
||||||
Err(_) if args.is_empty() => msg.reply(
|
}
|
||||||
&ctx,
|
|
||||||
format!(
|
|
||||||
"I rolled a 🎲 of **{}** faces, and got **{}**!",
|
|
||||||
dice, result
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Err(e) => return Err(e.into()),
|
Err(e) => return Err(e.into()),
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
|
@ -77,7 +84,7 @@ You may prefix the first choice with `?` to make it a question!
|
||||||
If no choices are given, Youmu defaults to `Yes!` and `No!`"#]
|
If no choices are given, Youmu defaults to `Yes!` and `No!`"#]
|
||||||
#[usage = "[?question]/[choice #1]/[choice #2]/..."]
|
#[usage = "[?question]/[choice #1]/[choice #2]/..."]
|
||||||
#[example = "?What for dinner/Pizza/Hamburger"]
|
#[example = "?What for dinner/Pizza/Hamburger"]
|
||||||
fn pick(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
async fn pick(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
let (question, choices) = {
|
let (question, choices) = {
|
||||||
// Get a list of options.
|
// Get a list of options.
|
||||||
let mut choices = args
|
let mut choices = args
|
||||||
|
@ -114,24 +121,30 @@ fn pick(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
};
|
};
|
||||||
|
|
||||||
match question {
|
match question {
|
||||||
None => msg.reply(
|
None => {
|
||||||
&ctx,
|
msg.reply(
|
||||||
MessageBuilder::new()
|
&ctx,
|
||||||
.push("Youmu picks 👉")
|
MessageBuilder::new()
|
||||||
.push_bold_safe(choice)
|
.push("Youmu picks 👉")
|
||||||
.push("👈!")
|
.push_bold_safe(choice)
|
||||||
.build(),
|
.push("👈!")
|
||||||
),
|
.build(),
|
||||||
Some(s) => msg.reply(
|
)
|
||||||
&ctx,
|
.await
|
||||||
MessageBuilder::new()
|
}
|
||||||
.push("you asked ")
|
Some(s) => {
|
||||||
.push_bold_safe(s)
|
msg.reply(
|
||||||
.push(", and Youmu picks 👉")
|
&ctx,
|
||||||
.push_bold_safe(choice)
|
MessageBuilder::new()
|
||||||
.push("👈!")
|
.push("you asked ")
|
||||||
.build(),
|
.push_bold_safe(s)
|
||||||
),
|
.push(", and Youmu picks 👉")
|
||||||
|
.push_bold_safe(choice)
|
||||||
|
.push("👈!")
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -142,7 +155,7 @@ fn pick(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
#[usage = "[user_mention = yourself]"]
|
#[usage = "[user_mention = yourself]"]
|
||||||
#[example = "@user#1234"]
|
#[example = "@user#1234"]
|
||||||
#[max_args(1)]
|
#[max_args(1)]
|
||||||
fn name(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
async fn name(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
let user_id = if args.is_empty() {
|
let user_id = if args.is_empty() {
|
||||||
msg.author.id
|
msg.author.id
|
||||||
} else {
|
} else {
|
||||||
|
@ -153,15 +166,15 @@ fn name(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
"your".to_owned()
|
"your".to_owned()
|
||||||
} else {
|
} else {
|
||||||
MessageBuilder::new()
|
MessageBuilder::new()
|
||||||
.push_bold_safe(user_id.to_user(&ctx)?.tag())
|
.push_bold_safe(user_id.to_user(&ctx).await?.tag())
|
||||||
.push("'s")
|
.push("'s")
|
||||||
.build()
|
.build()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Rule out a couple of cases
|
// Rule out a couple of cases
|
||||||
if user_id == ctx.http.get_current_application_info()?.id {
|
if user_id == ctx.http.get_current_application_info().await?.id {
|
||||||
// This is my own user_id
|
// This is my own user_id
|
||||||
msg.reply(&ctx, "😠 My name is **Youmu Konpaku**!")?;
|
msg.reply(&ctx, "😠 My name is **Youmu Konpaku**!").await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +186,7 @@ fn name(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
|
||||||
"{} Japanese🇯🇵 name is **{} {}**!",
|
"{} Japanese🇯🇵 name is **{} {}**!",
|
||||||
user_mention, first_name, last_name
|
user_mention, first_name, last_name
|
||||||
),
|
),
|
||||||
)?;
|
)
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue