From 0025ad5ea8d412aacc3184d18063fd5ff3de0175 Mon Sep 17 00:00:00 2001 From: seth Date: Sat, 2 Dec 2023 07:00:24 -0500 Subject: feat: add per guild configuration --- src/commands/copypasta.rs | 81 ----------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 src/commands/copypasta.rs (limited to 'src/commands/copypasta.rs') diff --git a/src/commands/copypasta.rs b/src/commands/copypasta.rs deleted file mode 100644 index 16ac562..0000000 --- a/src/commands/copypasta.rs +++ /dev/null @@ -1,81 +0,0 @@ -use crate::Context; - -use std::collections::HashMap; - -use color_eyre::eyre::{eyre, Result}; -use include_dir::{include_dir, Dir}; -use log::*; - -const FILES: Dir = include_dir!("src/copypastas"); - -#[allow(clippy::upper_case_acronyms)] -#[derive(Debug, poise::ChoiceParameter)] -pub enum Copypastas { - Astral, - DVD, - Egrill, - HappyMeal, - Sus, - TickTock, - Twitter, -} - -impl Copypastas { - fn as_str(&self) -> &str { - match self { - Copypastas::Astral => "astral", - Copypastas::DVD => "dvd", - Copypastas::Egrill => "egrill", - Copypastas::HappyMeal => "happymeal", - Copypastas::Sus => "sus", - Copypastas::TickTock => "ticktock", - Copypastas::Twitter => "twitter", - } - } -} - -fn get_copypasta(name: Copypastas) -> Result { - let mut files: HashMap<&str, &str> = HashMap::new(); - - for file in FILES.files() { - let name = file - .path() - .file_stem() - .ok_or_else(|| eyre!("couldn't get file stem from {file:#?}"))? - .to_str() - .ok_or_else(|| eyre!("couldn't convert file stem to str!"))?; - - let contents = file - .contents_utf8() - .ok_or_else(|| eyre!("couldnt get contents from copypasta!"))?; - - // refer to files by their name w/o extension - files.insert(name, contents); - } - - if files.contains_key(name.as_str()) { - Ok(files[name.as_str()].to_string()) - } else { - Err(eyre!("couldnt find copypasta {name}!")) - } -} - -/// ask teawie to send funni copypasta -#[poise::command(slash_command)] -pub async fn copypasta( - ctx: Context<'_>, - #[description = "the copypasta you want to send"] copypasta: Copypastas, -) -> Result<()> { - let gid = ctx - .guild_id() - .ok_or_else(|| eyre!("couldnt get guild from message!"))?; - - if !ctx.data().settings.is_guild_allowed(gid) { - info!("not running copypasta command in {gid}"); - return Ok(()); - } - - ctx.say(get_copypasta(copypasta)?).await?; - - Ok(()) -} -- cgit v1.2.3