Fix global config handling.
This commit is contained in:
parent
deea9d897e
commit
e02a731809
4 changed files with 31 additions and 28 deletions
18
main.py
18
main.py
|
@ -97,7 +97,9 @@ from matrix.config import (
|
|||
matrix_config_reload_cb
|
||||
)
|
||||
|
||||
from matrix.globals import W, OPTIONS, CONFIG, SERVERS
|
||||
import matrix.globals
|
||||
|
||||
from matrix.globals import W, OPTIONS, SERVERS
|
||||
|
||||
|
||||
WEECHAT_SCRIPT_NAME = "matrix" # type: str
|
||||
|
@ -438,7 +440,7 @@ def room_close_cb(data, buffer):
|
|||
|
||||
@utf8_decode
|
||||
def matrix_unload_cb():
|
||||
matrix_config_free(CONFIG)
|
||||
matrix_config_free(matrix.globals.CONFIG)
|
||||
return W.WEECHAT_RC_OK
|
||||
|
||||
|
||||
|
@ -458,14 +460,20 @@ if __name__ == "__main__":
|
|||
''):
|
||||
|
||||
# TODO if this fails we should abort and unload the script.
|
||||
CONFIG = matrix_config_init()
|
||||
matrix_config_read(CONFIG)
|
||||
|
||||
matrix.globals.CONFIG = W.config_new(
|
||||
"matrix",
|
||||
"matrix_config_reload_cb",
|
||||
""
|
||||
)
|
||||
matrix_config_init(matrix.globals.CONFIG)
|
||||
matrix_config_read(matrix.globals.CONFIG)
|
||||
|
||||
hook_commands()
|
||||
init_bar_items()
|
||||
init_completion()
|
||||
|
||||
if not SERVERS:
|
||||
create_default_server(CONFIG)
|
||||
create_default_server(matrix.globals.CONFIG)
|
||||
|
||||
autoconnect(SERVERS)
|
||||
|
|
|
@ -21,6 +21,7 @@ import re
|
|||
import time
|
||||
|
||||
import matrix.globals
|
||||
from matrix.globals import W, OPTIONS, SERVERS
|
||||
|
||||
from matrix.utf import utf8_decode
|
||||
from matrix.api import MatrixMessage, MessageType
|
||||
|
@ -29,11 +30,6 @@ from matrix.plugin_options import DebugType
|
|||
from matrix.server import MatrixServer
|
||||
|
||||
|
||||
W = matrix.globals.W
|
||||
GLOBAL_OPTIONS = matrix.globals.OPTIONS
|
||||
SERVERS = matrix.globals.SERVERS
|
||||
CONFIG = matrix.globals.CONFIG
|
||||
|
||||
def hook_commands():
|
||||
W.hook_command(
|
||||
# Command name and short description
|
||||
|
@ -98,7 +94,7 @@ def hook_commands():
|
|||
W.hook_command_run('/part', 'matrix_command_part_cb', '')
|
||||
W.hook_command_run('/invite', 'matrix_command_invite_cb', '')
|
||||
|
||||
if GLOBAL_OPTIONS.enable_backlog:
|
||||
if OPTIONS.enable_backlog:
|
||||
hook_page_up()
|
||||
|
||||
|
||||
|
@ -109,7 +105,7 @@ def matrix_fetch_old_messages(server, room_id):
|
|||
if not prev_batch:
|
||||
return
|
||||
|
||||
message = MatrixMessage(server, GLOBAL_OPTIONS, MessageType.ROOM_MSG,
|
||||
message = MatrixMessage(server, OPTIONS, MessageType.ROOM_MSG,
|
||||
room_id=room_id, extra_id=prev_batch)
|
||||
|
||||
server.send_or_queue(message)
|
||||
|
@ -127,7 +123,7 @@ def check_server_existence(server_name, servers):
|
|||
|
||||
|
||||
def hook_page_up():
|
||||
GLOBAL_OPTIONS.page_up_hook = W.hook_command_run(
|
||||
OPTIONS.page_up_hook = W.hook_command_run(
|
||||
'/window page_up',
|
||||
'matrix_command_pgup_cb',
|
||||
''
|
||||
|
@ -186,7 +182,7 @@ def matrix_command_join_cb(data, buffer, command):
|
|||
_, room_id = split_args
|
||||
message = MatrixMessage(
|
||||
server,
|
||||
GLOBAL_OPTIONS,
|
||||
OPTIONS,
|
||||
MessageType.JOIN,
|
||||
room_id=room_id
|
||||
)
|
||||
|
@ -227,7 +223,7 @@ def matrix_command_part_cb(data, buffer, command):
|
|||
for room_id in rooms:
|
||||
message = MatrixMessage(
|
||||
server,
|
||||
GLOBAL_OPTIONS,
|
||||
OPTIONS,
|
||||
MessageType.PART,
|
||||
room_id=room_id
|
||||
)
|
||||
|
@ -264,7 +260,7 @@ def matrix_command_invite_cb(data, buffer, command):
|
|||
|
||||
message = MatrixMessage(
|
||||
server,
|
||||
GLOBAL_OPTIONS,
|
||||
OPTIONS,
|
||||
MessageType.INVITE,
|
||||
room_id=room_id,
|
||||
data=body
|
||||
|
@ -354,7 +350,7 @@ def matrix_redact_command_cb(data, buffer, args):
|
|||
|
||||
message = MatrixMessage(
|
||||
server,
|
||||
GLOBAL_OPTIONS,
|
||||
OPTIONS,
|
||||
MessageType.REDACT,
|
||||
data=body,
|
||||
room_id=room_id,
|
||||
|
@ -383,20 +379,20 @@ def matrix_command_debug(args):
|
|||
return
|
||||
|
||||
def toggle_debug(debug_type):
|
||||
if debug_type in GLOBAL_OPTIONS.debug:
|
||||
if debug_type in OPTIONS.debug:
|
||||
message = ("{prefix}matrix: Disabling matrix {t} "
|
||||
"debugging.").format(
|
||||
prefix=W.prefix("error"),
|
||||
t=debug_type)
|
||||
W.prnt("", message)
|
||||
GLOBAL_OPTIONS.debug.remove(debug_type)
|
||||
OPTIONS.debug.remove(debug_type)
|
||||
else:
|
||||
message = ("{prefix}matrix: Enabling matrix {t} "
|
||||
"debugging.").format(
|
||||
prefix=W.prefix("error"),
|
||||
t=debug_type)
|
||||
W.prnt("", message)
|
||||
GLOBAL_OPTIONS.debug.append(debug_type)
|
||||
OPTIONS.debug.append(debug_type)
|
||||
|
||||
for command in args:
|
||||
if command == "network":
|
||||
|
@ -684,7 +680,7 @@ def matrix_server_command_add(args):
|
|||
W.prnt("", message)
|
||||
return
|
||||
|
||||
server = MatrixServer(args[0], W, CONFIG)
|
||||
server = MatrixServer(server_name, matrix.globals.CONFIG)
|
||||
SERVERS[server.name] = server
|
||||
|
||||
if len(args) >= 2:
|
||||
|
@ -922,7 +918,7 @@ def matrix_command_topic_cb(data, buffer, command):
|
|||
|
||||
message = MatrixMessage(
|
||||
server,
|
||||
GLOBAL_OPTIONS,
|
||||
OPTIONS,
|
||||
MessageType.STATE,
|
||||
data=body,
|
||||
room_id=room_id,
|
||||
|
|
|
@ -22,7 +22,8 @@ from matrix.plugin_options import (
|
|||
ServerBufferType
|
||||
)
|
||||
|
||||
from matrix.globals import W, OPTIONS, CONFIG, SERVERS
|
||||
import matrix.globals
|
||||
from matrix.globals import W, OPTIONS, SERVERS
|
||||
from matrix.utf import utf8_decode
|
||||
from matrix.utils import key_from_value, server_buffer_merge
|
||||
from matrix.commands import hook_page_up
|
||||
|
@ -57,7 +58,7 @@ def matrix_config_change_cb(data, option):
|
|||
|
||||
if OPTIONS.enable_backlog:
|
||||
if not OPTIONS.page_up_hook:
|
||||
hook_page_up(CONFIG)
|
||||
hook_page_up(matrix.globals.CONFIG)
|
||||
else:
|
||||
if OPTIONS.page_up_hook:
|
||||
W.unhook(OPTIONS.page_up_hook)
|
||||
|
@ -66,9 +67,7 @@ def matrix_config_change_cb(data, option):
|
|||
return 1
|
||||
|
||||
|
||||
def matrix_config_init():
|
||||
config_file = W.config_new("matrix", "matrix_config_reload_cb", "")
|
||||
|
||||
def matrix_config_init(config_file):
|
||||
look_options = [
|
||||
Option(
|
||||
"redactions", "integer",
|
||||
|
|
|
@ -477,7 +477,7 @@ def matrix_timer_cb(server_name, remaining_calls):
|
|||
|
||||
|
||||
def create_default_server(config_file):
|
||||
server = MatrixServer('matrix.org', W, config_file)
|
||||
server = MatrixServer('matrix.org', config_file)
|
||||
SERVERS[server.name] = server
|
||||
|
||||
W.config_option_set(server.options["address"], "matrix.org", 1)
|
||||
|
|
Loading…
Reference in a new issue