44 lines
1.7 KiB
Rust
44 lines
1.7 KiB
Rust
use super::{MessageContent, Styled};
|
|
use discord_message_format::DiscordComponent;
|
|
|
|
impl<'a> From<&DiscordComponent<'a>> for Styled {
|
|
fn from(discord: &DiscordComponent<'a>) -> Self {
|
|
match discord {
|
|
DiscordComponent::Plain(text) => Self::Plain(text.to_string()),
|
|
DiscordComponent::Literal(char) => Self::Plain(char.to_string()),
|
|
DiscordComponent::Link(link) => Self::Link {
|
|
target: link.to_string(),
|
|
text: vec![Self::Plain(link.to_string())],
|
|
},
|
|
|
|
DiscordComponent::Bold(content) => Self::Bold(convert_discord(content)),
|
|
DiscordComponent::Italic(content) => Self::Italic(convert_discord(content)),
|
|
DiscordComponent::Strikethrough(content) => {
|
|
Self::Strikethrough(convert_discord(content))
|
|
}
|
|
DiscordComponent::Underline(content) => Self::Underline(convert_discord(content)),
|
|
|
|
DiscordComponent::Code(code) => Self::Code(code.to_string()),
|
|
DiscordComponent::CodeBlock { lang, source } => Self::CodeBlock {
|
|
lang: lang.map(|s| s.to_string()),
|
|
source: source.to_string(),
|
|
},
|
|
|
|
DiscordComponent::Spoiler(content) => Self::Spoiler {
|
|
reason: None,
|
|
content: convert_discord(content),
|
|
},
|
|
|
|
DiscordComponent::LineBreak => Self::HardBreak,
|
|
DiscordComponent::Quote(content) => Self::BlockQuote(convert_discord(content)),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn convert_discord(discord_message: &[DiscordComponent<'_>]) -> MessageContent {
|
|
discord_message
|
|
.iter()
|
|
.map(Styled::from)
|
|
.collect::<MessageContent>()
|
|
}
|