Skip to main content

doxing_emulator/
messages.rs

1//! Static HTML bot error messages.
2
3use std::fmt;
4
5/// Built-in HTML error reply message.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum BotError {
8    /// Failed to identify the command invoker.
9    DoxerIdentificationFailed,
10    /// Failed to identify the dox target.
11    DoxeeIdentificationFailed,
12    /// The message origin cannot be used as a dox target.
13    InvalidOrigin,
14    /// Provided argument is not a user ID.
15    NotUserId,
16    /// Non-command message cannot be understood.
17    Incomprehensible,
18}
19
20impl BotError {
21    /// Return the error message HTML.
22    #[must_use]
23    pub const fn as_str(self) -> &'static str {
24        match self {
25            Self::DoxerIdentificationFailed => {
26                include_str!("messages/doxer-identification-failed.html")
27            }
28            Self::DoxeeIdentificationFailed => {
29                include_str!("messages/doxee-identification-failed.html")
30            }
31            Self::InvalidOrigin => include_str!("messages/invalid-origin.html"),
32            Self::NotUserId => include_str!("messages/not-user-id.html"),
33            Self::Incomprehensible => include_str!("messages/incomprehensible.html"),
34        }
35    }
36}
37
38impl AsRef<str> for BotError {
39    fn as_ref(&self) -> &str {
40        self.as_str()
41    }
42}
43
44impl From<BotError> for &'static str {
45    fn from(error: BotError) -> Self {
46        error.as_str()
47    }
48}
49
50impl From<BotError> for String {
51    fn from(error: BotError) -> Self {
52        error.as_str().to_owned()
53    }
54}
55
56impl fmt::Display for BotError {
57    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58        f.write_str(self.as_str())
59    }
60}