@@ -19,7 +19,7 @@ use tokio::sync::Mutex;
1919use super :: { ConfigChat , ConfigToken } ;
2020use crate :: {
2121 config:: { self , Accessor , AsSecretRef , Config , Overridable , Validator } ,
22- helper,
22+ format_if , helper,
2323 notify:: NotifierTrait ,
2424 platform:: { PlatformMetadata , PlatformTrait } ,
2525 source:: {
@@ -231,6 +231,7 @@ impl Notifier {
231231 let start_time = start_time. unwrap_or_else ( SystemTime :: now) ;
232232
233233 let text = make_live_text (
234+ self . params . base . option . platform_name ,
234235 self . params . base . option . author_name ,
235236 & title_history,
236237 live_status,
@@ -272,6 +273,7 @@ impl Notifier {
272273 let token = self . token ( ) ?;
273274
274275 let text = make_live_text (
276+ self . params . base . option . platform_name ,
275277 self . params . base . option . author_name ,
276278 & current_live. title_history ,
277279 live_status,
@@ -319,13 +321,17 @@ impl Notifier {
319321
320322 let text = Text :: link (
321323 format ! (
322- "[{}] ✏️ {}{}" ,
323- source. platform. display_name,
324- if self . params. base. option. author_name {
325- Cow :: Owned ( format!( "[{}] " , live_status. streamer_name) )
326- } else {
327- Cow :: Borrowed ( "" )
328- } ,
324+ "{}✏️ {}{}" ,
325+ format_if!(
326+ self . params. base. option. platform_name,
327+ "[{}] " ,
328+ source. platform. display_name
329+ ) ,
330+ format_if!(
331+ self . params. base. option. author_name,
332+ "[{}] " ,
333+ live_status. streamer_name
334+ ) ,
329335 live_status. title
330336 ) ,
331337 & live_status. live_url ,
@@ -362,6 +368,7 @@ impl Notifier {
362368 . push_front ( live_status. title . clone ( ) ) ;
363369
364370 let text = make_live_text (
371+ self . params . base . option . platform_name ,
365372 self . params . base . option . author_name ,
366373 & current_live. title_history ,
367374 live_status,
@@ -412,7 +419,11 @@ impl Notifier {
412419 post : & Post ,
413420 source : & StatusSource ,
414421 ) -> anyhow:: Result < ( ) > {
415- let mut text = Text :: plain ( format ! ( "[{}] " , source. platform. display_name) ) ;
422+ let mut text = Text :: plain ( format_if ! (
423+ self . params. base. option. platform_name,
424+ "[{}] " ,
425+ source. platform. display_name
426+ ) ) ;
416427
417428 match & post. repost_from {
418429 Some ( RepostFrom :: Recursion ( repost_from) ) => {
@@ -626,6 +637,7 @@ impl Notifier {
626637 . send_message (
627638 & self . params . chat ,
628639 make_file_text (
640+ self . params . base . option . platform_name ,
629641 self . params . base . option . author_name ,
630642 FileUploadStage :: PlaybackUploading ,
631643 & playback. file ,
@@ -664,6 +676,7 @@ impl Notifier {
664676 } ) ,
665677 )
666678 . text ( make_file_text (
679+ self . params . base . option . platform_name ,
667680 self . params . base . option . author_name ,
668681 FileUploadStage :: PlaybackFinished ,
669682 & playback. file ,
@@ -696,6 +709,7 @@ impl Notifier {
696709 & self . params . chat ,
697710 message_id,
698711 make_file_text (
712+ self . params . base . option . platform_name ,
699713 self . params . base . option . author_name ,
700714 FileUploadStage :: PlaybackFailed ,
701715 & playback. file ,
@@ -739,6 +753,7 @@ impl Notifier {
739753 } ,
740754 )
741755 . text ( make_file_text (
756+ self . params . base . option . platform_name ,
742757 self . params . base . option . author_name ,
743758 FileUploadStage :: MetadataFinished ,
744759 & document. file ,
@@ -761,25 +776,22 @@ impl Notifier {
761776}
762777
763778fn make_live_text < ' a > (
779+ platform_name : bool ,
764780 author_name : bool ,
765781 title_history : impl IntoIterator < Item = & ' a String > ,
766782 live_status : & ' a LiveStatus ,
767783 source : & StatusSource ,
768784 start_time : SystemTime ,
769785) -> Text < ' a > {
770786 let text = format ! (
771- "[{}] {} {}{}{}" ,
772- source. platform. display_name,
787+ "{} {} {}{}{}" ,
788+ format_if! ( platform_name , "[{}] " , source. platform. display_name) ,
773789 match live_status. kind {
774790 LiveStatusKind :: Online { start_time: _ } => "🟢" ,
775791 LiveStatusKind :: Offline => "🟠" ,
776792 LiveStatusKind :: Banned => "🔴" ,
777793 } ,
778- if author_name {
779- Cow :: Owned ( format!( "[{}] " , live_status. streamer_name) )
780- } else {
781- Cow :: Borrowed ( "" )
782- } ,
794+ format_if!( author_name, "[{}] " , live_status. streamer_name) ,
783795 itertools:: join( title_history, " ⬅️ " ) ,
784796 if live_status. kind == LiveStatusKind :: Offline || live_status. kind == LiveStatusKind :: Banned
785797 {
@@ -803,6 +815,7 @@ enum FileUploadStage {
803815}
804816
805817fn make_file_text < ' a > (
818+ platform_name : bool ,
806819 _author_name : bool ,
807820 stage : FileUploadStage ,
808821 file : & FileRef < ' a > ,
@@ -816,8 +829,9 @@ fn make_file_text<'a>(
816829 } ;
817830 // TODO: Append author_name
818831 let mut text = Text :: plain ( format ! (
819- "[{}] {emoji} {}" ,
820- source. platform. display_name, file. name,
832+ "{}{emoji} {}" ,
833+ format_if!( platform_name, "[{}] " , source. platform. display_name) ,
834+ file. name,
821835 ) ) ;
822836 match stage {
823837 FileUploadStage :: PlaybackUploading | FileUploadStage :: PlaybackFailed => {
0 commit comments