summaryrefslogtreecommitdiff
path: root/src/commands/copypasta.rs
blob: 313cd13ec43e04c0f833a1e002c997ab70a82c39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::{utils, 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) -> 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 contents = file.contents_utf8().unwrap();

		// 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()
	} else {
		warn!("copypasta {} not found!", name);
		format!("i don't have a copypasta named {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 !utils::is_guild_allowed(gid) {
		info!("not running copypasta command in {gid}");
		return Ok(());
	}

	ctx.say(get_copypasta(copypasta)).await?;

	Ok(())
}