From 8508dec52e3b1525ad36d1c91a84122fed0856f5 Mon Sep 17 00:00:00 2001 From: ana_rchy Date: Thu, 20 Jun 2024 01:14:17 +0100 Subject: [PATCH] add ban gambling command --- src/commands.rs | 22 ++++++++++++++++++++++ src/main.rs | 6 ++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 562c238..b74748a 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -160,3 +160,25 @@ pub async fn get_leaderboard(ctx: Context<'_>, param: Option) -> Result< Ok(()) } + + +#[poise::command(slash_command, prefix_command, required_bot_permissions = "BAN_MEMBERS")] +pub async fn roll_ban(ctx: Context<'_>) -> Result<(), Error> { + let roll = (rand::random::() % 1000000) + 1; + let roll_text = format!("roll: {roll}/1000000"); + + if roll == 1000000 { + let member = ctx.author_member().await.unwrap(); + member.ban_with_reason(ctx.http(), 0, "gg you won the lottery").await?; + + let message = + format!("{roll_text}\n{} has won the lottery and been BANISHED from these sacred lands", member.user.name); + ctx.say(message).await?; + } else { + let message = + format!("{roll_text}\nno ban, try again"); + ctx.say(message).await?; + } + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 8139399..a783ebd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,9 @@ async fn main() -> Result<(), Error> { pub async fn poise_setup(shared_data: &SharedData) -> serenity::Client { let token = std::env::var("DISCORD_TOKEN").expect("envvar the DISCORD_TOKEN"); - let intents = GatewayIntents::GUILDS | GatewayIntents::GUILD_MEMBERS | GatewayIntents::MESSAGE_CONTENT + let intents = GatewayIntents::GUILDS + | GatewayIntents::GUILD_MEMBERS + | GatewayIntents::MESSAGE_CONTENT | GatewayIntents::GUILD_MESSAGES; let sunset_time = shared_data.sunset_time.clone(); @@ -52,7 +54,7 @@ pub async fn poise_setup(shared_data: &SharedData) -> serenity::Client { }) }) .options(poise::FrameworkOptions { - commands: vec![fact_check(), get_leaderboard(), roll(), uwuify()], + commands: vec![fact_check(), get_leaderboard(), roll(), uwuify(), roll_ban()], prefix_options: poise::PrefixFrameworkOptions { prefix: Some("!".into()), ..Default::default()