diff options
Diffstat (limited to 'src/discord.rs')
-rw-r--r-- | src/discord.rs | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/src/discord.rs b/src/discord.rs index 4d59580..ea0ea36 100644 --- a/src/discord.rs +++ b/src/discord.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use anyhow::Result; use chrono::prelude::*; -use evtclib::{Log, Outcome}; +use evtclib::Log; use serenity::client::bridge::gateway::ShardManager; use serenity::model::id::*; use serenity::prelude::*; @@ -11,6 +11,7 @@ use tokio::runtime::Runtime; use log::info; use super::categories::Categorizable; +use super::logbag::{LogBag, state_emoji}; const MAX_HOURS: i64 = 5; const MAX_MESSAGE_LENGTH: usize = 2000; @@ -111,29 +112,9 @@ pub fn post_link(discord_token: &str, channel_id: u64, log: &Log, link: &str) -> }) } -fn find_insertion(text: &str, category: &str) -> Option<usize> { - let cat_pos = text.find(&format!("**{}**", category))?; - let empty_line = text[cat_pos..].find("\n\n")?; - Some(cat_pos + empty_line + 1) -} - fn insert_link(text: &str, log: &Log, link: &str) -> String { - let mut text = format!("\n\n{}\n\n", text); - let point = find_insertion(&text, log.category()); - let link_line = format!("{} {}\n", state_emoji(log), link); - if let Some(i) = point { - text.insert_str(i, &link_line); - } else { - text.push_str(&format!("**{}**\n{}", log.category(), link_line)); - } - text.trim().into() -} - -fn state_emoji(log: &Log) -> &'static str { - let outcome = log.analyzer().and_then(|a| a.outcome()); - match outcome { - Some(Outcome::Success) => "✅", - Some(Outcome::Failure) => "❌", - None => "❓", - } + let mut logbag = LogBag::parse_markdown(text).unwrap(); + let line = format!("{} {}", state_emoji(log), link); + logbag.insert(log.category(), line); + logbag.render_markdown() } |