feat: ping and roll

This commit is contained in:
Alzalia 2025-08-31 16:31:19 +02:00
parent 342bf5ea2d
commit 4092724586
8 changed files with 2621 additions and 2 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target /target
.env

2555
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,3 +4,8 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
dotenv = "0.15.0"
poise = "0.6.1"
rand = "0.9.2"
serenity = "0.12.4"
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }

3
src/commands/fun/mod.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod age;
pub mod ping;
pub mod roll;

10
src/commands/fun/ping.rs Normal file
View file

@ -0,0 +1,10 @@
use crate::{Context, Error};
/// Displays your or another user's account creation date
#[poise::command(slash_command, prefix_command)]
pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
let response = format!("pong {} !", ctx.author().display_name());
ctx.reply(response).await?;
Ok(())
}

16
src/commands/fun/roll.rs Normal file
View file

@ -0,0 +1,16 @@
use crate::{Context, Error};
use rand::prelude::*;
/// Displays your or another user's account creation date
#[poise::command(slash_command, prefix_command)]
pub async fn roll(
ctx: Context<'_>,
#[description = "Le nombre de faces du dé"] faces: u64,
) -> Result<(), Error> {
let num = (1..faces).choose(&mut rand::rng()).unwrap_or(1);
let response = format!("Le dé à {} faces est tombé sur **{}**", faces, num);
ctx.say(response).await?;
Ok(())
}

1
src/commands/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod fun;

View file

@ -1,3 +1,31 @@
fn main() { use poise::serenity_prelude as serenity;
println!("Hello, world!");
mod commands;
struct Data {} // User data, which is stored and accessible in all command invocations
type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>;
#[tokio::main]
async fn main() {
let token = dotenv::var("DISCORD_TOKEN").expect("missing DISCORD_TOKEN");
let intents = serenity::GatewayIntents::non_privileged();
let framework = poise::Framework::builder()
.options(poise::FrameworkOptions {
commands: vec![commands::fun::ping::ping(), commands::fun::roll::roll()],
..Default::default()
})
.setup(|ctx, _ready, framework| {
Box::pin(async move {
poise::builtins::register_globally(ctx, &framework.options().commands).await?;
Ok(Data {})
})
})
.build();
let client = serenity::ClientBuilder::new(token, intents)
.framework(framework)
.await;
client.unwrap().start().await.unwrap();
} }