65 lines
1.9 KiB
Rust
65 lines
1.9 KiB
Rust
use rand::seq::SliceRandom;
|
|
|
|
/// this is where we keep data for the bot
|
|
/// we can probably eventually serialize this to disk for cheap persistence
|
|
#[derive(Default)]
|
|
pub struct Data {}
|
|
type Error = Box<dyn std::error::Error + Send + Sync>;
|
|
type Context<'a> = poise::Context<'a, Data, Error>;
|
|
|
|
/// all of the commands supported by `buscemi`
|
|
pub fn commands() -> Vec<poise::Command<Data, Error>> {
|
|
vec![ping(), eight_ball()]
|
|
}
|
|
|
|
/// check that the bot is working
|
|
#[poise::command(prefix_command, slash_command)]
|
|
async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
|
let vowel = {
|
|
let mut rng = rand::thread_rng();
|
|
let vowels = ['a', 'e', 'o', 'u', 'y'];
|
|
vowels.choose(&mut rng).copied().unwrap()
|
|
};
|
|
ctx.say(format!("p{vowel}ng")).await?;
|
|
Ok(())
|
|
}
|
|
|
|
/// leave your important decisions up to chance
|
|
#[poise::command(prefix_command, slash_command, rename = "8ball")]
|
|
async fn eight_ball(
|
|
ctx: Context<'_>,
|
|
#[rest]
|
|
#[rename = "question"]
|
|
#[description = "a yes or no question"]
|
|
_question: String,
|
|
) -> Result<(), Error> {
|
|
let answer = {
|
|
let mut rng = rand::thread_rng();
|
|
let answers = [
|
|
"It is certain.",
|
|
"It is decidedly so.",
|
|
"Without a doubt.",
|
|
"Yes definitely.",
|
|
"You may rely on it.",
|
|
"As I see it, yes.",
|
|
"Most likely.",
|
|
"Outlook good.",
|
|
"Yes.",
|
|
"Signs point to yes.",
|
|
"Reply hazy, try again.",
|
|
"Ask again later.",
|
|
"Better not tell you now.",
|
|
"Cannot predict now.",
|
|
"Concentrate and ask again.",
|
|
"Don't count on it.",
|
|
"My reply is no.",
|
|
"My sources say no.",
|
|
"Outlook not so good.",
|
|
"Very doubtful.",
|
|
];
|
|
answers.choose(&mut rng).copied().unwrap()
|
|
};
|
|
ctx.say(answer).await?;
|
|
Ok(())
|
|
}
|