From b07e914b3a6895b844823d525ff341a806445641 Mon Sep 17 00:00:00 2001 From: Stachelbeere1248 Date: Sat, 25 May 2024 00:52:12 +0200 Subject: [PATCH] impl expert lfg --- src/commands/helpstart.rs | 6 +- src/commands/lfg.rs | 171 ++++++++++++++++++++++++++++++++++---- src/main.rs | 1 + 3 files changed, 159 insertions(+), 19 deletions(-) diff --git a/src/commands/helpstart.rs b/src/commands/helpstart.rs index 7dd012a..449331c 100644 --- a/src/commands/helpstart.rs +++ b/src/commands/helpstart.rs @@ -1,4 +1,5 @@ use poise::CreateReply; +use serenity::all::CreateAllowedMentions; use crate::{Context, Error}; use crate::commands::command_helper; @@ -27,7 +28,10 @@ pub(crate) async fn helpstart( "<@&1008075054971621448>\nneed: {}", needed_players - bots )) - .ephemeral(false), + .ephemeral(false) + .allowed_mentions(CreateAllowedMentions::new() + .roles(vec![1008075054971621448]) + ), Err(why) => reply.content(why.to_string()).ephemeral(true), } }; diff --git a/src/commands/lfg.rs b/src/commands/lfg.rs index 7f21295..75d09c1 100644 --- a/src/commands/lfg.rs +++ b/src/commands/lfg.rs @@ -1,9 +1,9 @@ use poise::{ChoiceParameter, CreateReply}; -use serenity::all::CreateAllowedMentions; +use serenity::all::{CreateAllowedMentions, RoleId}; //from main.rs -use crate::{Context, Error}; use crate::commands::command_helper::cooldown; +use crate::{Context, Error}; // use crate::commands::lfg::Difficulty::Normal; use crate::commands::lfg::Map::*; @@ -70,18 +70,17 @@ pub(crate) async fn lfg( #[rename = "message"] note: Option, ) -> Result<(), Error> { - - let mut reply = CreateReply::default(); + let mut reply: CreateReply = CreateReply::default(); reply = match cooldown(&ctx, 600, 300) { Ok(_) => { - let current = current_players.unwrap_or(1); - let mut desired = desired_players.unwrap_or(4); + let current: u8 = current_players.unwrap_or(1); + let mut desired: u8 = desired_players.unwrap_or(4); if current >= desired { desired = 4 } let map_name: &str = map.name(); - let ping = match mode { + let ping: u64 = match mode { Casual => match map { DeadEnd => 1005837123921915914, BadBlood => 1140190470698438666, @@ -92,34 +91,170 @@ pub(crate) async fn lfg( Event => 1175116511095050331, //Tournament => 1210508966036242445, }; - let difficulty = match map { + let difficulty: Difficulty = match map { DeadEnd => difficulty.unwrap_or(Normal), BadBlood => difficulty.unwrap_or(Normal), AlienArcadium => Normal, }; - let mut reply_content = format!( - "<@&{ping}> {current}/{desired} {map_name}", - ); + let mut reply_content: String = format!("<@&{ping}> {current}/{desired} {map_name}",); match difficulty { - Normal => {}, + Normal => {} Difficulty::Hard | Difficulty::Rip => { reply_content.push(' '); reply_content.push_str(difficulty.name()); } } match note { - None => {}, + None => {} Some(note) => { reply_content.push_str(format!("\nNote: {note}").as_str()); } } - reply.content(reply_content) + reply + .content(reply_content) .ephemeral(false) - .allowed_mentions(CreateAllowedMentions::new() - .roles(vec![ping]) - ) - }, + .allowed_mentions(CreateAllowedMentions::new().roles(vec![ping])) + } + Err(why) => reply.content(why.to_string()).ephemeral(true), + }; + + if let Err(why) = ctx.send(reply).await { + println!("Error sending message: {why}"); + } + Ok(()) +} +#[derive(Debug, poise::ChoiceParameter)] +enum Expert { + #[name = "Dead End"] + DeadEnd, + #[name = "Bad Blood"] + BadBlood, + #[name = "Alien Arcadium"] + AlienArcadium, + #[name = "Speedrun"] + Speedrun, +} +#[poise::command(slash_command, guild_only, rename = "expert-lfg")] +pub(crate) async fn expert ( + ctx: Context<'_>, + + #[rename = "map"] + mode: Expert, + + #[min = 1_u8] + #[max = 3_u8] + #[description = "default: 1"] + #[rename = "current"] + current_players: Option, + + #[min = 2_u8] + #[max = 4_u8] + #[description = "default: 4"] + #[rename = "desired"] + desired_players: Option, + + #[description = "extra message"] + #[rename = "message"] + note: String, +) -> Result<(), Error> { + let mut reply: CreateReply = CreateReply::default(); + + reply = match cooldown(&ctx, 600, 300) { + Ok(_) => { + let current: u8 = current_players.unwrap_or(1); + let mut desired: u8 = desired_players.unwrap_or(4); + if current >= desired { + desired = 4 + } + let (ping, allowed_roles): (u64, Vec) = match mode { + Expert::Speedrun => ( + 1243676538067488828, + vec![ + 1235975301461184513, + 1235975620400386172, + 1235975954413654167, + 1235976165345329162, + 1235976366109753404, + 1235967416605872179, + 1235967676048740434, + 1235968713354907648, + 1235968958511841351, + 1235969159679180860, + 1236226368052658217, + 1173396223592513647, + ], + ), + Expert::DeadEnd => ( + 1243675610895880366, + vec![ + 1235975562498015354, + 1235975873187020900, + 1235976093517746227, + 1235976301702156359, + 1235976469683896441, + 1235967416605872179, + 1235967676048740434, + 1235968713354907648, + 1235968958511841351, + 1235969159679180860, + 1236226368052658217, + 1173396223592513647, + ], + ), + Expert::BadBlood => ( + 1243676387634708491, + vec![ + 1235975518529261599, + 1235975747219357706, + 1235976055769268274, + 1235976257414631464, + 1235976434724376728, + 1235967416605872179, + 1235967676048740434, + 1235968713354907648, + 1235968958511841351, + 1235969159679180860, + 1236226368052658217, + 1173396223592513647, + ], + ), + Expert::AlienArcadium => ( + 1243676465829249116, + vec![ + 1235975471968157851, + 1235975697487364237, + 1235975991617130567, + 1235976216469835926, + 1235976398380863549, + 1235967416605872179, + 1235967676048740434, + 1235968713354907648, + 1235968958511841351, + 1235969159679180860, + 1236226368052658217, + 1173396223592513647, + ], + ), + }; + let is_expert: bool = ctx + .author_member() + .await + .unwrap() + .roles + .iter() + .any(|user_role: &RoleId| allowed_roles.contains(&user_role.get())); + let reply_content: String = format!("{current}/{desired} <@&{ping}>: {note}"); + match is_expert { + true => reply + .content(reply_content) + .ephemeral(false) + .allowed_mentions(CreateAllowedMentions::new().roles(vec![ping])), + false => reply + .content("You do not have any of the required expert ranks.") + .ephemeral(true), + } + } Err(why) => reply.content(why.to_string()).ephemeral(true), }; diff --git a/src/main.rs b/src/main.rs index 7f2e8ea..63254f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,7 @@ async fn main() { let options = poise::FrameworkOptions { commands: vec![ commands::lfg::lfg(), + commands::lfg::expert(), commands::xd::xd(), commands::helpstart::helpstart(), commands::bots::bots(),