@@ -348,20 +348,10 @@ def get_mentioned_personas(self, new_message: Message) -> list[BasePersona]:
348348 return persona_list
349349
350350 def on_chat_message (self , room_id : str , message : Message ):
351- self .route_message (message )
352-
353- def on_slash_cmd_message (self , room_id : str , message : Message ):
354- self .route_slash_command (message )
355-
356- def route_message (self , new_message : Message ):
357351 """
358352 Method that routes an incoming message to the correct personas by
359353 calling their `process_message()` methods.
360354
361- - If the message contains a slash command, the slash command will be
362- dispatched to `route_slash_command()` first. If the slash command is
363- unrecognized, the message will be handled as a normal message.
364-
365355 - If the chat has multiple users, then each persona only replies
366356 when `@`-mentioned.
367357
@@ -373,29 +363,21 @@ def route_message(self, new_message: Message):
373363 regardless of whether it is `@`-mentioned.
374364 """
375365
376- # Dispatch message to `route_slash_command()` if the first word is a
377- # slash command. Return immediately if the slash command is recognized.
378- first_word = get_first_word (new_message .body )
379- if first_word and first_word .startswith ("/" ):
380- slash_cmd_recognized = self .route_slash_command (new_message )
381- if slash_cmd_recognized :
382- return
383-
384366 # Gather routing context
385367 human_users = self .get_active_human_users ()
386368 sender_not_human = (
387- is_persona (new_message .sender ) or new_message .sender == SYSTEM_USERNAME
369+ is_persona (message .sender ) or message .sender == SYSTEM_USERNAME
388370 )
389371 sender_is_human = not sender_not_human
390- mentioned_personas = self .get_mentioned_personas (new_message )
372+ mentioned_personas = self .get_mentioned_personas (message )
391373 human_user_count = len (human_users )
392374 persona_count = len (self .personas )
393375
394376 # Multi-user case & non-human message case: only route message to
395377 # mentioned personas
396378 if sender_not_human or human_user_count > 1 :
397379 if mentioned_personas :
398- self ._broadcast (new_message , to_personas = mentioned_personas )
380+ self ._broadcast (message , to_personas = mentioned_personas )
399381 return
400382
401383 # Single user + multiple personas case: route message to mentioned
@@ -411,13 +393,13 @@ def route_message(self, new_message: Message):
411393 targeted_personas = mentioned_personas
412394 if default_persona and not targeted_personas :
413395 targeted_personas = [default_persona ]
414- self ._broadcast (new_message , to_personas = targeted_personas )
396+ self ._broadcast (message , to_personas = targeted_personas )
415397 return
416398
417399 # Default case (single user, 0/1 personas): persona always replies if present
418- self ._broadcast (new_message , to_personas = self .personas )
400+ self ._broadcast (message , to_personas = self .personas )
419401 return
420-
402+
421403 def _broadcast (
422404 self ,
423405 message : Message ,
@@ -434,7 +416,7 @@ def _broadcast(
434416 self .event_loop .create_task (persona .process_message (message ))
435417 return
436418
437- def route_slash_command (self , new_message : Message ) -> bool :
419+ def on_slash_cmd_message (self , room_id : str , message : Message ) :
438420 """
439421 Routes & handles a message containing a slash command. Returns `True` if
440422 the message specified a valid slash command recognized by
@@ -448,12 +430,12 @@ def route_slash_command(self, new_message: Message) -> bool:
448430 should return back to `route_message()`. This allows AI personas to
449431 receive custom slash commands that only they recognize.
450432 """
451- first_word = get_first_word (new_message .body )
433+ first_word = get_first_word (message .body )
452434 assert first_word and first_word .startswith ("/" )
453435
454436 command_id = first_word [1 :]
455437 if command_id == "refresh-personas" :
456- self .handle_refresh_personas_command (new_message )
438+ self .handle_refresh_personas_command (message )
457439 return True
458440
459441 # If command is unrecognized, log an error
0 commit comments