Better roulette
This commit is contained in:
parent
f53b4efee0
commit
fb51bbfffd
|
@ -99,7 +99,6 @@ async fn leave(ctx: &Context, msg: &Message) -> CommandResult {
|
|||
.expect("Expected VoiceManager in TypeMap.");
|
||||
let mut manager = manager_lock.lock().await;
|
||||
|
||||
|
||||
if let Some(handler) = manager.get_mut(guild_id) {
|
||||
handler.stop();
|
||||
manager.remove(guild_id);
|
||||
|
|
|
@ -13,13 +13,13 @@ use std::collections::HashMap;
|
|||
pub struct BulletsContainer;
|
||||
|
||||
impl TypeMapKey for BulletsContainer {
|
||||
type Value = HashMap<u64, u8>;
|
||||
type Value = HashMap<u64, (u8, u8)>;
|
||||
}
|
||||
|
||||
#[group]
|
||||
#[default_command(shot)]
|
||||
#[prefix("roulette")]
|
||||
#[commands(reload, shot)]
|
||||
#[commands(reload, shot, check)]
|
||||
struct Roulette;
|
||||
|
||||
#[command]
|
||||
|
@ -48,20 +48,22 @@ async fn _shot(ctx: &Context, msg: &Message) -> commands::Result<()> {
|
|||
let bullets_map = data
|
||||
.get_mut::<BulletsContainer>()
|
||||
.expect("Expected CommandCounter in TypeMap.");
|
||||
let bullets = bullets_map.entry(msg.author.id.0).or_insert(6);
|
||||
if rand::thread_rng().gen_range(0, *bullets) == 0 {
|
||||
api::send_reply(ctx, &msg, "BOOM !").await?;
|
||||
*bullets = 6;
|
||||
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));
|
||||
} else {
|
||||
*bullets -= 1;
|
||||
*bullets = (bullets.0 - 1, bullets.1);
|
||||
api::send_reply(
|
||||
&ctx,
|
||||
&msg,
|
||||
format!("Click ! bullets remaining : {}", bullets),
|
||||
format!("Click ! bullets remaining : {}", bullets.0 + 1),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
debugln!("{:?}", bullets_map);
|
||||
debugln!("Bullets Map : {:?}", bullets_map);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -80,8 +82,34 @@ async fn _reload(ctx: &Context, msg: &Message) -> commands::Result<()> {
|
|||
let bullets_map = data
|
||||
.get_mut::<BulletsContainer>()
|
||||
.expect("Expected CommandCounter in TypeMap.");
|
||||
bullets_map.insert(msg.author.id.0, 6);
|
||||
bullets_map.insert(msg.author.id.0, (5, rand::thread_rng().gen_range(0, 6)));
|
||||
msg.react(ctx, ReactionType::Unicode(String::from("✅")))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[description = "If you use that, you are a coward"]
|
||||
async fn check(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
let mut data = ctx.data.write().await;
|
||||
let bullets_map = data
|
||||
.get_mut::<BulletsContainer>()
|
||||
.expect("Expected CommandCounter in TypeMap.");
|
||||
let bullets = bullets_map
|
||||
.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?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn bullet_to_str<'m>(nbr: u8) -> &'m str {
|
||||
match nbr {
|
||||
1 => "first",
|
||||
2 => "second",
|
||||
3 => "third",
|
||||
4 => "fourth",
|
||||
5 => "fifth",
|
||||
6 => "sixth",
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ async fn main() -> IoResult<()> {
|
|||
struct Messages {}
|
||||
|
||||
impl Messages {
|
||||
async fn _reaction_add(
|
||||
/*async fn _reaction_add(
|
||||
&self,
|
||||
ctx: Context,
|
||||
reaction: Reaction,
|
||||
|
@ -171,7 +171,7 @@ impl Messages {
|
|||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
Loading…
Reference in New Issue