default chat_was_last_it = False

default waiting_player_input_in_chat = False

python early:
    import re

    def _get_pic_if_exists(string):
        
        padrao = r"::(.*?)::"
        correspondencias = re.search(padrao, string)
        
        
        if correspondencias:
            return correspondencias.group(1)
        else:
            
            return None

    def _remove_pic_if_exists(string):
        
        padrao = r"::(.*?)::"
        resultado = re.sub(padrao, "", string)
        
        return resultado

    def translation_strings(parsed_object):
        who, target, rest = parsed_object
        if not rest:
            return [_remove_pic_if_exists(str(target))]
        else:
            return [_remove_pic_if_exists(str(rest))]

    def execute_cellphone_cds(parsed_object):
        who, target, rest = parsed_object
        if isinstance(eval(who), ADVCharacter) is False:
            raise Exception("Character '"+str(who)+"' not found")
        who = eval(who)
        if rest is not None and isinstance(eval(target), ADVCharacter) is False:
            raise Exception("Character '"+str(target)+"' not found")
        if rest is not None:
            target = eval(target)
        else:
            target = str(target)
        if target==who:
            raise Exception("You can't text yourself")
        if who!=cds_mc and rest is not None:
            raise Exception("The first param should be the main character")
        
        current_chat_room_state = False
        wait_chat_room_state = False
        
        if rest is None:
            PhoneManager.get_instance().send_chat_message_by_name(name=who.name, body=_remove_pic_if_exists(target), photo_big = _get_pic_if_exists(target))
            if PhoneManager.get_instance().wait_chat_room==ChatDatabase.get_profile_by_name(who.name):
                wait_chat_room_state = True
            if PhoneManager.get_instance().current_chat_room==ChatDatabase.get_profile_by_name(who.name):
                current_chat_room_state = True
            
            
            
            phone_chat_room_screen_yadj.scroll_bottom()
            if current_chat_room_state or wait_chat_room_state:
                renpy.pause(1.1)
        else:
            rest = str(rest)
            PhoneManager.get_instance().send_chat_message_by_name(name=target.name, is_sent_by_player=True, body=_remove_pic_if_exists(rest), photo_big = _get_pic_if_exists(rest))
            if PhoneManager.get_instance().wait_chat_room==ChatDatabase.get_profile_by_name(target.name):
                wait_chat_room_state = True
            if PhoneManager.get_instance().current_chat_room==ChatDatabase.get_profile_by_name(target.name):
                current_chat_room_state = True
            
            
            
            phone_chat_room_screen_yadj.scroll_bottom()
            if current_chat_room_state or wait_chat_room_state:
                global waiting_player_input_in_chat
                waiting_player_input_in_chat = True
                renpy.pause()
                waiting_player_input_in_chat = False
                renpy.pause(0.000000001) 
        if PhoneManager.get_instance().current_chat_room:
            PhoneManager.get_instance().mark_unseen_messages_seen_by_chat_profile_id(PhoneManager.get_instance().current_chat_room.id)
        phone_chat_room_screen_yadj.scroll_bottom()
        
        global chat_was_last_it
        chat_was_last_it = True
        
        return


    def parse_cellphone_cds(lexer):
        who = lexer.simple_expression()
        
        if not who:
            raise Exception("Expected name")
        
        target = lexer.string()
        
        if not target:
            target = lexer.simple_expression() 
        
        if not target:
            raise Exception("Expected text or message target")
        
        rest = lexer.string()
        
        if not rest:
            rest = None
        
        if lexer.rest():
            raise Exception("Too many arguments!")
        
        return (who, target, rest)


    renpy.register_statement(
    name="c",
    parse=parse_cellphone_cds,
    execute=execute_cellphone_cds,
    translatable=False,
    translation_strings=translation_strings
)
return
# Decompiled by unrpyc: https://github.com/CensoredUsername/unrpyc
