summaryrefslogtreecommitdiff
path: root/src/commands/optional/copypasta.rs
diff options
context:
space:
mode:
authorseth <[email protected]>2023-12-02 07:00:24 -0500
committerseth <[email protected]>2023-12-15 16:41:13 -0500
commit0025ad5ea8d412aacc3184d18063fd5ff3de0175 (patch)
tree1d2b5ac5c04a092756180722358d929feeae50aa /src/commands/optional/copypasta.rs
parentac32ec2a0ba37deb0ad82b4f2ee9c1e1b359cc88 (diff)
feat: add per guild configuration
Diffstat (limited to 'src/commands/optional/copypasta.rs')
-rw-r--r--src/commands/optional/copypasta.rs80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/commands/optional/copypasta.rs b/src/commands/optional/copypasta.rs
new file mode 100644
index 0000000..ea23f5f
--- /dev/null
+++ b/src/commands/optional/copypasta.rs
@@ -0,0 +1,80 @@
+use crate::{Context, Settings};
+
+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<String> {
+ 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().unwrap_or_default();
+ let settings = Settings::from_redis(&ctx.data().redis, &gid).await?;
+
+ if !settings.optional_commands_enabled {
+ debug!("Not running copypasta command in {gid} since it's disabled");
+ return Ok(());
+ }
+
+ ctx.say(get_copypasta(copypasta)?).await?;
+
+ Ok(())
+}