@@ -385,7 +385,10 @@ impl<N: QueueSubscribeClient + Clone, P: Publish> DiscordAgent<N, P> {
385385 let update_subject = discord_nats:: subjects:: bot:: guild_update ( self . subscriber . prefix ( ) ) ;
386386 let delete_subject = discord_nats:: subjects:: bot:: guild_delete ( self . subscriber . prefix ( ) ) ;
387387
388- info ! ( "Subscribing to guild lifecycle: {}, {}, {}" , create_subject, update_subject, delete_subject) ;
388+ info ! (
389+ "Subscribing to guild lifecycle: {}, {}, {}" ,
390+ create_subject, update_subject, delete_subject
391+ ) ;
389392
390393 let mut create_stream = self
391394 . subscriber
@@ -458,7 +461,10 @@ impl<N: QueueSubscribeClient + Clone, P: Publish> DiscordAgent<N, P> {
458461 let update_subject = discord_nats:: subjects:: bot:: channel_update ( self . subscriber . prefix ( ) ) ;
459462 let delete_subject = discord_nats:: subjects:: bot:: channel_delete ( self . subscriber . prefix ( ) ) ;
460463
461- info ! ( "Subscribing to channel lifecycle: {}, {}, {}" , create_subject, update_subject, delete_subject) ;
464+ info ! (
465+ "Subscribing to channel lifecycle: {}, {}, {}" ,
466+ create_subject, update_subject, delete_subject
467+ ) ;
462468
463469 let mut create_stream = self
464470 . subscriber
@@ -531,7 +537,10 @@ impl<N: QueueSubscribeClient + Clone, P: Publish> DiscordAgent<N, P> {
531537 let update_subject = discord_nats:: subjects:: bot:: role_update ( self . subscriber . prefix ( ) ) ;
532538 let delete_subject = discord_nats:: subjects:: bot:: role_delete ( self . subscriber . prefix ( ) ) ;
533539
534- info ! ( "Subscribing to role lifecycle: {}, {}, {}" , create_subject, update_subject, delete_subject) ;
540+ info ! (
541+ "Subscribing to role lifecycle: {}, {}, {}" ,
542+ create_subject, update_subject, delete_subject
543+ ) ;
535544
536545 let mut create_stream = self
537546 . subscriber
@@ -652,7 +661,8 @@ impl<N: QueueSubscribeClient + Clone, P: Publish> DiscordAgent<N, P> {
652661 async fn handle_autocomplete ( & self ) -> Result < ( ) > {
653662 use discord_types:: events:: AutocompleteEvent ;
654663
655- let subject = discord_nats:: subjects:: bot:: interaction_autocomplete ( self . subscriber . prefix ( ) ) ;
664+ let subject =
665+ discord_nats:: subjects:: bot:: interaction_autocomplete ( self . subscriber . prefix ( ) ) ;
656666 info ! ( "Subscribing to autocomplete: {}" , subject) ;
657667
658668 let mut stream = self
@@ -832,8 +842,20 @@ mod tests {
832842 let client = MockNatsClient :: new ( ) ;
833843 let publisher = MockPublisher :: new ( "test" ) ;
834844 DiscordAgent :: new (
835- client, "test" . to_string ( ) , publisher, "test-agent" . to_string ( ) ,
836- None , None , None , None , None , None , None , 20 , 120 , None ,
845+ client,
846+ "test" . to_string ( ) ,
847+ publisher,
848+ "test-agent" . to_string ( ) ,
849+ None ,
850+ None ,
851+ None ,
852+ None ,
853+ None ,
854+ None ,
855+ None ,
856+ 20 ,
857+ 120 ,
858+ None ,
837859 )
838860 }
839861
@@ -851,7 +873,12 @@ mod tests {
851873 id : message_id,
852874 channel_id,
853875 guild_id : None ,
854- author : DiscordUser { id : 42 , username : "tester" . to_string ( ) , global_name : None , bot : false } ,
876+ author : DiscordUser {
877+ id : 42 ,
878+ username : "tester" . to_string ( ) ,
879+ global_name : None ,
880+ bot : false ,
881+ } ,
855882 content : content. to_string ( ) ,
856883 timestamp : "2024-01-01T00:00:00Z" . to_string ( ) ,
857884 edited_timestamp : None ,
@@ -878,7 +905,10 @@ mod tests {
878905 async fn test_agent_run_returns_err_when_subscribe_fails ( ) {
879906 let agent = make_agent ( ) ;
880907 let result = agent. run ( ) . await ;
881- assert ! ( result. is_err( ) , "run() must return Err when subscribe fails" ) ;
908+ assert ! (
909+ result. is_err( ) ,
910+ "run() must return Err when subscribe fails"
911+ ) ;
882912 let msg = result. unwrap_err ( ) . to_string ( ) ;
883913 assert ! ( !msg. is_empty( ) , "error must have a message" ) ;
884914 }
@@ -891,15 +921,30 @@ mod tests {
891921 let pub_ref = MockPublisher :: new ( "test" ) ;
892922 let event = make_message_event ( "sess-1" , "hello world" , 100 , 50 ) ;
893923
894- agent. processor . process_message ( & event, & pub_ref) . await . unwrap ( ) ;
924+ agent
925+ . processor
926+ . process_message ( & event, & pub_ref)
927+ . await
928+ . unwrap ( ) ;
895929
896930 let msgs = pub_ref. published_messages ( ) ;
897- assert_eq ! ( msgs. len( ) , 2 , "echo mode must publish typing + send_message" ) ;
931+ assert_eq ! (
932+ msgs. len( ) ,
933+ 2 ,
934+ "echo mode must publish typing + send_message"
935+ ) ;
898936 let cmd: discord_types:: SendMessageCommand =
899937 serde_json:: from_value ( msgs[ 1 ] . 1 . clone ( ) ) . unwrap ( ) ;
900938 assert_eq ! ( cmd. channel_id, 100 , "send must target the right channel" ) ;
901- assert ! ( cmd. content. contains( "hello world" ) , "send must echo the content" ) ;
902- assert_eq ! ( cmd. reply_to_message_id, Some ( 50 ) , "send must reply to the original message" ) ;
939+ assert ! (
940+ cmd. content. contains( "hello world" ) ,
941+ "send must echo the content"
942+ ) ;
943+ assert_eq ! (
944+ cmd. reply_to_message_id,
945+ Some ( 50 ) ,
946+ "send must reply to the original message"
947+ ) ;
903948 }
904949
905950 /// With ack_emoji: process_message publishes ack_reaction first, then typing, then send_message.
@@ -909,21 +954,49 @@ mod tests {
909954 let client = MockNatsClient :: new ( ) ;
910955 let publisher = MockPublisher :: new ( "test" ) ;
911956 let agent = DiscordAgent :: new (
912- client, "test" . to_string ( ) , publisher, "ack-agent" . to_string ( ) ,
913- None , None , None , None , None , None , None , 20 , 120 , Some ( "⏳" . to_string ( ) ) ,
957+ client,
958+ "test" . to_string ( ) ,
959+ publisher,
960+ "ack-agent" . to_string ( ) ,
961+ None ,
962+ None ,
963+ None ,
964+ None ,
965+ None ,
966+ None ,
967+ None ,
968+ 20 ,
969+ 120 ,
970+ Some ( "⏳" . to_string ( ) ) ,
914971 ) ;
915972 let pub_ref = MockPublisher :: new ( "test" ) ;
916973 let event = make_message_event ( "sess-2" , "help me" , 200 , 99 ) ;
917974
918- agent. processor . process_message ( & event, & pub_ref) . await . unwrap ( ) ;
975+ agent
976+ . processor
977+ . process_message ( & event, & pub_ref)
978+ . await
979+ . unwrap ( ) ;
919980
920981 let msgs = pub_ref. published_messages ( ) ;
921- assert ! ( msgs. len( ) >= 3 , "with ack_emoji: must publish ack_reaction + typing + send_message" ) ;
982+ assert ! (
983+ msgs. len( ) >= 3 ,
984+ "with ack_emoji: must publish ack_reaction + typing + send_message"
985+ ) ;
922986 let reaction: discord_types:: AddReactionCommand =
923987 serde_json:: from_value ( msgs[ 0 ] . 1 . clone ( ) ) . unwrap ( ) ;
924- assert_eq ! ( reaction. emoji, "⏳" , "ack reaction must use the configured emoji" ) ;
925- assert_eq ! ( reaction. message_id, 99 , "ack reaction must target the original message" ) ;
926- assert_eq ! ( reaction. channel_id, 200 , "ack reaction must be in the right channel" ) ;
988+ assert_eq ! (
989+ reaction. emoji, "⏳" ,
990+ "ack reaction must use the configured emoji"
991+ ) ;
992+ assert_eq ! (
993+ reaction. message_id, 99 ,
994+ "ack reaction must target the original message"
995+ ) ;
996+ assert_eq ! (
997+ reaction. channel_id, 200 ,
998+ "ack reaction must be in the right channel"
999+ ) ;
9271000 }
9281001
9291002 /// Two agents with different prefixes must not share publisher state.
@@ -932,16 +1005,44 @@ mod tests {
9321005 let pub_a = MockPublisher :: new ( "pfx-a" ) ;
9331006 let pub_b = MockPublisher :: new ( "pfx-b" ) ;
9341007 let agent_a = DiscordAgent :: new (
935- MockNatsClient :: new ( ) , "pfx-a" . to_string ( ) , pub_a. clone ( ) , "agent-a" . to_string ( ) ,
936- None , None , None , None , None , None , None , 20 , 120 , None ,
1008+ MockNatsClient :: new ( ) ,
1009+ "pfx-a" . to_string ( ) ,
1010+ pub_a. clone ( ) ,
1011+ "agent-a" . to_string ( ) ,
1012+ None ,
1013+ None ,
1014+ None ,
1015+ None ,
1016+ None ,
1017+ None ,
1018+ None ,
1019+ 20 ,
1020+ 120 ,
1021+ None ,
9371022 ) ;
9381023 let agent_b = DiscordAgent :: new (
939- MockNatsClient :: new ( ) , "pfx-b" . to_string ( ) , pub_b. clone ( ) , "agent-b" . to_string ( ) ,
940- None , None , None , None , None , None , None , 20 , 120 , None ,
1024+ MockNatsClient :: new ( ) ,
1025+ "pfx-b" . to_string ( ) ,
1026+ pub_b. clone ( ) ,
1027+ "agent-b" . to_string ( ) ,
1028+ None ,
1029+ None ,
1030+ None ,
1031+ None ,
1032+ None ,
1033+ None ,
1034+ None ,
1035+ 20 ,
1036+ 120 ,
1037+ None ,
9411038 ) ;
9421039
9431040 let event = make_message_event ( "sess-a" , "ping" , 100 , 1 ) ;
944- agent_a. processor . process_message ( & event, & pub_a) . await . unwrap ( ) ;
1041+ agent_a
1042+ . processor
1043+ . process_message ( & event, & pub_a)
1044+ . await
1045+ . unwrap ( ) ;
9451046
9461047 assert ! ( !pub_a. is_empty( ) , "agent_a's publisher must have messages" ) ;
9471048 assert ! ( pub_b. is_empty( ) , "agent_b's publisher must be unaffected" ) ;
0 commit comments