diff --git a/src/commands/roulette.rs b/src/commands/roulette.rs index 4ef5d94..ed5a41b 100644 --- a/src/commands/roulette.rs +++ b/src/commands/roulette.rs @@ -19,7 +19,7 @@ impl TypeMapKey for BulletsContainer { #[group] #[default_command(shot)] #[prefix("roulette")] -#[commands(reload, shot, check)] +#[commands(reload, shot, check, kick)] struct Roulette; #[command] @@ -29,7 +29,7 @@ async fn shot(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let _message = args.message().trim_end(); if _message == "shot" || _message == "" { if let Err(e) = _shot(ctx, msg).await { - eprintln!("{}", e); + eprintln!("Error in shot : {:?}", e); } } else if let Err(e) = api::send_reply( ctx, @@ -99,6 +99,7 @@ async fn check(ctx: &Context, msg: &Message) -> CommandResult { .entry(msg.author.id.0) .or_insert((5, rand::thread_rng().gen_range(0, 6))); msg.channel_id.say(ctx, format!("Because you are a little shit, you open your barrel and you see that the bullet was at the {} position", bullet_to_str(bullets.1 + 1))).await?; + debugln!("Bullets Map : {:?}", bullets_map); Ok(()) } @@ -113,3 +114,52 @@ fn bullet_to_str<'m>(nbr: u8) -> &'m str { _ => unimplemented!(), } } + + +// TODO ALLOW ADMINS TO DISABLE THAT +#[command] +#[description = "DO IT"] +#[only_in(guilds)] +async fn kick(ctx: &Context, msg: &Message) -> CommandResult { + if msg.author.bot { + if let Err(e) = + api::send_reply(ctx, msg, "Error, this command cannot be used by a bot").await + { + eprintln!("Error in kick : {:?}", e); + } + } else if let Err(e) = _kick(ctx, msg).await { + eprintln!("Error in kick : {:?}", e); + } + Ok(()) +} + +async fn _kick(ctx: &Context, msg: &Message) -> commands::Result<()> { + let mut data = ctx.data.write().await; + let bullets_map = data + .get_mut::() + .expect("Expected CommandCounter in TypeMap."); + let bullets = bullets_map + .entry(msg.author.id.0) + .or_insert((5, rand::thread_rng().gen_range(0, 6))); + if bullets.0 == bullets.1 { + api::send_reply(ctx, &msg, "💥").await?; + *bullets = (5, rand::thread_rng().gen_range(0, 6)); + if let Some(guild_id) = &msg.guild_id { + guild_id + .member(&ctx.http, &msg.author) + .await? + .kick_with_reason(&ctx.http, "You loose at the roulette") + .await?; + } + } else { + *bullets = (bullets.0 - 1, bullets.1); + api::send_reply( + &ctx, + &msg, + format!("Click ! bullets remaining : {}", bullets.0 + 1), + ) + .await?; + } + debugln!("Bullets Map : {:?}", bullets_map); + Ok(()) +}