Add missing files.
Those got forgotten while splitting functions out into different files.
This commit is contained in:
parent
0fbecf6bdb
commit
ad5472d5f2
2 changed files with 256 additions and 0 deletions
188
matrix/completion.py
Normal file
188
matrix/completion.py
Normal file
|
@ -0,0 +1,188 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright © 2018 Damir Jelić <poljar@termina.org.uk>
|
||||
#
|
||||
# Permission to use, copy, modify, and/or distribute this software for
|
||||
# any purpose with or without fee is hereby granted, provided that the
|
||||
# above copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
||||
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
||||
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from matrix.utf import utf8_decode
|
||||
from matrix.globals import W, SERVERS, OPTIONS
|
||||
from matrix.utils import tags_from_line_data
|
||||
|
||||
|
||||
def add_servers_to_completion(completion):
|
||||
for server_name in SERVERS:
|
||||
W.hook_completion_list_add(
|
||||
completion,
|
||||
server_name,
|
||||
0,
|
||||
W.WEECHAT_LIST_POS_SORT
|
||||
)
|
||||
|
||||
|
||||
@utf8_decode
|
||||
def server_command_completion_cb(data, completion_item, buffer, completion):
|
||||
buffer_input = W.buffer_get_string(buffer, "input").split()
|
||||
|
||||
args = buffer_input[1:]
|
||||
commands = ['add', 'delete', 'list', 'listfull']
|
||||
|
||||
def complete_commands():
|
||||
for command in commands:
|
||||
W.hook_completion_list_add(
|
||||
completion,
|
||||
command,
|
||||
0,
|
||||
W.WEECHAT_LIST_POS_SORT
|
||||
)
|
||||
|
||||
if len(args) == 1:
|
||||
complete_commands()
|
||||
|
||||
elif len(args) == 2:
|
||||
if args[1] not in commands:
|
||||
complete_commands()
|
||||
else:
|
||||
if args[1] == 'delete' or args[1] == 'listfull':
|
||||
add_servers_to_completion(completion)
|
||||
|
||||
elif len(args) == 3:
|
||||
if args[1] == 'delete' or args[1] == 'listfull':
|
||||
if args[2] not in SERVERS:
|
||||
add_servers_to_completion(completion)
|
||||
|
||||
return W.WEECHAT_RC_OK
|
||||
|
||||
|
||||
@utf8_decode
|
||||
def matrix_server_completion_cb(data, completion_item, buffer, completion):
|
||||
add_servers_to_completion(completion)
|
||||
return W.WEECHAT_RC_OK
|
||||
|
||||
|
||||
@utf8_decode
|
||||
def matrix_command_completion_cb(data, completion_item, buffer, completion):
|
||||
for command in [
|
||||
"connect",
|
||||
"disconnect",
|
||||
"reconnect",
|
||||
"server",
|
||||
"help",
|
||||
"debug"
|
||||
]:
|
||||
W.hook_completion_list_add(
|
||||
completion,
|
||||
command,
|
||||
0,
|
||||
W.WEECHAT_LIST_POS_SORT)
|
||||
return W.WEECHAT_RC_OK
|
||||
|
||||
|
||||
@utf8_decode
|
||||
def matrix_debug_completion_cb(data, completion_item, buffer, completion):
|
||||
for debug_type in ["messaging", "network", "timing"]:
|
||||
W.hook_completion_list_add(
|
||||
completion,
|
||||
debug_type,
|
||||
0,
|
||||
W.WEECHAT_LIST_POS_SORT)
|
||||
return W.WEECHAT_RC_OK
|
||||
|
||||
|
||||
@utf8_decode
|
||||
def matrix_message_completion_cb(data, completion_item, buffer, completion):
|
||||
own_lines = W.hdata_pointer(W.hdata_get('buffer'), buffer, 'own_lines')
|
||||
if own_lines:
|
||||
line = W.hdata_pointer(
|
||||
W.hdata_get('lines'),
|
||||
own_lines,
|
||||
'last_line'
|
||||
)
|
||||
|
||||
line_number = 1
|
||||
|
||||
while line:
|
||||
line_data = W.hdata_pointer(
|
||||
W.hdata_get('line'),
|
||||
line,
|
||||
'data'
|
||||
)
|
||||
|
||||
if line_data:
|
||||
message = W.hdata_string(W.hdata_get('line_data'), line_data,
|
||||
'message')
|
||||
|
||||
tags = tags_from_line_data(line_data)
|
||||
|
||||
# Only add non redacted user messages to the completion
|
||||
if (message
|
||||
and 'matrix_message' in tags
|
||||
and 'matrix_redacted' not in tags):
|
||||
|
||||
if len(message) > OPTIONS.redaction_comp_len + 2:
|
||||
message = (
|
||||
message[:OPTIONS.redaction_comp_len]
|
||||
+ '..')
|
||||
|
||||
item = ("{number}:\"{message}\"").format(
|
||||
number=line_number,
|
||||
message=message)
|
||||
|
||||
W.hook_completion_list_add(
|
||||
completion,
|
||||
item,
|
||||
0,
|
||||
W.WEECHAT_LIST_POS_END)
|
||||
line_number += 1
|
||||
|
||||
line = W.hdata_move(W.hdata_get('line'), line, -1)
|
||||
|
||||
return W.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def init_completion():
|
||||
W.hook_completion(
|
||||
"matrix_server_commands",
|
||||
"Matrix server completion",
|
||||
"server_command_completion_cb",
|
||||
""
|
||||
)
|
||||
|
||||
W.hook_completion(
|
||||
"matrix_servers",
|
||||
"Matrix server completion",
|
||||
"matrix_server_completion_cb",
|
||||
""
|
||||
)
|
||||
|
||||
W.hook_completion(
|
||||
"matrix_commands",
|
||||
"Matrix command completion",
|
||||
"matrix_command_completion_cb",
|
||||
""
|
||||
)
|
||||
|
||||
W.hook_completion(
|
||||
"matrix_messages",
|
||||
"Matrix message completion",
|
||||
"matrix_message_completion_cb",
|
||||
""
|
||||
)
|
||||
|
||||
W.hook_completion(
|
||||
"matrix_debug_types",
|
||||
"Matrix debugging type completion",
|
||||
"matrix_debug_completion_cb",
|
||||
""
|
||||
)
|
68
matrix/plugin_options.py
Normal file
68
matrix/plugin_options.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright © 2018 Damir Jelić <poljar@termina.org.uk>
|
||||
#
|
||||
# Permission to use, copy, modify, and/or distribute this software for
|
||||
# any purpose with or without fee is hereby granted, provided that the
|
||||
# above copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
||||
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
||||
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from collections import namedtuple
|
||||
from enum import Enum, unique
|
||||
|
||||
@unique
|
||||
class RedactType(Enum):
|
||||
STRIKETHROUGH = 0
|
||||
NOTICE = 1
|
||||
DELETE = 2
|
||||
|
||||
|
||||
@unique
|
||||
class ServerBufferType(Enum):
|
||||
MERGE_CORE = 0
|
||||
MERGE = 1
|
||||
INDEPENDENT = 2
|
||||
|
||||
|
||||
@unique
|
||||
class DebugType(Enum):
|
||||
MESSAGING = 0
|
||||
NETWORK = 1
|
||||
TIMING = 2
|
||||
|
||||
|
||||
Option = namedtuple(
|
||||
'Option', [
|
||||
'name',
|
||||
'type',
|
||||
'string_values',
|
||||
'min',
|
||||
'max',
|
||||
'value',
|
||||
'description'
|
||||
])
|
||||
|
||||
|
||||
|
||||
class PluginOptions:
|
||||
def __init__(self):
|
||||
self.redaction_type = RedactType.STRIKETHROUGH # type: RedactType
|
||||
self.look_server_buf = ServerBufferType.MERGE_CORE # type: ServerBufferType
|
||||
|
||||
self.sync_limit = 30 # type: int
|
||||
self.backlog_limit = 10 # type: int
|
||||
self.enable_backlog = True # type: bool
|
||||
self.page_up_hook = None # type: weechat.hook
|
||||
|
||||
self.redaction_comp_len = 50 # type: int
|
||||
|
||||
self.options = dict() # type: Dict[str, weechat.config_option]
|
||||
self.debug = [] # type: List[DebugType]
|
Loading…
Add table
Reference in a new issue