@@ -37,28 +37,63 @@ async fn main() -> Result<()> {
3737
3838 client. matrix_auth ( ) . login_username ( & username, & password) . await ?;
3939
40+ let ignore_bridge_users = env:: var ( "IGNORE_BRIDGE_USERS" )
41+ . map ( |v| v. to_lowercase ( ) == "true" )
42+ . unwrap_or ( false ) ;
43+
44+ let start_time = std:: time:: SystemTime :: now ( )
45+ . duration_since ( std:: time:: UNIX_EPOCH )
46+ . expect ( "Time went backwards" )
47+ . as_millis ( ) as u64 ;
48+
4049 // Share link_store with event handler
4150 let store_clone = link_store. clone ( ) ;
4251
4352 client. add_event_handler ( move |event : OriginalSyncRoomMessageEvent , room : Room | {
4453 let store = store_clone. clone ( ) ;
4554 async move {
55+ let sender = event. sender . as_str ( ) ;
56+ if ignore_bridge_users && sender. starts_with ( "@discord_" ) {
57+ return ;
58+ }
59+
60+ if u64:: from ( event. origin_server_ts . get ( ) ) < start_time {
61+ return ;
62+ }
63+
4664 let RoomMessageEventContent { msgtype, .. } = event. content ;
4765
4866 if let MessageType :: Text ( text_content) = msgtype {
4967 let body = text_content. body ;
50- if body. starts_with ( ".wiki " ) {
51- let argument = body. trim_start_matches ( ".wiki " ) . trim ( ) ;
52- if let Some ( link) = store. get ( argument) {
53- let response = format ! ( "Link for {}: {}" , argument, link) ;
68+ if body == ".wiki" || body. starts_with ( ".wiki " ) {
69+ let argument = body. trim_start_matches ( ".wiki" ) . trim ( ) ;
70+ if argument. is_empty ( ) {
71+ let response = "Use .wiki list to print all available links" ;
72+ let content = RoomMessageEventContent :: text_plain ( response) ;
73+ if let Err ( e) = room. send ( content) . await {
74+ eprintln ! ( "Failed to send message: {}" , e) ;
75+ }
76+ } else if argument == "list" {
77+ let keys = store. list_keys ( ) ;
78+ let response = if keys. is_empty ( ) {
79+ "No wiki links available." . to_string ( )
80+ } else {
81+ format ! ( "Available wiki links: {}" , keys. join( ", " ) )
82+ } ;
83+ let content = RoomMessageEventContent :: text_plain ( response) ;
84+ if let Err ( e) = room. send ( content) . await {
85+ eprintln ! ( "Failed to send message: {}" , e) ;
86+ }
87+ } else if let Some ( link) = store. get ( argument) {
88+ let response = format ! ( "Link for {}: {}\n (Use .wiki list to print all available links)" , argument, link) ;
5489 // Send response
5590 let content = RoomMessageEventContent :: text_plain ( response) ;
5691 if let Err ( e) = room. send ( content) . await {
5792 eprintln ! ( "Failed to send message: {}" , e) ;
5893 }
5994 } else {
6095 // Optional: reply not found, or just ignore
61- let response = format ! ( "No wiki link found for '{}'" , argument) ;
96+ let response = format ! ( "No wiki link found for '{}'\n (Use .wiki list to print all available links) " , argument) ;
6297 let content = RoomMessageEventContent :: text_plain ( response) ;
6398 if let Err ( e) = room. send ( content) . await {
6499 eprintln ! ( "Failed to send message: {}" , e) ;
0 commit comments