impl expert lfg
This commit is contained in:
parent
2707bcce9c
commit
b07e914b3a
3 changed files with 159 additions and 19 deletions
|
@ -1,4 +1,5 @@
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
|
use serenity::all::CreateAllowedMentions;
|
||||||
|
|
||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use crate::commands::command_helper;
|
use crate::commands::command_helper;
|
||||||
|
@ -27,7 +28,10 @@ pub(crate) async fn helpstart(
|
||||||
"<@&1008075054971621448>\nneed: {}",
|
"<@&1008075054971621448>\nneed: {}",
|
||||||
needed_players - bots
|
needed_players - bots
|
||||||
))
|
))
|
||||||
.ephemeral(false),
|
.ephemeral(false)
|
||||||
|
.allowed_mentions(CreateAllowedMentions::new()
|
||||||
|
.roles(vec![1008075054971621448])
|
||||||
|
),
|
||||||
Err(why) => reply.content(why.to_string()).ephemeral(true),
|
Err(why) => reply.content(why.to_string()).ephemeral(true),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use poise::{ChoiceParameter, CreateReply};
|
use poise::{ChoiceParameter, CreateReply};
|
||||||
use serenity::all::CreateAllowedMentions;
|
use serenity::all::{CreateAllowedMentions, RoleId};
|
||||||
|
|
||||||
//from main.rs
|
//from main.rs
|
||||||
use crate::{Context, Error};
|
|
||||||
use crate::commands::command_helper::cooldown;
|
use crate::commands::command_helper::cooldown;
|
||||||
|
use crate::{Context, Error};
|
||||||
//
|
//
|
||||||
use crate::commands::lfg::Difficulty::Normal;
|
use crate::commands::lfg::Difficulty::Normal;
|
||||||
use crate::commands::lfg::Map::*;
|
use crate::commands::lfg::Map::*;
|
||||||
|
@ -70,18 +70,17 @@ pub(crate) async fn lfg(
|
||||||
#[rename = "message"]
|
#[rename = "message"]
|
||||||
note: Option<String>,
|
note: Option<String>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
let mut reply: CreateReply = CreateReply::default();
|
||||||
let mut reply = CreateReply::default();
|
|
||||||
|
|
||||||
reply = match cooldown(&ctx, 600, 300) {
|
reply = match cooldown(&ctx, 600, 300) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let current = current_players.unwrap_or(1);
|
let current: u8 = current_players.unwrap_or(1);
|
||||||
let mut desired = desired_players.unwrap_or(4);
|
let mut desired: u8 = desired_players.unwrap_or(4);
|
||||||
if current >= desired {
|
if current >= desired {
|
||||||
desired = 4
|
desired = 4
|
||||||
}
|
}
|
||||||
let map_name: &str = map.name();
|
let map_name: &str = map.name();
|
||||||
let ping = match mode {
|
let ping: u64 = match mode {
|
||||||
Casual => match map {
|
Casual => match map {
|
||||||
DeadEnd => 1005837123921915914,
|
DeadEnd => 1005837123921915914,
|
||||||
BadBlood => 1140190470698438666,
|
BadBlood => 1140190470698438666,
|
||||||
|
@ -92,34 +91,170 @@ pub(crate) async fn lfg(
|
||||||
Event => 1175116511095050331,
|
Event => 1175116511095050331,
|
||||||
//Tournament => 1210508966036242445,
|
//Tournament => 1210508966036242445,
|
||||||
};
|
};
|
||||||
let difficulty = match map {
|
let difficulty: Difficulty = match map {
|
||||||
DeadEnd => difficulty.unwrap_or(Normal),
|
DeadEnd => difficulty.unwrap_or(Normal),
|
||||||
BadBlood => difficulty.unwrap_or(Normal),
|
BadBlood => difficulty.unwrap_or(Normal),
|
||||||
AlienArcadium => Normal,
|
AlienArcadium => Normal,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut reply_content = format!(
|
let mut reply_content: String = format!("<@&{ping}> {current}/{desired} {map_name}",);
|
||||||
"<@&{ping}> {current}/{desired} {map_name}",
|
|
||||||
);
|
|
||||||
match difficulty {
|
match difficulty {
|
||||||
Normal => {},
|
Normal => {}
|
||||||
Difficulty::Hard | Difficulty::Rip => {
|
Difficulty::Hard | Difficulty::Rip => {
|
||||||
reply_content.push(' ');
|
reply_content.push(' ');
|
||||||
reply_content.push_str(difficulty.name());
|
reply_content.push_str(difficulty.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match note {
|
match note {
|
||||||
None => {},
|
None => {}
|
||||||
Some(note) => {
|
Some(note) => {
|
||||||
reply_content.push_str(format!("\nNote: {note}").as_str());
|
reply_content.push_str(format!("\nNote: {note}").as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply.content(reply_content)
|
reply
|
||||||
|
.content(reply_content)
|
||||||
.ephemeral(false)
|
.ephemeral(false)
|
||||||
.allowed_mentions(CreateAllowedMentions::new()
|
.allowed_mentions(CreateAllowedMentions::new().roles(vec![ping]))
|
||||||
.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<u8>,
|
||||||
|
|
||||||
|
#[min = 2_u8]
|
||||||
|
#[max = 4_u8]
|
||||||
|
#[description = "default: 4"]
|
||||||
|
#[rename = "desired"]
|
||||||
|
desired_players: Option<u8>,
|
||||||
|
|
||||||
|
#[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<u64>) = 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),
|
Err(why) => reply.content(why.to_string()).ephemeral(true),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ async fn main() {
|
||||||
let options = poise::FrameworkOptions {
|
let options = poise::FrameworkOptions {
|
||||||
commands: vec![
|
commands: vec![
|
||||||
commands::lfg::lfg(),
|
commands::lfg::lfg(),
|
||||||
|
commands::lfg::expert(),
|
||||||
commands::xd::xd(),
|
commands::xd::xd(),
|
||||||
commands::helpstart::helpstart(),
|
commands::helpstart::helpstart(),
|
||||||
commands::bots::bots(),
|
commands::bots::bots(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue