improved lfg

This commit is contained in:
Moritz Roßbacher 2023-10-23 16:07:27 +02:00
parent 1bfa79e4bd
commit b0a712bd6e
2 changed files with 30 additions and 17 deletions

View file

@ -1,11 +1,16 @@
//
use crate::commands::lfg::Difficulty::Normal; use crate::commands::lfg::Difficulty::Normal;
use crate::commands::lfg::Mode::Casual; use crate::commands::lfg::Map::*;
use crate::commands::lfg::Mode::*;
//from main.rs
use crate::Context; use crate::Context;
use crate::Error; use crate::Error;
//
use serenity::model::id::RoleId; use serenity::model::id::RoleId;
use serenity::model::mention::Mention; use serenity::model::mention::Mention;
use serenity::model::mention::Mention::Role; use serenity::model::mention::Mention::Role;
use serenity::prelude::Mentionable; use serenity::prelude::Mentionable;
#[derive(Debug, poise::ChoiceParameter)] #[derive(Debug, poise::ChoiceParameter)]
pub enum Map { pub enum Map {
#[name = "Dead End"] #[name = "Dead End"]
@ -37,7 +42,10 @@ pub enum Difficulty {
pub(crate) async fn lfg( pub(crate) async fn lfg(
ctx: Context<'_>, ctx: Context<'_>,
#[rename = "map"] map: Map, #[rename = "map"] map: Map,
#[rename = "difficulty"] difficulty: Option<Difficulty>,
#[description = "Normal"]
#[rename = "difficulty"]
difficulty: Option<Difficulty>,
#[rename = "mode"] #[rename = "mode"]
#[description = "play-style"] #[description = "play-style"]
@ -67,22 +75,26 @@ pub(crate) async fn lfg(
let ping: Mention; let ping: Mention;
match mode.unwrap_or(Casual) { match mode.unwrap_or(Casual) {
Casual => match map { Casual => match map {
Map::DeadEnd => ping = Role(RoleId(1005837123921915914)), DeadEnd => ping = Role(RoleId(1005837123921915914)),
Map::BadBlood => ping = Role(RoleId(1140190470698438666)), BadBlood => ping = Role(RoleId(1140190470698438666)),
Map::AlienArcadium => ping = Role(RoleId(1105917281898336356)), AlienArcadium => ping = Role(RoleId(1105917281898336356)),
}, },
Mode::Speedrun => ping = Role(RoleId(1005836989595144243)), Speedrun => ping = Role(RoleId(1005836989595144243)),
Mode::Challenge => ping = Role(RoleId(1005836864680361994)), Challenge => ping = Role(RoleId(1005836864680361994)),
} }
let mut reply = format!( let mut reply = format!(
"{} is looking for {}\n{}/{} {} {}", "{c}/{d} {e} {f} {b}",
ctx.author().mention(), //a = ctx.author().mention(),
ping, b = ping,
current, c = current,
desired, d = desired,
map.name(), e = map.name(),
f = if map != AlienArcadium {
difficulty.unwrap_or(Normal).name() difficulty.unwrap_or(Normal).name()
} else {
Normal.name()
}
); );
if note.is_some() { if note.is_some() {
reply.push_str(format!("\nNote: {}", note.unwrap()).as_str()) reply.push_str(format!("\nNote: {}", note.unwrap()).as_str())

View file

@ -1,9 +1,9 @@
mod commands; mod commands;
use std::collections::HashSet;
use std::convert::Into;
use poise::serenity_prelude as serenity; use poise::serenity_prelude as serenity;
use serenity::model::id::UserId; use serenity::model::id::UserId;
use std::collections::HashSet;
use std::convert::Into;
type Error = Box<dyn std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>; type Context<'a> = poise::Context<'a, Data, Error>;
@ -34,7 +34,8 @@ async fn main() {
other => poise::builtins::on_error(other).await.unwrap(), other => poise::builtins::on_error(other).await.unwrap(),
} }
}) })
},owners, },
owners,
..Default::default() ..Default::default()
}) })
.token(std::env::var("DISCORD_TOKEN").unwrap()) .token(std::env::var("DISCORD_TOKEN").unwrap())