This commit is contained in:
oupson1er@gmail.com 2021-03-17 23:16:54 +01:00
parent f0a95356d4
commit 5794295d3a
3 changed files with 12 additions and 51 deletions

View File

@ -10,17 +10,17 @@ edition = "2018"
music = ["serenity/voice"] music = ["serenity/voice"]
[dependencies] [dependencies]
serenity = "0.9" serenity = "0.10"
toml = "0.5" toml = "0.5"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
reqwest = "0.10" reqwest = "0.11"
rand = "0.7" rand = "0.8"
lazy_static = "1.4" lazy_static = "1.4"
async-trait = "0.1" async-trait = "0.1"
tokio = { version = "0.2", features = ["full"] } tokio = { version = "1.0", features = ["full"] }
futures = "0.3" futures = "0.3"
chrono = "0.4" chrono = "0.4"
serde_json = "1.0" serde_json = "1.0"
log = "0.4" log = "0.4"
log4rs = "0.13" log4rs = "1.0"
ctrlc = "3.1" ctrlc = "3.1"

View File

@ -25,7 +25,7 @@ struct Roulette;
async fn shot(ctx: &Context, msg: &Message, args: Args) -> CommandResult { async fn shot(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let _message = args.message().trim_end(); let _message = args.message().trim_end();
if _message == "shot" || _message == "" { if _message == "shot" || _message == "" {
if rand::thread_rng().gen_range(0, 6) == 0 { if rand::thread_rng().gen_range(0..6) == 0 {
api::send_reply(ctx, &msg, "💥").await?; api::send_reply(ctx, &msg, "💥").await?;
} else { } else {
api::send_reply(&ctx, &msg, format!("Click ! Reloading")).await?; api::send_reply(&ctx, &msg, format!("Click ! Reloading")).await?;
@ -57,7 +57,7 @@ async fn _reload(ctx: &Context, msg: &Message) -> commands::Result<()> {
let bullets_map = data let bullets_map = data
.get_mut::<BulletsContainer>() .get_mut::<BulletsContainer>()
.expect("Expected CommandCounter in TypeMap."); .expect("Expected CommandCounter in TypeMap.");
bullets_map.insert(msg.author.id.0, (5, rand::thread_rng().gen_range(0, 6))); bullets_map.insert(msg.author.id.0, (5, rand::thread_rng().gen_range(0..6)));
msg.react(ctx, ReactionType::Unicode(String::from(""))) msg.react(ctx, ReactionType::Unicode(String::from("")))
.await?; .await?;
Ok(()) Ok(())
@ -72,7 +72,7 @@ async fn check(ctx: &Context, msg: &Message) -> CommandResult {
.expect("Expected CommandCounter in TypeMap."); .expect("Expected CommandCounter in TypeMap.");
let bullets = bullets_map let bullets = bullets_map
.entry(msg.author.id.0) .entry(msg.author.id.0)
.or_insert((5, rand::thread_rng().gen_range(0, 6))); .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?; 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?;
debug!("Bullets Map : {:?}", bullets_map); debug!("Bullets Map : {:?}", bullets_map);
Ok(()) Ok(())
@ -127,10 +127,10 @@ async fn _kick(ctx: &Context, msg: &Message) -> CommandResult {
.expect("Expected CommandCounter in TypeMap."); .expect("Expected CommandCounter in TypeMap.");
let bullets = bullets_map let bullets = bullets_map
.entry(msg.author.id.0) .entry(msg.author.id.0)
.or_insert((5, rand::thread_rng().gen_range(0, 6))); .or_insert((5, rand::thread_rng().gen_range(0..6)));
if bullets.0 == bullets.1 { if bullets.0 == bullets.1 {
api::send_reply(ctx, &msg, "💥").await?; api::send_reply(ctx, &msg, "💥").await?;
*bullets = (5, rand::thread_rng().gen_range(0, 6)); *bullets = (5, rand::thread_rng().gen_range(0..6));
guild_id guild_id
.member(&ctx.http, &msg.author) .member(&ctx.http, &msg.author)

View File

@ -171,45 +171,6 @@ async fn main() -> IoResult<()> {
struct Messages {} struct Messages {}
impl Messages {
/*async fn _reaction_add(
&self,
ctx: Context,
reaction: Reaction,
) -> Result<(), Box<dyn std::error::Error>> {
// TODO
let message: Message = reaction.message(&ctx.http).await?;
if message.is_own(&ctx).await && message.content.starts_with("Do you want to take the gun")
{
debugln!("My own garbage !");
let user = reaction.user(&ctx.http).await?;
if user == message.mentions[1] {
message.delete(&ctx.http).await?;
if reaction.emoji
== serenity::model::channel::ReactionType::Unicode(String::from(""))
{
let mut data = ctx.data.write().await;
let bullets_map = data
.get_mut::<BulletsContainer>()
.expect("Expected CommandCounter in TypeMap.");
if bullets_map.contains_key(&message.mentions[0].id.0) {
let bullet_count =
bullets_map.remove(&message.mentions[0].id.0).unwrap_or(6);
bullets_map.insert(message.mentions[1].id.0, bullet_count);
message.channel_id.say(&ctx, "Done").await?;
} else {
message
.channel_id
.say(&ctx, "Error : Your gun is empty")
.await?;
}
}
}
}
Ok(())
}*/
}
#[async_trait] #[async_trait]
impl EventHandler for Messages { impl EventHandler for Messages {
async fn ready(&self, ctx: Context, ready: Ready) { async fn ready(&self, ctx: Context, ready: Ready) {
@ -225,7 +186,7 @@ impl EventHandler for Messages {
ctx_clone ctx_clone
.set_presence(Some(act), OnlineStatus::Online) .set_presence(Some(act), OnlineStatus::Online)
.await; .await;
tokio::time::delay_for(delay).await; tokio::time::sleep(delay).await;
} }
} }