-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will be useful if I decide to add and use custom emojis to the bot
- Loading branch information
1 parent
746ef0a
commit a51fb34
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/// Discord emojis are sent like this: | ||
/// | ||
/// `<EmojiName:EmojiId>` | ||
/// | ||
/// This macro aims to simplify the process by writing the display implementor like this: | ||
/// | ||
/// ```rust | ||
/// use serenity_discord_bot::display_emoji_impl; | ||
/// | ||
/// pub enum Emojis { | ||
/// EmojiOne, | ||
/// EmojiTwo, | ||
/// } | ||
/// | ||
/// display_emoji_impl! { | ||
/// Emojis { | ||
/// EmojiOne => "123456789", | ||
/// EmojiTwo => "987654321", | ||
/// } | ||
/// } | ||
/// | ||
/// assert_eq!(Emojis::EmojiOne.to_string(), "<:EmojiOne:123456789>".to_string()); | ||
/// assert_eq!(Emojis::EmojiTwo.to_string(), "<:EmojiTwo:987654321>".to_string()); | ||
/// ``` | ||
#[macro_export] | ||
macro_rules! display_emoji_impl { | ||
($enum_name:ident { $($variant:ident => $id:expr),* $(,)? }) => { | ||
impl std::fmt::Display for $enum_name { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
$( | ||
Self::$variant => { | ||
write!( | ||
f, | ||
concat!( | ||
"<:", | ||
stringify!($variant), | ||
":", | ||
$id, | ||
">" | ||
) | ||
) | ||
} | ||
)* | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
/// NOTE: This allows non-PascalCase because the emoji itself could have a non-PascalCase name. I'd | ||
/// still try to have them all be PascalCase though. | ||
#[allow(non_camel_case_types)] | ||
#[allow(dead_code)] | ||
pub enum Emojis { | ||
HuTaoHeh, | ||
} | ||
|
||
display_emoji_impl! { | ||
Emojis { | ||
HuTaoHeh => "1317920658021290097", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod command_enums; | ||
pub mod emojis; | ||
pub mod schemas; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters