Esempio n. 1
0
def test_receive(content):
    def handle_ping(data):
        assert 'location' in data
        assert 'timestamp' in data

    SocketScience.register('ping', handle_ping)
    SocketScience.receive(content)
def test_receive(content):
    def handle_ping(data):
        assert 'location' in data
        assert 'timestamp' in data

    SocketScience.register('ping', handle_ping)
    SocketScience.receive(content)
Esempio n. 3
0
def on_msg(msg, client):
    global _room_roles

    if not isinstance(msg, events.MessagePosted) and not isinstance(
            msg, events.MessageEdited):
        return

    message = msg.message
    room_ident = (client.host, message.room.id)

    with _room_roles_lock:
        if message.owner.id == client._br.user_id:
            if 'direct' in _room_roles and room_ident in _room_roles['direct']:
                SocketScience.receive(
                    message.content_source.replace("\u200B",
                                                   "").replace("\u200C", ""))

            return

    if message.content.startswith("<div class='partial'>"):
        message.content = message.content[21:]
        if message.content.endswith("</div>"):
            message.content = message.content[:-6]

    if message.parent:
        try:
            if message.parent.owner.id == client._br.user_id:
                strip_mention = regex.sub(
                    "^(<span class=(\"|')mention(\"|')>)?@.*?(</span>)? ", "",
                    message.content)
                cmd = GlobalVars.parser.unescape(strip_mention)

                result = dispatch_reply_command(message.parent, message, cmd)
                send_reply_if_not_blank(room_ident, message.id, result)
        except ValueError:
            pass
    elif message.content.lower().startswith("sd "):
        result = dispatch_shorthand_command(message)
        send_reply_if_not_blank(room_ident, message.id, result)
    elif message.content.startswith(
            "!!/") or message.content.lower().startswith("sdc "):
        result = dispatch_command(message)
        send_reply_if_not_blank(room_ident, message.id, result)
    elif classes.feedback.FEEDBACK_REGEX.search(message.content) \
            and is_privileged(message.owner, message.room) and datahandling.last_feedbacked:
        ids, expires_in = datahandling.last_feedbacked

        if time.time() < expires_in:
            Tasks.do(metasmoke.Metasmoke.post_auto_comment,
                     message.content_source,
                     message.owner,
                     ids=ids)
    else:
        with _room_roles_lock:
            if 'direct' in _room_roles and room_ident in _room_roles['direct']:
                SocketScience.receive(
                    message.content_source.replace("\u200B",
                                                   "").replace("\u200C", ""))
def on_msg(msg, client):
    global _room_roles

    if not isinstance(msg, events.MessagePosted) and not isinstance(msg, events.MessageEdited):
        return

    message = msg.message
    room_ident = (client.host, message.room.id)
    room_data = _rooms[room_ident]

    if message.owner.id == client._br.user_id:
        if 'direct' in _room_roles and room_ident in _room_roles['direct']:
            SocketScience.receive(message.content_source.replace("\u200B", "").replace("\u200C", ""))

        return

    if message.content.startswith("<div class='partial'>"):
        message.content = message.content[21:]
        if message.content.endswith("</div>"):
            message.content = message.content[:-6]

    if message.parent:
        try:
            if message.parent.owner.id == client._br.user_id:
                strip_mention = regex.sub("^(<span class=(\"|')mention(\"|')>)?@.*?(</span>)? ", "", message.content)
                cmd = GlobalVars.parser.unescape(strip_mention)

                result = dispatch_reply_command(message.parent, message, cmd)

                if result:
                    s = ":{}\n{}" if "\n" not in result and len(result) >= 488 else ":{} {}"
                    _msg_queue.put((room_data, s.format(message.id, result), None))
        except ValueError:
            pass
    elif message.content.lower().startswith("sd "):
        result = dispatch_shorthand_command(message)

        if result:
            s = ":{}\n{}" if "\n" not in result and len(result) >= 488 else ":{} {}"
            _msg_queue.put((room_data, s.format(message.id, result), None))
    elif message.content.startswith("!!/"):
        result = dispatch_command(message)

        if result:
            s = ":{}\n{}" if "\n" not in result and len(result) >= 488 else ":{} {}"
            _msg_queue.put((room_data, s.format(message.id, result), None))
    elif classes.feedback.FEEDBACK_REGEX.search(message.content) \
            and is_privileged(message.owner, message.room) and datahandling.last_feedbacked:
        ids, expires_in = datahandling.last_feedbacked

        if time.time() < expires_in:
            Tasks.do(metasmoke.Metasmoke.post_auto_comment, message.content_source, message.owner, ids=ids)
    elif 'direct' in _room_roles and room_ident in _room_roles['direct']:
        SocketScience.receive(message.content_source.replace("\u200B", "").replace("\u200C", ""))