コード例 #1
0
    def kick(server, buf, args):
        split_args = args.split(" ", 1)[1:]

        if (len(split_args) < 1
                or split_args[0].startswith("#") and len(split_args) < 2):
            error_msg = ('{prefix}Error with command "/kick" (help on '
                         'command: /help kick)').format(
                             prefix=W.prefix("error"))
            W.prnt("", error_msg)
            return

        if split_args[0].startswith("#"):
            assert len(split_args) >= 2
            room_id = split_args[0]
            kicked_user = split_args[1]
            reason = split_args[2:] or None
        else:
            room_id = key_from_value(server.buffers, buf)
            kicked_user = split_args[0]
            reason = split_args[1:] or None

        message = MatrixKickMessage(server.client,
                                    room_id=room_id,
                                    user_id=kicked_user,
                                    reason=reason)
        server.send_or_queue(message)
コード例 #2
0
def matrix_me_command_cb(data, buffer, args):
    for server in SERVERS.values():
        if buffer in server.buffers.values():

            if not server.connected:
                message = ("{prefix}matrix: you are not connected to "
                           "the server").format(prefix=W.prefix("error"))
                W.prnt(server.server_buffer, message)
                return W.WEECHAT_RC_ERROR

            room_id = key_from_value(server.buffers, buffer)

            if not args:
                return W.WEECHAT_RC_OK

            formatted_data = Formatted.from_input_line(args)
            message = MatrixEmoteMessage(server.client,
                                         room_id=room_id,
                                         formatted_message=formatted_data)

            server.send_or_queue(message)

            return W.WEECHAT_RC_OK

        elif buffer == server.server_buffer:
            message = ("{prefix}matrix: command \"me\" must be "
                       "executed on a Matrix channel buffer").format(
                           prefix=W.prefix("error"))
            W.prnt("", message)
            return W.WEECHAT_RC_OK
コード例 #3
0
ファイル: config.py プロジェクト: tylerjw/weechat-matrix
def matrix_config_change_cb(data, option):
    option_name = key_from_value(OPTIONS.options, option)

    if option_name == "redactions":
        OPTIONS.redaction_type = RedactType(W.config_integer(option))

    elif option_name == "server_buffer":
        OPTIONS.look_server_buf = ServerBufferType(W.config_integer(option))
        for server in SERVERS.values():
            if server.server_buffer:
                server_buffer_merge(server.server_buffer)

    elif option_name == "max_initial_sync_events":
        OPTIONS.sync_limit = W.config_integer(option)

    elif option_name == "max_backlog_sync_events":
        OPTIONS.backlog_limit = W.config_integer(option)

    elif option_name == "fetch_backlog_on_pgup":
        OPTIONS.enable_backlog = W.config_boolean(option)

        if OPTIONS.enable_backlog:
            if not OPTIONS.page_up_hook:
                hook_page_up(matrix.globals.CONFIG)
        else:
            if OPTIONS.page_up_hook:
                W.unhook(OPTIONS.page_up_hook)
                OPTIONS.page_up_hook = None

    return 1
コード例 #4
0
def matrix_bar_item_name(data, item, window, buffer, extra_info):
    # pylint: disable=unused-argument
    for server in SERVERS.values():
        if buffer in server.buffers.values():
            color = ("status_name_ssl"
                     if server.ssl_context.check_hostname else "status_name")

            room_id = key_from_value(server.buffers, buffer)

            room = server.rooms[room_id]

            return "{color}{name}".format(
                color=W.color(color),
                name=room.display_name(server.user_id))

        elif buffer == server.server_buffer:
            color = ("status_name_ssl"
                     if server.ssl_context.check_hostname else "status_name")

            return "{color}server{del_color}[{color}{name}{del_color}]".format(
                color=W.color(color),
                del_color=W.color("bar_delim"),
                name=server.name)

    return ""
コード例 #5
0
def matrix_command_buf_clear_cb(data, buffer, command):
    for server in SERVERS.values():
        if buffer in server.buffers.values():
            room_id = key_from_value(server.buffers, buffer)
            server.rooms[room_id].prev_batch = server.next_batch

            return W.WEECHAT_RC_OK

    return W.WEECHAT_RC_OK
コード例 #6
0
ファイル: server.py プロジェクト: tylerjw/weechat-matrix
def matrix_config_server_change_cb(server_name, option):
    # type: (str, weechat.config_option) -> int
    server = SERVERS[server_name]
    option_name = None

    # The function config_option_get_string() is used to get differing
    # properties from a config option, sadly it's only available in the plugin
    # API of weechat.
    option_name = key_from_value(server.options, option)
    server.update_option(option, option_name)

    return 1
コード例 #7
0
def matrix_bar_item_buffer_modes(data, item, window, buffer, extra_info):
    # pylint: disable=unused-argument
    for server in SERVERS.values():
        if buffer in server.buffers.values():
            room_id = key_from_value(server.buffers, buffer)
            room = server.rooms[room_id]
            modes = []

            if room.encrypted:
                modes.append("�")

            if room.backlog_pending:
                modes.append("�")

            return "".join(modes)

    return ""
コード例 #8
0
    def invite(server, buf, args):
        split_args = args.split(" ", 1)

        # TODO handle join for non public rooms
        if len(split_args) != 2:
            message = ("{prefix}Error with command \"/invite\" (help on "
                       "command: /help invite)").format(
                           prefix=W.prefix("error"))
            W.prnt("", message)
            return

        _, invitee = split_args
        room_id = key_from_value(server.buffers, buf)

        message = MatrixInviteMessage(server.client,
                                      room_id=room_id,
                                      user_id=invitee)
        server.send_or_queue(message)
コード例 #9
0
def matrix_redact_command_cb(data, buffer, args):
    for server in SERVERS.values():
        if buffer in server.buffers.values():
            room_id = key_from_value(server.buffers, buffer)

            matches = re.match(r"(\d+)(:\".*\")? ?(.*)?", args)

            if not matches:
                message = (
                    "{prefix}matrix: Invalid command arguments (see /help redact)"
                ).format(prefix=W.prefix("error"))
                W.prnt("", message)
                return W.WEECHAT_RC_ERROR

            line_string, _, reason = matches.groups()
            line = int(line_string)

            event_id = event_id_from_line(buffer, line)

            if not event_id:
                message = ("{prefix}matrix: No such message with number "
                           "{number} found").format(prefix=W.prefix("error"),
                                                    number=line)
                W.prnt("", message)
                return W.WEECHAT_RC_OK

            message = MatrixRedactMessage(server.client,
                                          room_id=room_id,
                                          event_id=event_id,
                                          reason=reason)
            server.send_or_queue(message)

            return W.WEECHAT_RC_OK

        elif buffer == server.server_buffer:
            message = ("{prefix}matrix: command \"redact\" must be "
                       "executed on a Matrix channel buffer").format(
                           prefix=W.prefix("error"))
            W.prnt("", message)
            return W.WEECHAT_RC_OK

    return W.WEECHAT_RC_OK
コード例 #10
0
def matrix_command_pgup_cb(data, buffer, command):
    # TODO the highlight status of a line isn't allowed to be updated/changed
    # via hdata, therefore the highlight status of a messages can't be
    # reoredered this would need to be fixed in weechat
    # TODO we shouldn't fetch and print out more messages than
    # max_buffer_lines_number or older messages than max_buffer_lines_minutes
    for server in SERVERS.values():
        if buffer in server.buffers.values():
            window = W.window_search_with_buffer(buffer)

            first_line_displayed = bool(
                W.window_get_integer(window, "first_line_displayed"))

            if first_line_displayed:
                room_id = key_from_value(server.buffers, buffer)
                matrix_fetch_old_messages(server, room_id)

            return W.WEECHAT_RC_OK

    return W.WEECHAT_RC_OK
コード例 #11
0
    def part(server, buffer, args):
        rooms = []

        split_args = args.split(" ", 1)

        if len(split_args) == 1:
            if buffer == server.server_buffer:
                message = ("{prefix}Error with command \"/part\" (help on "
                           "command: /help part)").format(
                               prefix=W.prefix("error"))
                W.prnt("", message)
                return

            rooms = [key_from_value(server.buffers, buffer)]

        else:
            _, rooms = split_args
            rooms = rooms.split(" ")

        for room_id in rooms:
            message = MatrixPartMessage(server.client, room_id=room_id)
            server.send_or_queue(message)
コード例 #12
0
def matrix_command_topic_cb(data, buffer, command):
    for server in SERVERS.values():
        if buffer in server.buffers.values():
            topic = None
            room_id = key_from_value(server.buffers, buffer)
            split_command = command.split(' ', 1)

            if len(split_command) == 2:
                topic = split_command[1]

            if not topic:
                room = server.rooms[room_id]
                if not room.topic:
                    return W.WEECHAT_RC_OK

                if room.is_named():
                    message = ('{prefix}Topic for {color}{room}{ncolor} is '
                               '"{topic}"').format(
                                   prefix=W.prefix("network"),
                                   color=W.color("chat_buffer"),
                                   ncolor=W.color("reset"),
                                   room=room.named_room_name(),
                                   topic=room.topic)
                else:
                    message = ('{prefix}Topic is "{topic}"').format(
                        prefix=W.prefix("network"), topic=room.topic)

                date = int(time.time())
                topic_date = room.topic_date.strftime("%a, %d %b %Y "
                                                      "%H:%M:%S")

                tags = "matrix_topic,log1"
                W.prnt_date_tags(buffer, date, tags, message)

                # TODO the nick should be colored

                # TODO we should use the display name as well as
                # the user name here
                message = ("{prefix}Topic set by {author} on "
                           "{date}").format(prefix=W.prefix("network"),
                                            author=room.topic_author,
                                            date=topic_date)
                W.prnt_date_tags(buffer, date, tags, message)

                return W.WEECHAT_RC_OK_EAT

            message = MatrixTopicMessage(server.client,
                                         room_id=room_id,
                                         topic=topic)
            server.send_or_queue(message)

            return W.WEECHAT_RC_OK_EAT

        elif buffer == server.server_buffer:
            message = ("{prefix}matrix: command \"topic\" must be "
                       "executed on a Matrix channel buffer").format(
                           prefix=W.prefix("error"))
            W.prnt(buffer, message)
            return W.WEECHAT_RC_OK_EAT

    return W.WEECHAT_RC_OK