Example #1
0
def ab_bridge(ab_mode, target, msg, source, **kwds):
    work = te_work.get(target.lower())
    if work is None or not hasattr(work, 'terraria_protocol'): return
    msg = strip_codes(msg)
    if MAX_CHAT_LENGTH is not None:
        max_len = MAX_CHAT_LENGTH - len('<%s> ' % work.terraria.user)
        while len(msg) > max_len:
            head, msg = msg[:max_len-3]+'...', '...'+msg[max_len-3:]
            terraria_protocol.chat(work, head)
    terraria_protocol.chat(work, msg)
Example #2
0
def te_chat(work, slot, colour, text):
    no_echo = [False]
    echo_lines = []
    event_type = None
    agent = work.terraria.user

    if slot == 255:
        match = re.match(r'((?P<sn>\[\S+\])|\*(?P<an>\S+))\s*(?P<m>.*)', text)
        if match:
            event_type = 'MESSAGE' if match.group('sn') else 'ACTION'
            event_name = match.group('sn') or match.group('an')
            event_text = match.group('m')
    else:
        event_type = 'MESSAGE'
        event_name = work.terraria_protocol.players.get(slot, slot)
        event_text = text

    if event_type is not None:
        reply = bridge.substitute_reply(
            context       = work.terraria.name,
            local_name    = event_name,
            msg_local     = lambda m: terraria_protocol.chat(work, strip_codes(m)),
            msg_bridge    = lambda m: echo_lines.append('<%s> %s' % (agent, m)),
            cancel_bridge = lambda: operator.setitem(no_echo, 0, True))
        yield util.msign(ab_mode, ('BRIDGE', event_type), ab_mode,
            event_name, work.terraria.name, event_text, reply)

    if not no_echo[0] and slot != work.terraria_protocol.slot:
        if slot != 255:
            text = '<%s> %s' % (name, text)
        echo_lines.insert(0, text)

    for line in echo_lines:
        line = bridge.substitute_text(work.terraria.name, line)
        yield sign('TERRARIA', work, line)