diff options
| author | seth <[email protected]> | 2023-11-30 22:44:26 -0500 |
|---|---|---|
| committer | seth <[email protected]> | 2023-12-01 07:12:49 -0500 |
| commit | 41dfa94258215769b9d844875e79097d4a498770 (patch) | |
| tree | 5fb5a42545477ea1958ca6e5a1c1ae9b8d4899f7 /src/commands | |
| parent | 76c0f94e6d7aa108424b34826eb7d8514b026287 (diff) | |
refactor: expand Settings
Diffstat (limited to 'src/commands')
| -rw-r--r-- | src/commands/copypasta.rs | 24 | ||||
| -rw-r--r-- | src/commands/teawiespam.rs | 4 |
2 files changed, 17 insertions, 11 deletions
diff --git a/src/commands/copypasta.rs b/src/commands/copypasta.rs index 313cd13..16ac562 100644 --- a/src/commands/copypasta.rs +++ b/src/commands/copypasta.rs @@ -1,4 +1,4 @@ -use crate::{utils, Context}; +use crate::Context; use std::collections::HashMap; @@ -34,23 +34,29 @@ impl Copypastas { } } -fn get_copypasta(name: Copypastas) -> String { +fn get_copypasta(name: Copypastas) -> Result<String> { let mut files: HashMap<&str, &str> = HashMap::new(); for file in FILES.files() { - let name = file.path().file_stem().unwrap().to_str().unwrap(); + 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().unwrap(); + 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()) { - files[name.as_str()].to_string() + Ok(files[name.as_str()].to_string()) } else { - warn!("copypasta {} not found!", name); - format!("i don't have a copypasta named {name} :(") + Err(eyre!("couldnt find copypasta {name}!")) } } @@ -64,12 +70,12 @@ pub async fn copypasta( .guild_id() .ok_or_else(|| eyre!("couldnt get guild from message!"))?; - if !utils::is_guild_allowed(gid) { + if !ctx.data().settings.is_guild_allowed(gid) { info!("not running copypasta command in {gid}"); return Ok(()); } - ctx.say(get_copypasta(copypasta)).await?; + ctx.say(get_copypasta(copypasta)?).await?; Ok(()) } diff --git a/src/commands/teawiespam.rs b/src/commands/teawiespam.rs index da01af9..aeea255 100644 --- a/src/commands/teawiespam.rs +++ b/src/commands/teawiespam.rs @@ -1,4 +1,3 @@ -use crate::utils; use crate::Context; use color_eyre::eyre::Result; @@ -8,7 +7,8 @@ use log::*; #[poise::command(slash_command, prefix_command)] pub async fn teawiespam(ctx: Context<'_>) -> Result<()> { let gid = ctx.guild_id().unwrap_or_default(); - if !utils::is_guild_allowed(gid) { + + if !ctx.data().settings.is_guild_allowed(gid) { info!("not running teawiespam command in {gid}"); return Ok(()); } |
