More formatting fixes using yapf.
This commit is contained in:
parent
6d4f69e3a2
commit
11076f9649
8 changed files with 172 additions and 349 deletions
|
@ -43,21 +43,17 @@ def matrix_bar_item_name(data, item, window, buffer, extra_info):
|
||||||
for server in SERVERS.values():
|
for server in SERVERS.values():
|
||||||
if buffer in server.buffers.values():
|
if buffer in server.buffers.values():
|
||||||
color = ("status_name_ssl"
|
color = ("status_name_ssl"
|
||||||
if server.ssl_context.check_hostname else
|
if server.ssl_context.check_hostname else "status_name")
|
||||||
"status_name")
|
|
||||||
|
|
||||||
room_id = key_from_value(server.buffers, buffer)
|
room_id = key_from_value(server.buffers, buffer)
|
||||||
|
|
||||||
room = server.rooms[room_id]
|
room = server.rooms[room_id]
|
||||||
|
|
||||||
return "{color}{name}".format(
|
return "{color}{name}".format(color=W.color(color), name=room.alias)
|
||||||
color=W.color(color),
|
|
||||||
name=room.alias)
|
|
||||||
|
|
||||||
elif buffer == server.server_buffer:
|
elif buffer == server.server_buffer:
|
||||||
color = ("status_name_ssl"
|
color = ("status_name_ssl"
|
||||||
if server.ssl_context.check_hostname else
|
if server.ssl_context.check_hostname else "status_name")
|
||||||
"status_name")
|
|
||||||
|
|
||||||
return "{color}server{del_color}[{color}{name}{del_color}]".format(
|
return "{color}server{del_color}[{color}{name}{del_color}]".format(
|
||||||
color=W.color(color),
|
color=W.color(color),
|
||||||
|
@ -82,8 +78,7 @@ def matrix_bar_item_lag(data, item, window, buffer, extra_info):
|
||||||
lag_string = "Lag: {color}{lag}{ncolor}".format(
|
lag_string = "Lag: {color}{lag}{ncolor}".format(
|
||||||
lag=lag.format((server.lag / 1000)),
|
lag=lag.format((server.lag / 1000)),
|
||||||
color=color,
|
color=color,
|
||||||
ncolor=W.color("reset")
|
ncolor=W.color("reset"))
|
||||||
)
|
|
||||||
return lag_string
|
return lag_string
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
|
@ -24,15 +24,9 @@ import matrix.globals
|
||||||
from matrix.globals import W, OPTIONS, SERVERS
|
from matrix.globals import W, OPTIONS, SERVERS
|
||||||
|
|
||||||
from matrix.utf import utf8_decode
|
from matrix.utf import utf8_decode
|
||||||
from matrix.api import (
|
from matrix.api import (MessageType, MatrixTopicMessage, MatrixRedactMessage,
|
||||||
MessageType,
|
MatrixBacklogMessage, MatrixJoinMessage,
|
||||||
MatrixTopicMessage,
|
MatrixPartMessage, MatrixInviteMessage)
|
||||||
MatrixRedactMessage,
|
|
||||||
MatrixBacklogMessage,
|
|
||||||
MatrixJoinMessage,
|
|
||||||
MatrixPartMessage,
|
|
||||||
MatrixInviteMessage
|
|
||||||
)
|
|
||||||
from matrix.utils import key_from_value, tags_from_line_data
|
from matrix.utils import key_from_value, tags_from_line_data
|
||||||
from matrix.plugin_options import DebugType
|
from matrix.plugin_options import DebugType
|
||||||
from matrix.server import MatrixServer
|
from matrix.server import MatrixServer
|
||||||
|
@ -41,60 +35,52 @@ from matrix.server import MatrixServer
|
||||||
def hook_commands():
|
def hook_commands():
|
||||||
W.hook_command(
|
W.hook_command(
|
||||||
# Command name and short description
|
# Command name and short description
|
||||||
'matrix', 'Matrix chat protocol command',
|
'matrix',
|
||||||
|
'Matrix chat protocol command',
|
||||||
# Synopsis
|
# Synopsis
|
||||||
(
|
('server add <server-name> <hostname>[:<port>] ||'
|
||||||
'server add <server-name> <hostname>[:<port>] ||'
|
|
||||||
'server delete|list|listfull <server-name> ||'
|
'server delete|list|listfull <server-name> ||'
|
||||||
'connect <server-name> ||'
|
'connect <server-name> ||'
|
||||||
'disconnect <server-name> ||'
|
'disconnect <server-name> ||'
|
||||||
'reconnect <server-name> ||'
|
'reconnect <server-name> ||'
|
||||||
'debug <debug-type> ||'
|
'debug <debug-type> ||'
|
||||||
'help <matrix-command>'
|
'help <matrix-command>'),
|
||||||
),
|
|
||||||
# Description
|
# Description
|
||||||
(
|
(' server: list, add, or remove Matrix servers\n'
|
||||||
' server: list, add, or remove Matrix servers\n'
|
|
||||||
' connect: connect to Matrix servers\n'
|
' connect: connect to Matrix servers\n'
|
||||||
'disconnect: disconnect from one or all Matrix servers\n'
|
'disconnect: disconnect from one or all Matrix servers\n'
|
||||||
' reconnect: reconnect to server(s)\n\n'
|
' reconnect: reconnect to server(s)\n\n'
|
||||||
' help: show detailed command help\n\n'
|
' help: show detailed command help\n\n'
|
||||||
' debug: enable or disable debugging\n\n'
|
' debug: enable or disable debugging\n\n'
|
||||||
'Use /matrix help [command] to find out more\n'
|
'Use /matrix help [command] to find out more\n'),
|
||||||
),
|
|
||||||
# Completions
|
# Completions
|
||||||
(
|
('server %(matrix_server_commands)|%* ||'
|
||||||
'server %(matrix_server_commands)|%* ||'
|
|
||||||
'connect %(matrix_servers) ||'
|
'connect %(matrix_servers) ||'
|
||||||
'disconnect %(matrix_servers) ||'
|
'disconnect %(matrix_servers) ||'
|
||||||
'reconnect %(matrix_servers) ||'
|
'reconnect %(matrix_servers) ||'
|
||||||
'debug %(matrix_debug_types) ||'
|
'debug %(matrix_debug_types) ||'
|
||||||
'help %(matrix_commands)'
|
'help %(matrix_commands)'),
|
||||||
),
|
|
||||||
# Function name
|
# Function name
|
||||||
'matrix_command_cb', '')
|
'matrix_command_cb',
|
||||||
|
'')
|
||||||
|
|
||||||
W.hook_command(
|
W.hook_command(
|
||||||
# Command name and short description
|
# Command name and short description
|
||||||
'redact', 'redact messages',
|
'redact',
|
||||||
|
'redact messages',
|
||||||
# Synopsis
|
# Synopsis
|
||||||
(
|
('<message-number>[:<"message-part">] [<reason>]'),
|
||||||
'<message-number>[:<"message-part">] [<reason>]'
|
|
||||||
),
|
|
||||||
# Description
|
# Description
|
||||||
(
|
("message-number: number of the message to redact (message numbers"
|
||||||
"message-number: number of the message to redact (message numbers"
|
|
||||||
"\n start from the last recieved as "
|
"\n start from the last recieved as "
|
||||||
"1 and count up)\n"
|
"1 and count up)\n"
|
||||||
" message-part: a shortened part of the message\n"
|
" message-part: a shortened part of the message\n"
|
||||||
" reason: the redaction reason\n"
|
" reason: the redaction reason\n"),
|
||||||
),
|
|
||||||
# Completions
|
# Completions
|
||||||
(
|
('%(matrix_messages)'),
|
||||||
'%(matrix_messages)'
|
|
||||||
),
|
|
||||||
# Function name
|
# Function name
|
||||||
'matrix_redact_command_cb', '')
|
'matrix_redact_command_cb',
|
||||||
|
'')
|
||||||
|
|
||||||
W.hook_command_run('/topic', 'matrix_command_topic_cb', '')
|
W.hook_command_run('/topic', 'matrix_command_topic_cb', '')
|
||||||
W.hook_command_run('/buffer clear', 'matrix_command_buf_clear_cb', '')
|
W.hook_command_run('/buffer clear', 'matrix_command_buf_clear_cb', '')
|
||||||
|
@ -121,8 +107,7 @@ def matrix_fetch_old_messages(server, room_id):
|
||||||
server.client,
|
server.client,
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
token=prev_batch,
|
token=prev_batch,
|
||||||
limit=OPTIONS.backlog_limit
|
limit=OPTIONS.backlog_limit)
|
||||||
)
|
|
||||||
room.backlog_pending = True
|
room.backlog_pending = True
|
||||||
|
|
||||||
server.send_or_queue(message)
|
server.send_or_queue(message)
|
||||||
|
@ -140,11 +125,8 @@ def check_server_existence(server_name, servers):
|
||||||
|
|
||||||
|
|
||||||
def hook_page_up():
|
def hook_page_up():
|
||||||
OPTIONS.page_up_hook = W.hook_command_run(
|
OPTIONS.page_up_hook = W.hook_command_run('/window page_up',
|
||||||
'/window page_up',
|
'matrix_command_pgup_cb', '')
|
||||||
'matrix_command_pgup_cb',
|
|
||||||
''
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@utf8_decode
|
@utf8_decode
|
||||||
|
@ -171,8 +153,7 @@ def matrix_command_pgup_cb(data, buffer, command):
|
||||||
window = W.window_search_with_buffer(buffer)
|
window = W.window_search_with_buffer(buffer)
|
||||||
|
|
||||||
first_line_displayed = bool(
|
first_line_displayed = bool(
|
||||||
W.window_get_integer(window, "first_line_displayed")
|
W.window_get_integer(window, "first_line_displayed"))
|
||||||
)
|
|
||||||
|
|
||||||
if first_line_displayed:
|
if first_line_displayed:
|
||||||
room_id = key_from_value(server.buffers, buffer)
|
room_id = key_from_value(server.buffers, buffer)
|
||||||
|
@ -185,22 +166,19 @@ def matrix_command_pgup_cb(data, buffer, command):
|
||||||
|
|
||||||
@utf8_decode
|
@utf8_decode
|
||||||
def matrix_command_join_cb(data, buffer, command):
|
def matrix_command_join_cb(data, buffer, command):
|
||||||
|
|
||||||
def join(server, args):
|
def join(server, args):
|
||||||
split_args = args.split(" ", 1)
|
split_args = args.split(" ", 1)
|
||||||
|
|
||||||
# TODO handle join for non public rooms
|
# TODO handle join for non public rooms
|
||||||
if len(split_args) != 2:
|
if len(split_args) != 2:
|
||||||
message = ("{prefix}Error with command \"/join\" (help on "
|
message = ("{prefix}Error with command \"/join\" (help on "
|
||||||
"command: /help join)").format(
|
"command: /help join)").format(prefix=W.prefix("error"))
|
||||||
prefix=W.prefix("error"))
|
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
return
|
return
|
||||||
|
|
||||||
_, room_id = split_args
|
_, room_id = split_args
|
||||||
message = MatrixJoinMessage(
|
message = MatrixJoinMessage(server.client, room_id=room_id)
|
||||||
server.client,
|
|
||||||
room_id=room_id
|
|
||||||
)
|
|
||||||
server.send_or_queue(message)
|
server.send_or_queue(message)
|
||||||
|
|
||||||
for server in SERVERS.values():
|
for server in SERVERS.values():
|
||||||
|
@ -216,6 +194,7 @@ def matrix_command_join_cb(data, buffer, command):
|
||||||
|
|
||||||
@utf8_decode
|
@utf8_decode
|
||||||
def matrix_command_part_cb(data, buffer, command):
|
def matrix_command_part_cb(data, buffer, command):
|
||||||
|
|
||||||
def part(server, buffer, args):
|
def part(server, buffer, args):
|
||||||
rooms = []
|
rooms = []
|
||||||
|
|
||||||
|
@ -223,9 +202,9 @@ def matrix_command_part_cb(data, buffer, command):
|
||||||
|
|
||||||
if len(split_args) == 1:
|
if len(split_args) == 1:
|
||||||
if buffer == server.server_buffer:
|
if buffer == server.server_buffer:
|
||||||
message = ("{prefix}Error with command \"/part\" (help on "
|
message = (
|
||||||
"command: /help part)").format(
|
"{prefix}Error with command \"/part\" (help on "
|
||||||
prefix=W.prefix("error"))
|
"command: /help part)").format(prefix=W.prefix("error"))
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -236,10 +215,7 @@ def matrix_command_part_cb(data, buffer, command):
|
||||||
rooms = rooms.split(" ")
|
rooms = rooms.split(" ")
|
||||||
|
|
||||||
for room_id in rooms:
|
for room_id in rooms:
|
||||||
message = MatrixPartMessage(
|
message = MatrixPartMessage(server.client, room_id=room_id)
|
||||||
server.client,
|
|
||||||
room_id=room_id
|
|
||||||
)
|
|
||||||
server.send_or_queue(message)
|
server.send_or_queue(message)
|
||||||
|
|
||||||
for server in SERVERS.values():
|
for server in SERVERS.values():
|
||||||
|
@ -255,14 +231,15 @@ def matrix_command_part_cb(data, buffer, command):
|
||||||
|
|
||||||
@utf8_decode
|
@utf8_decode
|
||||||
def matrix_command_invite_cb(data, buffer, command):
|
def matrix_command_invite_cb(data, buffer, command):
|
||||||
|
|
||||||
def invite(server, buf, args):
|
def invite(server, buf, args):
|
||||||
split_args = args.split(" ", 1)
|
split_args = args.split(" ", 1)
|
||||||
|
|
||||||
# TODO handle join for non public rooms
|
# TODO handle join for non public rooms
|
||||||
if len(split_args) != 2:
|
if len(split_args) != 2:
|
||||||
message = ("{prefix}Error with command \"/invite\" (help on "
|
message = (
|
||||||
"command: /help invite)").format(
|
"{prefix}Error with command \"/invite\" (help on "
|
||||||
prefix=W.prefix("error"))
|
"command: /help invite)").format(prefix=W.prefix("error"))
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -270,10 +247,7 @@ def matrix_command_invite_cb(data, buffer, command):
|
||||||
room_id = key_from_value(server.buffers, buf)
|
room_id = key_from_value(server.buffers, buf)
|
||||||
|
|
||||||
message = MatrixInviteMessage(
|
message = MatrixInviteMessage(
|
||||||
server.client,
|
server.client, room_id=room_id, user_id=invitee)
|
||||||
room_id=room_id,
|
|
||||||
user_id=invitee
|
|
||||||
)
|
|
||||||
server.send_or_queue(message)
|
server.send_or_queue(message)
|
||||||
|
|
||||||
for server in SERVERS.values():
|
for server in SERVERS.values():
|
||||||
|
@ -288,28 +262,20 @@ def event_id_from_line(buf, target_number):
|
||||||
# type: (weechat.buffer, int) -> str
|
# type: (weechat.buffer, int) -> str
|
||||||
own_lines = W.hdata_pointer(W.hdata_get('buffer'), buf, 'own_lines')
|
own_lines = W.hdata_pointer(W.hdata_get('buffer'), buf, 'own_lines')
|
||||||
if own_lines:
|
if own_lines:
|
||||||
line = W.hdata_pointer(
|
line = W.hdata_pointer(W.hdata_get('lines'), own_lines, 'last_line')
|
||||||
W.hdata_get('lines'),
|
|
||||||
own_lines,
|
|
||||||
'last_line'
|
|
||||||
)
|
|
||||||
|
|
||||||
line_number = 1
|
line_number = 1
|
||||||
|
|
||||||
while line:
|
while line:
|
||||||
line_data = W.hdata_pointer(
|
line_data = W.hdata_pointer(W.hdata_get('line'), line, 'data')
|
||||||
W.hdata_get('line'),
|
|
||||||
line,
|
|
||||||
'data'
|
|
||||||
)
|
|
||||||
|
|
||||||
if line_data:
|
if line_data:
|
||||||
tags = tags_from_line_data(line_data)
|
tags = tags_from_line_data(line_data)
|
||||||
|
|
||||||
# Only count non redacted user messages
|
# Only count non redacted user messages
|
||||||
if ("matrix_message" in tags
|
if ("matrix_message" in tags and
|
||||||
and 'matrix_redacted' not in tags
|
'matrix_redacted' not in tags and
|
||||||
and "matrix_new_redacted" not in tags):
|
"matrix_new_redacted" not in tags):
|
||||||
|
|
||||||
if line_number == target_number:
|
if line_number == target_number:
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
|
@ -334,8 +300,8 @@ def matrix_redact_command_cb(data, buffer, args):
|
||||||
|
|
||||||
if not matches:
|
if not matches:
|
||||||
message = ("{prefix}matrix: Invalid command arguments (see "
|
message = ("{prefix}matrix: Invalid command arguments (see "
|
||||||
"the help for the command /help redact)").format(
|
"the help for the command /help redact)"
|
||||||
prefix=W.prefix("error"))
|
).format(prefix=W.prefix("error"))
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
return W.WEECHAT_RC_ERROR
|
return W.WEECHAT_RC_ERROR
|
||||||
|
|
||||||
|
@ -347,8 +313,7 @@ def matrix_redact_command_cb(data, buffer, args):
|
||||||
if not event_id:
|
if not event_id:
|
||||||
message = ("{prefix}matrix: No such message with number "
|
message = ("{prefix}matrix: No such message with number "
|
||||||
"{number} found").format(
|
"{number} found").format(
|
||||||
prefix=W.prefix("error"),
|
prefix=W.prefix("error"), number=line)
|
||||||
number=line)
|
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
return W.WEECHAT_RC_OK
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
@ -356,16 +321,15 @@ def matrix_redact_command_cb(data, buffer, args):
|
||||||
server.client,
|
server.client,
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
event_id=event_id,
|
event_id=event_id,
|
||||||
reason=reason
|
reason=reason)
|
||||||
)
|
|
||||||
server.send_or_queue(message)
|
server.send_or_queue(message)
|
||||||
|
|
||||||
return W.WEECHAT_RC_OK
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
elif buffer == server.server_buffer:
|
elif buffer == server.server_buffer:
|
||||||
message = ("{prefix}matrix: command \"redact\" must be "
|
message = ("{prefix}matrix: command \"redact\" must be "
|
||||||
"executed on a Matrix channel buffer").format(
|
"executed on a Matrix channel buffer"
|
||||||
prefix=W.prefix("error"))
|
).format(prefix=W.prefix("error"))
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
return W.WEECHAT_RC_OK
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
@ -384,15 +348,13 @@ def matrix_command_debug(args):
|
||||||
if debug_type in OPTIONS.debug:
|
if debug_type in OPTIONS.debug:
|
||||||
message = ("{prefix}matrix: Disabling matrix {t} "
|
message = ("{prefix}matrix: Disabling matrix {t} "
|
||||||
"debugging.").format(
|
"debugging.").format(
|
||||||
prefix=W.prefix("error"),
|
prefix=W.prefix("error"), t=debug_type)
|
||||||
t=debug_type)
|
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
OPTIONS.debug.remove(debug_type)
|
OPTIONS.debug.remove(debug_type)
|
||||||
else:
|
else:
|
||||||
message = ("{prefix}matrix: Enabling matrix {t} "
|
message = ("{prefix}matrix: Enabling matrix {t} "
|
||||||
"debugging.").format(
|
"debugging.").format(
|
||||||
prefix=W.prefix("error"),
|
prefix=W.prefix("error"), t=debug_type)
|
||||||
t=debug_type)
|
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
OPTIONS.debug.append(debug_type)
|
OPTIONS.debug.append(debug_type)
|
||||||
|
|
||||||
|
@ -406,8 +368,7 @@ def matrix_command_debug(args):
|
||||||
else:
|
else:
|
||||||
message = ("{prefix}matrix: Unknown matrix debug "
|
message = ("{prefix}matrix: Unknown matrix debug "
|
||||||
"type \"{t}\".").format(
|
"type \"{t}\".").format(
|
||||||
prefix=W.prefix("error"),
|
prefix=W.prefix("error"), t=command)
|
||||||
t=command)
|
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
|
|
||||||
|
|
||||||
|
@ -517,8 +478,7 @@ def matrix_command_help(args):
|
||||||
else:
|
else:
|
||||||
message = ("{prefix}matrix: No help available, \"{command}\" "
|
message = ("{prefix}matrix: No help available, \"{command}\" "
|
||||||
"is not a matrix command").format(
|
"is not a matrix command").format(
|
||||||
prefix=W.prefix("error"),
|
prefix=W.prefix("error"), command=command)
|
||||||
command=command)
|
|
||||||
|
|
||||||
W.prnt("", "")
|
W.prnt("", "")
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
|
@ -527,6 +487,7 @@ def matrix_command_help(args):
|
||||||
|
|
||||||
|
|
||||||
def matrix_server_command_listfull(args):
|
def matrix_server_command_listfull(args):
|
||||||
|
|
||||||
def get_value_string(value, default_value):
|
def get_value_string(value, default_value):
|
||||||
if value == default_value:
|
if value == default_value:
|
||||||
if not value:
|
if not value:
|
||||||
|
@ -691,11 +652,7 @@ def matrix_server_command_add(args):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
host, port = args[1], None
|
host, port = args[1], None
|
||||||
|
|
||||||
return_code = W.config_option_set(
|
return_code = W.config_option_set(server.options["address"], host, 1)
|
||||||
server.options["address"],
|
|
||||||
host,
|
|
||||||
1
|
|
||||||
)
|
|
||||||
|
|
||||||
if return_code == W.WEECHAT_CONFIG_OPTION_SET_ERROR:
|
if return_code == W.WEECHAT_CONFIG_OPTION_SET_ERROR:
|
||||||
remove_server(server)
|
remove_server(server)
|
||||||
|
@ -712,11 +669,7 @@ def matrix_server_command_add(args):
|
||||||
return
|
return
|
||||||
|
|
||||||
if port:
|
if port:
|
||||||
return_code = W.config_option_set(
|
return_code = W.config_option_set(server.options["port"], port, 1)
|
||||||
server.options["port"],
|
|
||||||
port,
|
|
||||||
1
|
|
||||||
)
|
|
||||||
if return_code == W.WEECHAT_CONFIG_OPTION_SET_ERROR:
|
if return_code == W.WEECHAT_CONFIG_OPTION_SET_ERROR:
|
||||||
remove_server(server)
|
remove_server(server)
|
||||||
message = ("{prefix}Failed to set port for server "
|
message = ("{prefix}Failed to set port for server "
|
||||||
|
@ -733,11 +686,7 @@ def matrix_server_command_add(args):
|
||||||
|
|
||||||
if len(args) >= 3:
|
if len(args) >= 3:
|
||||||
user = args[2]
|
user = args[2]
|
||||||
return_code = W.config_option_set(
|
return_code = W.config_option_set(server.options["username"], user, 1)
|
||||||
server.options["username"],
|
|
||||||
user,
|
|
||||||
1
|
|
||||||
)
|
|
||||||
|
|
||||||
if return_code == W.WEECHAT_CONFIG_OPTION_SET_ERROR:
|
if return_code == W.WEECHAT_CONFIG_OPTION_SET_ERROR:
|
||||||
remove_server(server)
|
remove_server(server)
|
||||||
|
@ -756,11 +705,8 @@ def matrix_server_command_add(args):
|
||||||
if len(args) == 4:
|
if len(args) == 4:
|
||||||
password = args[3]
|
password = args[3]
|
||||||
|
|
||||||
return_code = W.config_option_set(
|
return_code = W.config_option_set(server.options["password"], password,
|
||||||
server.options["password"],
|
1)
|
||||||
password,
|
|
||||||
1
|
|
||||||
)
|
|
||||||
if return_code == W.WEECHAT_CONFIG_OPTION_SET_ERROR:
|
if return_code == W.WEECHAT_CONFIG_OPTION_SET_ERROR:
|
||||||
remove_server(server)
|
remove_server(server)
|
||||||
message = ("{prefix}Failed to set password for server "
|
message = ("{prefix}Failed to set password for server "
|
||||||
|
@ -783,14 +729,13 @@ def matrix_server_command_add(args):
|
||||||
|
|
||||||
|
|
||||||
def matrix_server_command(command, args):
|
def matrix_server_command(command, args):
|
||||||
|
|
||||||
def list_servers(_):
|
def list_servers(_):
|
||||||
if SERVERS:
|
if SERVERS:
|
||||||
W.prnt("", "\nAll matrix servers:")
|
W.prnt("", "\nAll matrix servers:")
|
||||||
for server in SERVERS:
|
for server in SERVERS:
|
||||||
W.prnt("", " {color}{server}".format(
|
W.prnt("", " {color}{server}".format(
|
||||||
color=W.color("chat_server"),
|
color=W.color("chat_server"), server=server))
|
||||||
server=server
|
|
||||||
))
|
|
||||||
|
|
||||||
# TODO the argument for list and listfull is used as a match word to
|
# TODO the argument for list and listfull is used as a match word to
|
||||||
# find/filter servers, we're currently match exactly to the whole name
|
# find/filter servers, we're currently match exactly to the whole name
|
||||||
|
@ -805,13 +750,13 @@ def matrix_server_command(command, args):
|
||||||
else:
|
else:
|
||||||
message = ("{prefix}matrix: Error: unknown matrix server command, "
|
message = ("{prefix}matrix: Error: unknown matrix server command, "
|
||||||
"\"{command}\" (type /matrix help server for help)").format(
|
"\"{command}\" (type /matrix help server for help)").format(
|
||||||
prefix=W.prefix("error"),
|
prefix=W.prefix("error"), command=command)
|
||||||
command=command)
|
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
|
|
||||||
|
|
||||||
@utf8_decode
|
@utf8_decode
|
||||||
def matrix_command_cb(data, buffer, args):
|
def matrix_command_cb(data, buffer, args):
|
||||||
|
|
||||||
def connect_server(args):
|
def connect_server(args):
|
||||||
for server_name in args:
|
for server_name in args:
|
||||||
if check_server_existence(server_name, SERVERS):
|
if check_server_existence(server_name, SERVERS):
|
||||||
|
@ -865,8 +810,7 @@ def matrix_command_cb(data, buffer, args):
|
||||||
else:
|
else:
|
||||||
message = ("{prefix}matrix: Error: unknown matrix command, "
|
message = ("{prefix}matrix: Error: unknown matrix command, "
|
||||||
"\"{command}\" (type /help matrix for help)").format(
|
"\"{command}\" (type /help matrix for help)").format(
|
||||||
prefix=W.prefix("error"),
|
prefix=W.prefix("error"), command=command)
|
||||||
command=command)
|
|
||||||
W.prnt("", message)
|
W.prnt("", message)
|
||||||
|
|
||||||
return W.WEECHAT_RC_OK
|
return W.WEECHAT_RC_OK
|
||||||
|
@ -917,18 +861,15 @@ def matrix_command_topic_cb(data, buffer, command):
|
||||||
return W.WEECHAT_RC_OK_EAT
|
return W.WEECHAT_RC_OK_EAT
|
||||||
|
|
||||||
message = MatrixTopicMessage(
|
message = MatrixTopicMessage(
|
||||||
server.client,
|
server.client, room_id=room_id, topic=topic)
|
||||||
room_id=room_id,
|
|
||||||
topic=topic
|
|
||||||
)
|
|
||||||
server.send_or_queue(message)
|
server.send_or_queue(message)
|
||||||
|
|
||||||
return W.WEECHAT_RC_OK_EAT
|
return W.WEECHAT_RC_OK_EAT
|
||||||
|
|
||||||
elif buffer == server.server_buffer:
|
elif buffer == server.server_buffer:
|
||||||
message = ("{prefix}matrix: command \"topic\" must be "
|
message = ("{prefix}matrix: command \"topic\" must be "
|
||||||
"executed on a Matrix channel buffer").format(
|
"executed on a Matrix channel buffer"
|
||||||
prefix=W.prefix("error"))
|
).format(prefix=W.prefix("error"))
|
||||||
W.prnt(buffer, message)
|
W.prnt(buffer, message)
|
||||||
return W.WEECHAT_RC_OK_EAT
|
return W.WEECHAT_RC_OK_EAT
|
||||||
|
|
||||||
|
|
|
@ -23,16 +23,13 @@ from matrix.utils import tags_from_line_data
|
||||||
|
|
||||||
def add_servers_to_completion(completion):
|
def add_servers_to_completion(completion):
|
||||||
for server_name in SERVERS:
|
for server_name in SERVERS:
|
||||||
W.hook_completion_list_add(
|
W.hook_completion_list_add(completion, server_name, 0,
|
||||||
completion,
|
W.WEECHAT_LIST_POS_SORT)
|
||||||
server_name,
|
|
||||||
0,
|
|
||||||
W.WEECHAT_LIST_POS_SORT
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@utf8_decode
|
@utf8_decode
|
||||||
def matrix_server_command_completion_cb(data, completion_item, buffer, completion):
|
def matrix_server_command_completion_cb(data, completion_item, buffer,
|
||||||
|
completion):
|
||||||
buffer_input = W.buffer_get_string(buffer, "input").split()
|
buffer_input = W.buffer_get_string(buffer, "input").split()
|
||||||
|
|
||||||
args = buffer_input[1:]
|
args = buffer_input[1:]
|
||||||
|
@ -40,12 +37,8 @@ def matrix_server_command_completion_cb(data, completion_item, buffer, completio
|
||||||
|
|
||||||
def complete_commands():
|
def complete_commands():
|
||||||
for command in commands:
|
for command in commands:
|
||||||
W.hook_completion_list_add(
|
W.hook_completion_list_add(completion, command, 0,
|
||||||
completion,
|
W.WEECHAT_LIST_POS_SORT)
|
||||||
command,
|
|
||||||
0,
|
|
||||||
W.WEECHAT_LIST_POS_SORT
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
complete_commands()
|
complete_commands()
|
||||||
|
@ -74,17 +67,9 @@ def matrix_server_completion_cb(data, completion_item, buffer, completion):
|
||||||
@utf8_decode
|
@utf8_decode
|
||||||
def matrix_command_completion_cb(data, completion_item, buffer, completion):
|
def matrix_command_completion_cb(data, completion_item, buffer, completion):
|
||||||
for command in [
|
for command in [
|
||||||
"connect",
|
"connect", "disconnect", "reconnect", "server", "help", "debug"
|
||||||
"disconnect",
|
|
||||||
"reconnect",
|
|
||||||
"server",
|
|
||||||
"help",
|
|
||||||
"debug"
|
|
||||||
]:
|
]:
|
||||||
W.hook_completion_list_add(
|
W.hook_completion_list_add(completion, command, 0,
|
||||||
completion,
|
|
||||||
command,
|
|
||||||
0,
|
|
||||||
W.WEECHAT_LIST_POS_SORT)
|
W.WEECHAT_LIST_POS_SORT)
|
||||||
return W.WEECHAT_RC_OK
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
@ -92,10 +77,7 @@ def matrix_command_completion_cb(data, completion_item, buffer, completion):
|
||||||
@utf8_decode
|
@utf8_decode
|
||||||
def matrix_debug_completion_cb(data, completion_item, buffer, completion):
|
def matrix_debug_completion_cb(data, completion_item, buffer, completion):
|
||||||
for debug_type in ["messaging", "network", "timing"]:
|
for debug_type in ["messaging", "network", "timing"]:
|
||||||
W.hook_completion_list_add(
|
W.hook_completion_list_add(completion, debug_type, 0,
|
||||||
completion,
|
|
||||||
debug_type,
|
|
||||||
0,
|
|
||||||
W.WEECHAT_LIST_POS_SORT)
|
W.WEECHAT_LIST_POS_SORT)
|
||||||
return W.WEECHAT_RC_OK
|
return W.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
@ -104,45 +86,30 @@ def matrix_debug_completion_cb(data, completion_item, buffer, completion):
|
||||||
def matrix_message_completion_cb(data, completion_item, buffer, completion):
|
def matrix_message_completion_cb(data, completion_item, buffer, completion):
|
||||||
own_lines = W.hdata_pointer(W.hdata_get('buffer'), buffer, 'own_lines')
|
own_lines = W.hdata_pointer(W.hdata_get('buffer'), buffer, 'own_lines')
|
||||||
if own_lines:
|
if own_lines:
|
||||||
line = W.hdata_pointer(
|
line = W.hdata_pointer(W.hdata_get('lines'), own_lines, 'last_line')
|
||||||
W.hdata_get('lines'),
|
|
||||||
own_lines,
|
|
||||||
'last_line'
|
|
||||||
)
|
|
||||||
|
|
||||||
line_number = 1
|
line_number = 1
|
||||||
|
|
||||||
while line:
|
while line:
|
||||||
line_data = W.hdata_pointer(
|
line_data = W.hdata_pointer(W.hdata_get('line'), line, 'data')
|
||||||
W.hdata_get('line'),
|
|
||||||
line,
|
|
||||||
'data'
|
|
||||||
)
|
|
||||||
|
|
||||||
if line_data:
|
if line_data:
|
||||||
message = W.hdata_string(W.hdata_get('line_data'), line_data,
|
message = W.hdata_string(
|
||||||
'message')
|
W.hdata_get('line_data'), line_data, 'message')
|
||||||
|
|
||||||
tags = tags_from_line_data(line_data)
|
tags = tags_from_line_data(line_data)
|
||||||
|
|
||||||
# Only add non redacted user messages to the completion
|
# Only add non redacted user messages to the completion
|
||||||
if (message
|
if (message and 'matrix_message' in tags and
|
||||||
and 'matrix_message' in tags
|
'matrix_redacted' not in tags):
|
||||||
and 'matrix_redacted' not in tags):
|
|
||||||
|
|
||||||
if len(message) > OPTIONS.redaction_comp_len + 2:
|
if len(message) > OPTIONS.redaction_comp_len + 2:
|
||||||
message = (
|
message = (message[:OPTIONS.redaction_comp_len] + '..')
|
||||||
message[:OPTIONS.redaction_comp_len]
|
|
||||||
+ '..')
|
|
||||||
|
|
||||||
item = ("{number}:\"{message}\"").format(
|
item = ("{number}:\"{message}\"").format(
|
||||||
number=line_number,
|
number=line_number, message=message)
|
||||||
message=message)
|
|
||||||
|
|
||||||
W.hook_completion_list_add(
|
W.hook_completion_list_add(completion, item, 0,
|
||||||
completion,
|
|
||||||
item,
|
|
||||||
0,
|
|
||||||
W.WEECHAT_LIST_POS_END)
|
W.WEECHAT_LIST_POS_END)
|
||||||
line_number += 1
|
line_number += 1
|
||||||
|
|
||||||
|
@ -152,37 +119,17 @@ def matrix_message_completion_cb(data, completion_item, buffer, completion):
|
||||||
|
|
||||||
|
|
||||||
def init_completion():
|
def init_completion():
|
||||||
W.hook_completion(
|
W.hook_completion("matrix_server_commands", "Matrix server completion",
|
||||||
"matrix_server_commands",
|
"matrix_server_command_completion_cb", "")
|
||||||
"Matrix server completion",
|
|
||||||
"matrix_server_command_completion_cb",
|
|
||||||
""
|
|
||||||
)
|
|
||||||
|
|
||||||
W.hook_completion(
|
W.hook_completion("matrix_servers", "Matrix server completion",
|
||||||
"matrix_servers",
|
"matrix_server_completion_cb", "")
|
||||||
"Matrix server completion",
|
|
||||||
"matrix_server_completion_cb",
|
|
||||||
""
|
|
||||||
)
|
|
||||||
|
|
||||||
W.hook_completion(
|
W.hook_completion("matrix_commands", "Matrix command completion",
|
||||||
"matrix_commands",
|
"matrix_command_completion_cb", "")
|
||||||
"Matrix command completion",
|
|
||||||
"matrix_command_completion_cb",
|
|
||||||
""
|
|
||||||
)
|
|
||||||
|
|
||||||
W.hook_completion(
|
W.hook_completion("matrix_messages", "Matrix message completion",
|
||||||
"matrix_messages",
|
"matrix_message_completion_cb", "")
|
||||||
"Matrix message completion",
|
|
||||||
"matrix_message_completion_cb",
|
|
||||||
""
|
|
||||||
)
|
|
||||||
|
|
||||||
W.hook_completion(
|
W.hook_completion("matrix_debug_types", "Matrix debugging type completion",
|
||||||
"matrix_debug_types",
|
"matrix_debug_completion_cb", "")
|
||||||
"Matrix debugging type completion",
|
|
||||||
"matrix_debug_completion_cb",
|
|
||||||
""
|
|
||||||
)
|
|
||||||
|
|
|
@ -16,11 +16,7 @@
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from matrix.plugin_options import (
|
from matrix.plugin_options import (Option, RedactType, ServerBufferType)
|
||||||
Option,
|
|
||||||
RedactType,
|
|
||||||
ServerBufferType
|
|
||||||
)
|
|
||||||
|
|
||||||
import matrix.globals
|
import matrix.globals
|
||||||
from matrix.globals import W, OPTIONS, SERVERS
|
from matrix.globals import W, OPTIONS, SERVERS
|
||||||
|
@ -42,8 +38,7 @@ def matrix_config_change_cb(data, option):
|
||||||
OPTIONS.redaction_type = RedactType(W.config_integer(option))
|
OPTIONS.redaction_type = RedactType(W.config_integer(option))
|
||||||
|
|
||||||
elif option_name == "server_buffer":
|
elif option_name == "server_buffer":
|
||||||
OPTIONS.look_server_buf = ServerBufferType(
|
OPTIONS.look_server_buf = ServerBufferType(W.config_integer(option))
|
||||||
W.config_integer(option))
|
|
||||||
for server in SERVERS.values():
|
for server in SERVERS.values():
|
||||||
if server.server_buffer:
|
if server.server_buffer:
|
||||||
server_buffer_merge(server.server_buffer)
|
server_buffer_merge(server.server_buffer)
|
||||||
|
@ -70,56 +65,31 @@ def matrix_config_change_cb(data, option):
|
||||||
|
|
||||||
def matrix_config_init(config_file):
|
def matrix_config_init(config_file):
|
||||||
look_options = [
|
look_options = [
|
||||||
Option(
|
Option("redactions", "integer", "strikethrough|notice|delete", 0, 0,
|
||||||
"redactions", "integer",
|
|
||||||
"strikethrough|notice|delete", 0, 0,
|
|
||||||
"strikethrough",
|
"strikethrough",
|
||||||
(
|
("Only notice redactions, strike through or delete "
|
||||||
"Only notice redactions, strike through or delete "
|
"redacted messages")),
|
||||||
"redacted messages"
|
Option("server_buffer", "integer",
|
||||||
)
|
"merge_with_core|merge_without_core|independent", 0, 0,
|
||||||
),
|
"merge_with_core", "Merge server buffers")
|
||||||
Option(
|
|
||||||
"server_buffer", "integer",
|
|
||||||
"merge_with_core|merge_without_core|independent",
|
|
||||||
0, 0, "merge_with_core", "Merge server buffers"
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
network_options = [
|
network_options = [
|
||||||
Option(
|
Option("max_initial_sync_events", "integer", "", 1, 10000, "30",
|
||||||
"max_initial_sync_events", "integer",
|
("How many events to fetch during the initial sync")),
|
||||||
"", 1, 10000,
|
Option("max_backlog_sync_events", "integer", "", 1, 100, "10",
|
||||||
"30",
|
("How many events to fetch during backlog fetching")),
|
||||||
(
|
Option("fetch_backlog_on_pgup", "boolean", "", 0, 0, "on",
|
||||||
"How many events to fetch during the initial sync"
|
("Fetch messages in the backlog on a window page up event"))
|
||||||
)
|
|
||||||
),
|
|
||||||
Option(
|
|
||||||
"max_backlog_sync_events", "integer",
|
|
||||||
"", 1, 100,
|
|
||||||
"10",
|
|
||||||
(
|
|
||||||
"How many events to fetch during backlog fetching"
|
|
||||||
)
|
|
||||||
),
|
|
||||||
Option(
|
|
||||||
"fetch_backlog_on_pgup", "boolean",
|
|
||||||
"", 0, 0,
|
|
||||||
"on",
|
|
||||||
(
|
|
||||||
"Fetch messages in the backlog on a window page up event"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def add_global_options(section, options):
|
def add_global_options(section, options):
|
||||||
for option in options:
|
for option in options:
|
||||||
OPTIONS.options[option.name] = W.config_new_option(
|
OPTIONS.options[option.name] = W.config_new_option(
|
||||||
config_file, section, option.name,
|
config_file, section, option.name, option.type,
|
||||||
option.type, option.description, option.string_values,
|
option.description, option.string_values, option.min,
|
||||||
option.min, option.max, option.value, option.value, 0, "",
|
option.max, option.value, option.value, 0, "", "",
|
||||||
"", "matrix_config_change_cb", "", "", "")
|
"matrix_config_change_cb", "", "", "")
|
||||||
|
|
||||||
section = W.config_new_section(config_file, "color", 0, 0, "", "", "", "",
|
section = W.config_new_section(config_file, "color", 0, 0, "", "", "", "",
|
||||||
"", "", "", "", "", "")
|
"", "", "", "", "", "")
|
||||||
|
@ -131,19 +101,14 @@ def matrix_config_init(config_file):
|
||||||
|
|
||||||
add_global_options(section, look_options)
|
add_global_options(section, look_options)
|
||||||
|
|
||||||
section = W.config_new_section(config_file, "network", 0, 0, "", "", "",
|
section = W.config_new_section(config_file, "network", 0, 0, "", "", "", "",
|
||||||
"", "", "", "", "", "", "")
|
"", "", "", "", "", "")
|
||||||
|
|
||||||
add_global_options(section, network_options)
|
add_global_options(section, network_options)
|
||||||
|
|
||||||
W.config_new_section(
|
W.config_new_section(
|
||||||
config_file, "server",
|
config_file, "server", 0, 0, "matrix_config_server_read_cb", "",
|
||||||
0, 0,
|
"matrix_config_server_write_cb", "", "", "", "", "", "", "")
|
||||||
"matrix_config_server_read_cb",
|
|
||||||
"",
|
|
||||||
"matrix_config_server_write_cb",
|
|
||||||
"", "", "", "", "", "", ""
|
|
||||||
)
|
|
||||||
|
|
||||||
return config_file
|
return config_file
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ from matrix.plugin_options import PluginOptions
|
||||||
|
|
||||||
import weechat
|
import weechat
|
||||||
|
|
||||||
|
|
||||||
W = weechat if sys.hexversion >= 0x3000000 else WeechatWrapper(weechat)
|
W = weechat if sys.hexversion >= 0x3000000 else WeechatWrapper(weechat)
|
||||||
|
|
||||||
OPTIONS = PluginOptions() # type: PluginOptions
|
OPTIONS = PluginOptions() # type: PluginOptions
|
||||||
|
|
|
@ -18,6 +18,7 @@ from __future__ import unicode_literals
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from enum import Enum, unique
|
from enum import Enum, unique
|
||||||
|
|
||||||
|
|
||||||
@unique
|
@unique
|
||||||
class RedactType(Enum):
|
class RedactType(Enum):
|
||||||
STRIKETHROUGH = 0
|
STRIKETHROUGH = 0
|
||||||
|
@ -40,19 +41,12 @@ class DebugType(Enum):
|
||||||
|
|
||||||
|
|
||||||
Option = namedtuple(
|
Option = namedtuple(
|
||||||
'Option', [
|
'Option',
|
||||||
'name',
|
['name', 'type', 'string_values', 'min', 'max', 'value', 'description'])
|
||||||
'type',
|
|
||||||
'string_values',
|
|
||||||
'min',
|
|
||||||
'max',
|
|
||||||
'value',
|
|
||||||
'description'
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PluginOptions:
|
class PluginOptions:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.redaction_type = RedactType.STRIKETHROUGH # type: RedactType
|
self.redaction_type = RedactType.STRIKETHROUGH # type: RedactType
|
||||||
self.look_server_buf = ServerBufferType.MERGE_CORE # type: ServerBufferType
|
self.look_server_buf = ServerBufferType.MERGE_CORE # type: ServerBufferType
|
||||||
|
|
|
@ -31,7 +31,6 @@ from builtins import bytes, str
|
||||||
from collections import Mapping, Iterable
|
from collections import Mapping, Iterable
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
|
|
||||||
# These functions were written by Trygve Aaberge for wee-slack and are under a
|
# These functions were written by Trygve Aaberge for wee-slack and are under a
|
||||||
# MIT License.
|
# MIT License.
|
||||||
# More info can be found in the wee-slack repository under the commit:
|
# More info can be found in the wee-slack repository under the commit:
|
||||||
|
@ -40,17 +39,20 @@ from functools import wraps
|
||||||
|
|
||||||
|
|
||||||
class WeechatWrapper(object):
|
class WeechatWrapper(object):
|
||||||
|
|
||||||
def __init__(self, wrapped_class):
|
def __init__(self, wrapped_class):
|
||||||
self.wrapped_class = wrapped_class
|
self.wrapped_class = wrapped_class
|
||||||
|
|
||||||
# Helper method used to encode/decode method calls.
|
# Helper method used to encode/decode method calls.
|
||||||
def wrap_for_utf8(self, method):
|
def wrap_for_utf8(self, method):
|
||||||
|
|
||||||
def hooked(*args, **kwargs):
|
def hooked(*args, **kwargs):
|
||||||
result = method(*encode_to_utf8(args), **encode_to_utf8(kwargs))
|
result = method(*encode_to_utf8(args), **encode_to_utf8(kwargs))
|
||||||
# Prevent wrapped_class from becoming unwrapped
|
# Prevent wrapped_class from becoming unwrapped
|
||||||
if result == self.wrapped_class:
|
if result == self.wrapped_class:
|
||||||
return self
|
return self
|
||||||
return decode_from_utf8(result)
|
return decode_from_utf8(result)
|
||||||
|
|
||||||
return hooked
|
return hooked
|
||||||
|
|
||||||
# Encode and decode everything sent to/received from weechat. We use the
|
# Encode and decode everything sent to/received from weechat. We use the
|
||||||
|
@ -67,11 +69,7 @@ class WeechatWrapper(object):
|
||||||
def prnt_date_tags(self, buffer, date, tags, message):
|
def prnt_date_tags(self, buffer, date, tags, message):
|
||||||
message = message.replace("\n", "\n \t")
|
message = message.replace("\n", "\n \t")
|
||||||
return self.wrap_for_utf8(self.wrapped_class.prnt_date_tags)(
|
return self.wrap_for_utf8(self.wrapped_class.prnt_date_tags)(
|
||||||
buffer,
|
buffer, date, tags, message)
|
||||||
date,
|
|
||||||
tags,
|
|
||||||
message
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def utf8_decode(function):
|
def utf8_decode(function):
|
||||||
|
@ -79,6 +77,7 @@ def utf8_decode(function):
|
||||||
Decode all arguments from byte strings to unicode strings. Use this for
|
Decode all arguments from byte strings to unicode strings. Use this for
|
||||||
functions called from outside of this script, e.g. callbacks from weechat.
|
functions called from outside of this script, e.g. callbacks from weechat.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@wraps(function)
|
@wraps(function)
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
|
|
||||||
|
@ -87,6 +86,7 @@ def utf8_decode(function):
|
||||||
return function(*args, **kwargs)
|
return function(*args, **kwargs)
|
||||||
|
|
||||||
return function(*decode_from_utf8(args), **decode_from_utf8(kwargs))
|
return function(*decode_from_utf8(args), **decode_from_utf8(kwargs))
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,29 +44,21 @@ def server_buffer_prnt(server, string):
|
||||||
def tags_from_line_data(line_data):
|
def tags_from_line_data(line_data):
|
||||||
# type: (weechat.hdata) -> List[str]
|
# type: (weechat.hdata) -> List[str]
|
||||||
tags_count = W.hdata_get_var_array_size(
|
tags_count = W.hdata_get_var_array_size(
|
||||||
W.hdata_get('line_data'),
|
W.hdata_get('line_data'), line_data, 'tags_array')
|
||||||
line_data,
|
|
||||||
'tags_array')
|
|
||||||
|
|
||||||
tags = [
|
tags = [
|
||||||
W.hdata_string(
|
W.hdata_string(
|
||||||
W.hdata_get('line_data'),
|
W.hdata_get('line_data'), line_data, '%d|tags_array' % i)
|
||||||
line_data,
|
for i in range(tags_count)
|
||||||
'%d|tags_array' % i
|
]
|
||||||
) for i in range(tags_count)]
|
|
||||||
|
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
|
||||||
def create_server_buffer(server):
|
def create_server_buffer(server):
|
||||||
# type: (MatrixServer) -> None
|
# type: (MatrixServer) -> None
|
||||||
server.server_buffer = W.buffer_new(
|
server.server_buffer = W.buffer_new(server.name, "server_buffer_cb",
|
||||||
server.name,
|
server.name, "", "")
|
||||||
"server_buffer_cb",
|
|
||||||
server.name,
|
|
||||||
"",
|
|
||||||
""
|
|
||||||
)
|
|
||||||
|
|
||||||
server_buffer_set_title(server)
|
server_buffer_set_title(server)
|
||||||
W.buffer_set(server.server_buffer, "localvar_set_type", 'server')
|
W.buffer_set(server.server_buffer, "localvar_set_type", 'server')
|
||||||
|
@ -107,9 +99,7 @@ def server_buffer_set_title(server):
|
||||||
ip_string = ""
|
ip_string = ""
|
||||||
|
|
||||||
title = ("Matrix: {address}:{port}{ip}").format(
|
title = ("Matrix: {address}:{port}{ip}").format(
|
||||||
address=server.address,
|
address=server.address, port=server.port, ip=ip_string)
|
||||||
port=server.port,
|
|
||||||
ip=ip_string)
|
|
||||||
|
|
||||||
W.buffer_set(server.server_buffer, "title", title)
|
W.buffer_set(server.server_buffer, "title", title)
|
||||||
|
|
||||||
|
@ -155,17 +145,9 @@ def sender_to_nick_and_color(room, sender):
|
||||||
|
|
||||||
def tags_for_message(message_type):
|
def tags_for_message(message_type):
|
||||||
default_tags = {
|
default_tags = {
|
||||||
"message": [
|
"message": ["matrix_message", "notify_message", "log1"],
|
||||||
"matrix_message",
|
"backlog":
|
||||||
"notify_message",
|
["matrix_message", "notify_message", "no_log", "no_highlight"]
|
||||||
"log1"
|
|
||||||
],
|
|
||||||
"backlog": [
|
|
||||||
"matrix_message",
|
|
||||||
"notify_message",
|
|
||||||
"no_log",
|
|
||||||
"no_highlight"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return default_tags[message_type]
|
return default_tags[message_type]
|
||||||
|
|
Loading…
Add table
Reference in a new issue