Merge pull request 'feat: ping and roll' (#1) from dev into main
Reviewed-on: #1
This commit is contained in:
commit
86e836a3ca
8 changed files with 2621 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
|||
/target
|
||||
.env
|
||||
|
|
|
|||
2555
Cargo.lock
generated
Normal file
2555
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -4,3 +4,8 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[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
3
src/commands/fun/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pub mod age;
|
||||
pub mod ping;
|
||||
pub mod roll;
|
||||
10
src/commands/fun/ping.rs
Normal file
10
src/commands/fun/ping.rs
Normal 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
16
src/commands/fun/roll.rs
Normal 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
1
src/commands/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod fun;
|
||||
32
src/main.rs
32
src/main.rs
|
|
@ -1,3 +1,31 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use poise::serenity_prelude as serenity;
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue