summaryrefslogtreecommitdiff
path: root/src/commands/optional/copypasta.rs
blob: 06440b14477a4046cbe049816df939e1ffabff27 (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
use crate::{Context, Error};

use include_dir::{include_dir, Dir};
use log::debug;

const COPYPASTAS: Dir = include_dir!("src/copypastas");

#[derive(Debug, poise::ChoiceParameter)]
pub enum Copypasta {
	Astral,
	Dvd,
	Egrill,
	HappyMeal,
	Sus,
	TickTock,
	Twitter,
}

impl ToString for Copypasta {
	fn to_string(&self) -> String {
		let str = match self {
			Self::Astral => "astral",
			Self::Dvd => "dvd",
			Self::Egrill => "egrill",
			Self::HappyMeal => "happymeal",
			Self::Sus => "sus",
			Self::TickTock => "ticktock",
			Self::Twitter => "twitter",
		};
		str.to_string()
	}
}

impl Copypasta {
	fn contents(&self) -> Option<&str> {
		let file_name = format!("{}.txt", self.to_string());
		COPYPASTAS
			.get_file(file_name)
			.and_then(|file| file.contents_utf8())
	}
}

/// ask teawie to send funni copypasta
#[poise::command(slash_command)]
pub async fn copypasta(
	ctx: Context<'_>,
	#[description = "the copypasta you want to send"] copypasta: Copypasta,
) -> Result<(), Error> {
	if let Some(guild_id) = ctx.guild_id() {
		if let Some(storage) = &ctx.data().storage {
			let settings = storage.get_guild_settings(&guild_id).await?;

			if !settings.optional_commands_enabled {
				debug!("Not running command in {guild_id} since it's disabled");
				ctx.reply("I'm not allowed to do that here").await?;

				return Ok(());
			}
		} else {
			debug!("Ignoring restrictions on command; no storage backend is attached!");
		}
	} else {
		debug!("Ignoring restrictions on command; we're not in a guild");
	}

	if let Some(contents) = copypasta.contents() {
		ctx.say(contents).await?;
	} else {
		ctx.reply("I couldn't find that copypasta :(").await?;
	}

	Ok(())
}