Event ping
This commit is contained in:
parent
c93b3e4a58
commit
9a392d6b8b
4 changed files with 82 additions and 36 deletions
38
src/commands/command_helper.rs
Normal file
38
src/commands/command_helper.rs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
use crate::{Context, Error};
|
||||||
|
|
||||||
|
pub(crate) async fn send(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
reply: String
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
if let Err(why) = ctx
|
||||||
|
.send(|m| {
|
||||||
|
m.content(reply)
|
||||||
|
.allowed_mentions(|am| am.parse(serenity::builder::ParseValue::Roles))
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
println!("Error sending message: {:?}", why)
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn cooldown(
|
||||||
|
ctx: &Context,
|
||||||
|
user: u64,
|
||||||
|
global: u64
|
||||||
|
) -> Option<Result<(), Error>> {
|
||||||
|
let mut cooldown_tracker = ctx.command().cooldowns.lock().unwrap();
|
||||||
|
let mut cooldown_durations = poise::CooldownConfig::default();
|
||||||
|
cooldown_durations.user = Some(Duration::from_secs(user));
|
||||||
|
cooldown_durations.global = Some(Duration::from_secs(global));
|
||||||
|
|
||||||
|
match cooldown_tracker.remaining_cooldown_2(*ctx, &cooldown_durations) {
|
||||||
|
Some(remaining) =>
|
||||||
|
Some(Err(format!("Please wait {} seconds", remaining.as_secs()).into())),
|
||||||
|
None => {
|
||||||
|
cooldown_tracker.start_cooldown(*ctx);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
src/commands/helpstart.rs
Normal file
27
src/commands/helpstart.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
use crate::{Context, Error};
|
||||||
|
use crate::commands::command_helper;
|
||||||
|
|
||||||
|
#[poise::command(slash_command)]
|
||||||
|
pub(crate) async fn helpstart(
|
||||||
|
ctx: Context<'_>,
|
||||||
|
|
||||||
|
#[min = 1_u8]
|
||||||
|
#[max = 3_u8]
|
||||||
|
#[description = "default: 3"]
|
||||||
|
#[rename = "needed"]
|
||||||
|
needed_players: u8
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
if let Some(value) = command_helper::cooldown(
|
||||||
|
&ctx,
|
||||||
|
1200,
|
||||||
|
600
|
||||||
|
) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
let reply = format!(
|
||||||
|
"<@&1008075054971621448>\nneed: {}"
|
||||||
|
,needed_players
|
||||||
|
);
|
||||||
|
|
||||||
|
command_helper::send(ctx, reply).await
|
||||||
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
use std::time::Duration;
|
|
||||||
//
|
//
|
||||||
use crate::commands::lfg::Difficulty::Normal;
|
use crate::commands::lfg::Difficulty::Normal;
|
||||||
use crate::commands::lfg::Map::*;
|
use crate::commands::lfg::Map::*;
|
||||||
|
@ -9,6 +8,7 @@ use crate::{Context, 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 crate::commands::command_helper;
|
||||||
|
|
||||||
#[derive(Debug, poise::ChoiceParameter, PartialEq)]
|
#[derive(Debug, poise::ChoiceParameter, PartialEq)]
|
||||||
pub enum Map {
|
pub enum Map {
|
||||||
|
@ -27,6 +27,8 @@ pub enum Mode {
|
||||||
Speedrun,
|
Speedrun,
|
||||||
#[name = "Challenge"]
|
#[name = "Challenge"]
|
||||||
Challenge,
|
Challenge,
|
||||||
|
#[name = "Event/Challenge"]
|
||||||
|
Event,
|
||||||
}
|
}
|
||||||
#[derive(Debug, poise::ChoiceParameter)]
|
#[derive(Debug, poise::ChoiceParameter)]
|
||||||
pub enum Difficulty {
|
pub enum Difficulty {
|
||||||
|
@ -49,7 +51,7 @@ pub(crate) async fn lfg(
|
||||||
|
|
||||||
#[rename = "mode"]
|
#[rename = "mode"]
|
||||||
#[description = "play-style"]
|
#[description = "play-style"]
|
||||||
mode: Option<Mode>,
|
mode: Mode,
|
||||||
|
|
||||||
#[min = 1_u8]
|
#[min = 1_u8]
|
||||||
#[max = 3_u8]
|
#[max = 3_u8]
|
||||||
|
@ -68,28 +70,13 @@ pub(crate) async fn lfg(
|
||||||
note: Option<String>,
|
note: Option<String>,
|
||||||
|
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
{
|
if let Some(value) = command_helper::cooldown(
|
||||||
let mut cooldown_tracker = ctx.command().cooldowns.lock().unwrap();
|
&ctx,
|
||||||
let mut cooldown_durations = poise::CooldownConfig::default();
|
600,
|
||||||
cooldown_durations.user = Some(Duration::from_secs(600));
|
300
|
||||||
|
) {
|
||||||
match cooldown_tracker.remaining_cooldown_2(ctx, &cooldown_durations) {
|
return value;
|
||||||
Some(remaining) => {
|
|
||||||
return Err(format!("Please wait {} seconds", remaining.as_secs()).into())
|
|
||||||
}
|
}
|
||||||
None => cooldown_tracker.start_cooldown(ctx),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,7 +85,7 @@ pub(crate) async fn lfg(
|
||||||
if current >= desired { desired = 4 }
|
if current >= desired { desired = 4 }
|
||||||
let map_name: &str = map.name();
|
let map_name: &str = map.name();
|
||||||
let ping: Mention;
|
let ping: Mention;
|
||||||
match mode.unwrap_or(Casual) {
|
match mode {
|
||||||
Casual => match map {
|
Casual => match map {
|
||||||
DeadEnd => ping = Role(RoleId(1005837123921915914)),
|
DeadEnd => ping = Role(RoleId(1005837123921915914)),
|
||||||
BadBlood => ping = Role(RoleId(1140190470698438666)),
|
BadBlood => ping = Role(RoleId(1140190470698438666)),
|
||||||
|
@ -106,6 +93,7 @@ pub(crate) async fn lfg(
|
||||||
},
|
},
|
||||||
Speedrun => ping = Role(RoleId(1005836989595144243)),
|
Speedrun => ping = Role(RoleId(1005836989595144243)),
|
||||||
Challenge => ping = Role(RoleId(1005836864680361994)),
|
Challenge => ping = Role(RoleId(1005836864680361994)),
|
||||||
|
Event => ping = Role(RoleId(1175116511095050331))
|
||||||
}
|
}
|
||||||
let diff_name: &str = if map != AlienArcadium {
|
let diff_name: &str = if map != AlienArcadium {
|
||||||
difficulty.unwrap_or(Normal).name()
|
difficulty.unwrap_or(Normal).name()
|
||||||
|
@ -135,15 +123,5 @@ pub(crate) async fn lfg(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
command_helper::send(ctx, reply).await
|
||||||
if let Err(why) = ctx
|
|
||||||
.send(|m| {
|
|
||||||
m.content(reply)
|
|
||||||
.allowed_mentions(|am| am.parse(serenity::builder::ParseValue::Roles))
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
println!("Error sending message: {:?}", why)
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,5 @@
|
||||||
pub(crate) mod lfg;
|
pub(crate) mod lfg;
|
||||||
pub(crate) mod xd;
|
pub(crate) mod xd;
|
||||||
|
pub(crate) mod helpstart;
|
||||||
|
mod command_helper;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue