summaryrefslogtreecommitdiff
path: root/src/commands/copypasta.rs
diff options
context:
space:
mode:
authorseth <[email protected]>2023-11-30 22:44:26 -0500
committerseth <[email protected]>2023-12-01 07:12:49 -0500
commit41dfa94258215769b9d844875e79097d4a498770 (patch)
tree5fb5a42545477ea1958ca6e5a1c1ae9b8d4899f7 /src/commands/copypasta.rs
parent76c0f94e6d7aa108424b34826eb7d8514b026287 (diff)
refactor: expand Settings
Diffstat (limited to 'src/commands/copypasta.rs')
-rw-r--r--src/commands/copypasta.rs24
1 files changed, 15 insertions, 9 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(())
}