Add ping and 8ball
parent
1a72a031e7
commit
38a879b9cd
|
@ -83,6 +83,15 @@ version = "3.12.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
|
||||
|
||||
[[package]]
|
||||
name = "buscemi"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"poise",
|
||||
"rand",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
|
@ -1105,14 +1114,6 @@ version = "0.5.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
||||
[[package]]
|
||||
name = "steve"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"poise",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
|
@ -1132,9 +1133,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.2.0"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
|
||||
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "steve"
|
||||
name = "buscemi"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
@ -7,4 +7,5 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
poise = "0.5.2"
|
||||
rand = "0.8.5"
|
||||
tokio = { version = "1.25.0", features = ["full"] }
|
||||
|
|
|
@ -43,12 +43,16 @@
|
|||
inputsFrom = builtins.attrValues self.checks;
|
||||
|
||||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||
nativeBuildInputs = builtins.attrValues {
|
||||
nativeBuildInputs = builtins.attrValues ({
|
||||
inherit (pkgs)
|
||||
cargo
|
||||
cargo-watch
|
||||
rustc
|
||||
;
|
||||
};
|
||||
} // pkgs.lib.optionalAttrs pkgs.stdenv.isDarwin {
|
||||
inherit (pkgs) libiconv;
|
||||
inherit (pkgs.darwin.apple_sdk.frameworks) Security;
|
||||
});
|
||||
buildInputs = builtins.attrValues {
|
||||
inherit (pkgs)
|
||||
rust-analyzer
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
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(())
|
||||
}
|
24
src/main.rs
24
src/main.rs
|
@ -1,29 +1,23 @@
|
|||
mod commands;
|
||||
|
||||
use poise::serenity_prelude as serenity;
|
||||
|
||||
struct Data {}
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||
|
||||
#[poise::command(prefix_command)]
|
||||
async fn ping(ctx: Context<'_>) -> Result<(), Error> {
|
||||
ctx.say("pang").await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let options = poise::FrameworkOptions {
|
||||
commands: commands::commands(),
|
||||
..Default::default()
|
||||
};
|
||||
let framework = poise::Framework::builder()
|
||||
.options(poise::FrameworkOptions {
|
||||
commands: vec![ping()],
|
||||
..Default::default()
|
||||
})
|
||||
.options(options)
|
||||
.token(std::env::var("DISCORD_TOKEN").expect("failed to find DISCORD_TOKEN in env"))
|
||||
.intents(serenity::GatewayIntents::non_privileged())
|
||||
.setup(|ctx, _ready, framework| {
|
||||
Box::pin(async move {
|
||||
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
|
||||
Ok(Data {})
|
||||
Ok(Default::default())
|
||||
})
|
||||
});
|
||||
println!("it's beneath me. i'm mr. pink. let's move on.");
|
||||
framework.run().await.unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue