11/// Facebook command handler
22/// Supports: fb, fb [username/page], fb [search terms]
3+ /// Subcommands: mp/buy/sell -> Marketplace
34use crate :: commands:: bunnylol_command:: { BunnylolCommand , BunnylolCommandInfo } ;
45use crate :: utils:: url_encoding:: { build_path_url, build_search_url} ;
56
67pub struct FacebookCommand ;
78
89impl FacebookCommand {
10+ const MARKETPLACE_URL : & ' static str = "https://www.facebook.com/marketplace" ;
11+
912 fn construct_profile_url ( profile : & str ) -> String {
1013 build_path_url ( "https://www.facebook.com" , profile)
1114 }
@@ -20,14 +23,11 @@ impl BunnylolCommand for FacebookCommand {
2023
2124 fn process_args ( args : & str ) -> String {
2225 let query = Self :: get_command_args ( args) ;
23- if query. is_empty ( ) {
24- "https://www.facebook.com" . to_string ( )
25- } else if !query. contains ( ' ' ) {
26- // Single word without spaces - treat as profile/page
27- Self :: construct_profile_url ( query)
28- } else {
29- // Multiple words - search
30- Self :: construct_search_url ( query)
26+ match query {
27+ "" => "https://www.facebook.com" . to_string ( ) ,
28+ "mp" | "buy" | "sell" => Self :: MARKETPLACE_URL . to_string ( ) ,
29+ _ if !query. contains ( ' ' ) => Self :: construct_profile_url ( query) ,
30+ _ => Self :: construct_search_url ( query) ,
3131 }
3232 }
3333
@@ -67,4 +67,28 @@ mod tests {
6767 "https://www.facebook.com/search/top?q=Meta%20AI"
6868 ) ;
6969 }
70+
71+ #[ test]
72+ fn test_facebook_command_marketplace_mp ( ) {
73+ assert_eq ! (
74+ FacebookCommand :: process_args( "fb mp" ) ,
75+ FacebookCommand :: MARKETPLACE_URL
76+ ) ;
77+ }
78+
79+ #[ test]
80+ fn test_facebook_command_marketplace_buy ( ) {
81+ assert_eq ! (
82+ FacebookCommand :: process_args( "fb buy" ) ,
83+ FacebookCommand :: MARKETPLACE_URL
84+ ) ;
85+ }
86+
87+ #[ test]
88+ fn test_facebook_command_marketplace_sell ( ) {
89+ assert_eq ! (
90+ FacebookCommand :: process_args( "fb sell" ) ,
91+ FacebookCommand :: MARKETPLACE_URL
92+ ) ;
93+ }
7094}
0 commit comments