html terminal
end4trusted
bendn 2024-02-23
parent ed93959 · commit 7fcc54b
-rw-r--r--src/bot/maps.rs7
-rw-r--r--src/bot/mod.rs20
2 files changed, 19 insertions, 8 deletions
diff --git a/src/bot/maps.rs b/src/bot/maps.rs
index e1a1b99..e00d394 100644
--- a/src/bot/maps.rs
+++ b/src/bot/maps.rs
@@ -34,6 +34,13 @@ impl Maps {
}
}
+pub async fn has(map: &str, ctx: &Context<'_>) -> bool {
+ Maps::get_all(&ctx.data().stdin)
+ .await
+ .iter()
+ .any(|x| map == x)
+}
+
pub async fn autocomplete<'a>(
ctx: Context<'a>,
partial: &'a str,
diff --git a/src/bot/mod.rs b/src/bot/mod.rs
index 46df650..eb56ae8 100644
--- a/src/bot/mod.rs
+++ b/src/bot/mod.rs
@@ -14,7 +14,7 @@ mod voting;
use crate::webhook::Webhook;
use anyhow::Result;
use maps::Maps;
-
+use emoji::named::*;
use poise::serenity_prelude::*;
use regex::Regex;
use serenity::http::Http;
@@ -29,6 +29,11 @@ use std::sync::{
};
use tokio::sync::broadcast;
+pub async fn trusted(c: Context<'_>) -> Result<bool> {
+ let c = c.author_member().await.ok_or(anyhow::anyhow!("dang"))?;
+ Ok(c.user.name == "bendn" || c.roles.contains(&RoleId::new(1110439183190863913)))
+}
+
#[derive(Debug)]
pub struct Data {
stdin: broadcast::Sender<String>,
@@ -398,19 +403,18 @@ pub async fn start(
return_next!(ctx)
}
-#[poise::command(
- slash_command,
- category = "Control",
- default_member_permissions = "ADMINISTRATOR",
- required_permissions = "ADMINISTRATOR"
-)]
-/// end the game.
+#[poise::command(slash_command, category = "Control", check = "trusted")]
+/// end the game. (requires trusted)
pub async fn end(
ctx: Context<'_>,
#[description = "the map to go to"]
#[autocomplete = "maps::autocomplete"]
map: String,
) -> Result<()> {
+ if !maps::has(&map, &ctx).await {
+ repl!(ctx, "{CANCEL} pls pick one of the maps.")?;
+ return Ok(());
+ }
send_ctx!(
ctx,
"gameover {}",