mirror of
https://github.com/gryf/weechat-xmpp.git
synced 2025-12-19 20:38:07 +01:00
[mod] autopep8
This commit is contained in:
69
jabber.py
69
jabber.py
@@ -262,6 +262,7 @@ jabber_jid_aliases = {} # { 'alias1': 'jid1', 'alias2': 'jid2', ...
|
||||
|
||||
# =================================[ config ]=================================
|
||||
|
||||
|
||||
def jabber_config_init():
|
||||
""" Initialize config file: create sections and options in memory. """
|
||||
global jabber_config_file, jabber_config_section
|
||||
@@ -309,10 +310,12 @@ def jabber_config_init():
|
||||
weechat.config_free(jabber_config_file)
|
||||
return
|
||||
|
||||
|
||||
def jabber_config_reload_cb(data, config_file):
|
||||
""" Reload config file. """
|
||||
return weechat.config_reload(config_file)
|
||||
|
||||
|
||||
def jabber_config_server_read_cb(data, config_file, section, option_name, value):
|
||||
""" Read server option in config file. """
|
||||
global jabber_servers
|
||||
@@ -327,6 +330,7 @@ def jabber_config_server_read_cb(data, config_file, section, option_name, value)
|
||||
rc = weechat.config_option_set(server.options[items[1]], value, 1)
|
||||
return rc
|
||||
|
||||
|
||||
def jabber_config_server_write_cb(data, config_file, section_name):
|
||||
""" Write server section in config file. """
|
||||
global jabber_servers
|
||||
@@ -336,6 +340,7 @@ def jabber_config_server_write_cb(data, config_file, section_name):
|
||||
weechat.config_write_option(config_file, option)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def jabber_config_jid_aliases_read_cb(data, config_file, section, option_name, value):
|
||||
""" Read jid_aliases option in config file. """
|
||||
global jabber_jid_aliases
|
||||
@@ -348,6 +353,7 @@ def jabber_config_jid_aliases_read_cb(data, config_file, section, option_name, v
|
||||
return weechat.WEECHAT_CONFIG_OPTION_SET_ERROR
|
||||
return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED
|
||||
|
||||
|
||||
def jabber_config_jid_aliases_write_cb(data, config_file, section_name):
|
||||
""" Write jid_aliases section in config file. """
|
||||
global jabber_jid_aliases
|
||||
@@ -356,16 +362,19 @@ def jabber_config_jid_aliases_write_cb(data, config_file, section_name):
|
||||
weechat.config_write_line(config_file, alias, jid)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def jabber_config_read():
|
||||
""" Read jabber config file (jabber.conf). """
|
||||
global jabber_config_file
|
||||
return weechat.config_read(jabber_config_file)
|
||||
|
||||
|
||||
def jabber_config_write():
|
||||
""" Write jabber config file (jabber.conf). """
|
||||
global jabber_config_file
|
||||
return weechat.config_write(jabber_config_file)
|
||||
|
||||
|
||||
def jabber_debug_enabled():
|
||||
""" Return True if debug is enabled. """
|
||||
global jabber_config_options
|
||||
@@ -373,6 +382,7 @@ def jabber_debug_enabled():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def jabber_config_color(color):
|
||||
""" Return color code for a jabber color option. """
|
||||
global jabber_config_option
|
||||
@@ -380,6 +390,7 @@ def jabber_config_color(color):
|
||||
return weechat.color(weechat.config_color(jabber_config_option[color]))
|
||||
return ""
|
||||
|
||||
|
||||
def ping_timeout_check_cb(server_name, option, value):
|
||||
global jabber_config_file, jabber_config_section
|
||||
ping_interval_option = weechat.config_search_option(
|
||||
@@ -394,6 +405,7 @@ def ping_timeout_check_cb(server_name, option, value):
|
||||
return weechat.WEECHAT_CONFIG_OPTION_SET_ERROR
|
||||
return weechat.WEECHAT_CONFIG_OPTION_SET_OK_CHANGED
|
||||
|
||||
|
||||
def ping_interval_check_cb(server_name, option, value):
|
||||
global jabber_config_file, jabber_config_section
|
||||
ping_timeout_option = weechat.config_search_option(
|
||||
@@ -410,6 +422,7 @@ def ping_interval_check_cb(server_name, option, value):
|
||||
|
||||
# ================================[ servers ]=================================
|
||||
|
||||
|
||||
class Server:
|
||||
""" Class to manage a server: buffer, connection, send/recv data. """
|
||||
|
||||
@@ -529,7 +542,7 @@ class Server:
|
||||
self.sock = self.client.Connection._sock.fileno()
|
||||
self.hook_fd = weechat.hook_fd(self.sock, 1, 0, 0, "jabber_fd_cb", "")
|
||||
weechat.buffer_set(self.buffer, "highlight_words", self.buddy.username)
|
||||
weechat.buffer_set(self.buffer, "localvar_set_nick", self.buddy.username);
|
||||
weechat.buffer_set(self.buffer, "localvar_set_nick", self.buddy.username)
|
||||
hook_away = weechat.hook_command_run("/away -all*", "jabber_away_command_run_cb", "")
|
||||
|
||||
# Joining rooms registerer in autojoin server option
|
||||
@@ -543,7 +556,6 @@ class Server:
|
||||
priority = weechat.config_integer(self.options['priority'])
|
||||
self.set_presence(show="", priority=priority)
|
||||
|
||||
|
||||
self.ping_up = True
|
||||
else:
|
||||
weechat.prnt(self.buffer, "%sjabber: could not authenticate"
|
||||
@@ -804,9 +816,12 @@ class Server:
|
||||
self.set_presence(show, status, priority)
|
||||
|
||||
def set_presence(self, show=None, status=None, priority=None):
|
||||
if not show == None: self.presence.setShow(show)
|
||||
if not status == None: self.presence.setStatus(status)
|
||||
if not priority == None: self.presence.setPriority(priority)
|
||||
if not show == None:
|
||||
self.presence.setShow(show)
|
||||
if not status == None:
|
||||
self.presence.setStatus(status)
|
||||
if not priority == None:
|
||||
self.presence.setPriority(priority)
|
||||
self.client.send(self.presence)
|
||||
|
||||
def add_buddy(self, jid=None):
|
||||
@@ -1040,6 +1055,7 @@ class Server:
|
||||
for name, option in self.options.items():
|
||||
weechat.config_option_free(option)
|
||||
|
||||
|
||||
def eval_expression(option_name):
|
||||
""" Return a evaluated expression """
|
||||
if int(version) >= 0x00040200:
|
||||
@@ -1047,6 +1063,7 @@ def eval_expression(option_name):
|
||||
else:
|
||||
return option_name
|
||||
|
||||
|
||||
def jabber_search_server_by_name(name):
|
||||
""" Search a server by name. """
|
||||
global jabber_servers
|
||||
@@ -1055,6 +1072,7 @@ def jabber_search_server_by_name(name):
|
||||
return server
|
||||
return None
|
||||
|
||||
|
||||
def jabber_search_context(buffer):
|
||||
""" Search a server / chat for a buffer. """
|
||||
global jabber_servers
|
||||
@@ -1070,6 +1088,7 @@ def jabber_search_context(buffer):
|
||||
return context
|
||||
return context
|
||||
|
||||
|
||||
def jabber_search_context_by_name(server_name):
|
||||
"""Search for buffer given name of server. """
|
||||
|
||||
@@ -1170,6 +1189,7 @@ class Chat:
|
||||
|
||||
class MUC:
|
||||
""" Class to manage XMPP MUC. """
|
||||
|
||||
def __init__(self, jid=None, chat=None, server=None):
|
||||
""" Init MUC
|
||||
|
||||
@@ -1363,8 +1383,10 @@ class MUC:
|
||||
msg))
|
||||
return
|
||||
|
||||
|
||||
class Buddy:
|
||||
""" Class to manage buddies. """
|
||||
|
||||
def __init__(self, jid=None, chat=None, server=None):
|
||||
""" Init buddy
|
||||
|
||||
@@ -1475,6 +1497,7 @@ class Buddy:
|
||||
|
||||
# ================================[ commands ]================================
|
||||
|
||||
|
||||
def jabber_hook_commands_and_completions():
|
||||
""" Hook commands and completions. """
|
||||
weechat.hook_command(SCRIPT_COMMAND, "Manage Jabber servers",
|
||||
@@ -1561,6 +1584,7 @@ def jabber_hook_commands_and_completions():
|
||||
weechat.hook_completion("jabber_jid_aliases", "list of jabber jid aliases",
|
||||
"jabber_completion_jid_aliases", "")
|
||||
|
||||
|
||||
def jabber_list_servers_chats(name):
|
||||
""" List servers and chats. """
|
||||
global jabber_servers
|
||||
@@ -1585,6 +1609,7 @@ def jabber_list_servers_chats(name):
|
||||
else:
|
||||
weechat.prnt("", "jabber: no server defined")
|
||||
|
||||
|
||||
def jabber_cmd_jabber(data, buffer, args):
|
||||
""" Command '/jabber'. """
|
||||
global jabber_servers, jabber_config_option
|
||||
@@ -1610,8 +1635,10 @@ def jabber_cmd_jabber(data, buffer, args):
|
||||
if conn_port and not conn_port.isdigit():
|
||||
weechat.prnt("", "jabber: error, invalid port, digits only")
|
||||
return weechat.WEECHAT_RC_OK
|
||||
if conn_server: kwargs['server'] = conn_server
|
||||
if conn_port: kwargs['port'] = conn_port
|
||||
if conn_server:
|
||||
kwargs['server'] = conn_server
|
||||
if conn_port:
|
||||
kwargs['port'] = conn_port
|
||||
server = Server(argv[1], **kwargs)
|
||||
jabber_servers.append(server)
|
||||
weechat.prnt("", "jabber: server '%s' created" % argv[1])
|
||||
@@ -1694,13 +1721,16 @@ def jabber_cmd_jabber(data, buffer, args):
|
||||
if context["server"]:
|
||||
if len(argv) == 1:
|
||||
show = context["server"].presence.getShow()
|
||||
if show == "": show = "online"
|
||||
if show == "":
|
||||
show = "online"
|
||||
weechat.prnt("", "jabber: presence = %s" % show)
|
||||
elif not re.match(r'^(?:online|chat|away|xa|dnd)$', argv[1]):
|
||||
weechat.prnt("", "jabber: Presence should be one of: online, chat, away, xa, dnd")
|
||||
else:
|
||||
if argv[1] == "online": show = ""
|
||||
else: show = argv[1]
|
||||
if argv[1] == "online":
|
||||
show = ""
|
||||
else:
|
||||
show = argv[1]
|
||||
context["server"].set_presence(show=show)
|
||||
elif argv[0] == "buddies":
|
||||
context = jabber_search_context(buffer)
|
||||
@@ -1716,6 +1746,7 @@ def jabber_cmd_jabber(data, buffer, args):
|
||||
weechat.prnt("", "jabber: unknown action")
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def jabber_cmd_jchat(data, buffer, args):
|
||||
""" Command '/jchat'. """
|
||||
if args:
|
||||
@@ -1731,6 +1762,7 @@ def jabber_cmd_jchat(data, buffer, args):
|
||||
weechat.prnt("", "Usage: /jchat <nickname>")
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def jabber_cmd_room(data, buffer, args):
|
||||
""" Command '/jroom'. """
|
||||
global jabber_config_file
|
||||
@@ -1767,6 +1799,7 @@ def jabber_cmd_room(data, buffer, args):
|
||||
weechat.prnt("", "Usage: /jroom <roomname>@conference.<server_FQDN> [<optional_user_nickname>]")
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def jabber_cmd_jmsg(data, buffer, args):
|
||||
""" Command '/jmsg'. """
|
||||
if args:
|
||||
@@ -1787,6 +1820,7 @@ def jabber_cmd_jmsg(data, buffer, args):
|
||||
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def jabber_cmd_invite(data, buffer, args):
|
||||
""" Command '/invite'. """
|
||||
if args:
|
||||
@@ -1795,6 +1829,7 @@ def jabber_cmd_invite(data, buffer, args):
|
||||
context["server"].add_buddy(args)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def jabber_cmd_kick(data, buffer, args):
|
||||
""" Command '/kick'. """
|
||||
if args:
|
||||
@@ -1803,6 +1838,7 @@ def jabber_cmd_kick(data, buffer, args):
|
||||
context["server"].del_buddy(args)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def jabber_away_command_run_cb(data, buffer, command):
|
||||
""" Callback called when /away -all command is run """
|
||||
global jabber_servers
|
||||
@@ -1816,6 +1852,7 @@ def jabber_away_command_run_cb(data, buffer, command):
|
||||
server.set_away(message)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
class AliasCommand(object):
|
||||
"""Class representing a jabber alias command, ie /jabber alias ..."""
|
||||
|
||||
@@ -1945,7 +1982,8 @@ class AliasCommand(object):
|
||||
self.action = self.argv[0]
|
||||
if len(self.argv) > 1:
|
||||
# Pad argv list to prevent IndexError exceptions
|
||||
while len(self.argv) < 3: self.argv.append('')
|
||||
while len(self.argv) < 3:
|
||||
self.argv.append('')
|
||||
self.alias = self.argv[1]
|
||||
self.jid = self.argv[2]
|
||||
return
|
||||
@@ -1959,6 +1997,7 @@ class AliasCommand(object):
|
||||
self.list()
|
||||
return
|
||||
|
||||
|
||||
def jabber_completion_servers(data, completion_item, buffer, completion):
|
||||
""" Completion with jabber server names. """
|
||||
global jabber_servers
|
||||
@@ -1967,6 +2006,7 @@ def jabber_completion_servers(data, completion_item, buffer, completion):
|
||||
0, weechat.WEECHAT_LIST_POS_SORT)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def jabber_completion_jid_aliases(data, completion_item, buffer, completion):
|
||||
""" Completion with jabber alias names. """
|
||||
global jabber_jid_aliases
|
||||
@@ -1977,6 +2017,7 @@ def jabber_completion_jid_aliases(data, completion_item, buffer, completion):
|
||||
|
||||
# ==================================[ fd ]====================================
|
||||
|
||||
|
||||
def jabber_fd_cb(data, fd):
|
||||
""" Callback for reading socket. """
|
||||
global jabber_servers
|
||||
@@ -1987,6 +2028,7 @@ def jabber_fd_cb(data, fd):
|
||||
|
||||
# ================================[ buffers ]=================================
|
||||
|
||||
|
||||
def jabber_buffer_input_cb(data, buffer, input_data):
|
||||
""" Callback called for input data on a jabber buffer. """
|
||||
context = jabber_search_context(buffer)
|
||||
@@ -1999,6 +2041,7 @@ def jabber_buffer_input_cb(data, buffer, input_data):
|
||||
context["server"].send_message_from_input(input=input_data)
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def jabber_buffer_close_cb(data, buffer):
|
||||
""" Callback called when a jabber buffer is closed. """
|
||||
context = jabber_search_context(buffer)
|
||||
@@ -2013,12 +2056,14 @@ def jabber_buffer_close_cb(data, buffer):
|
||||
|
||||
# ==================================[ timers ]==================================
|
||||
|
||||
|
||||
def jabber_ping_timeout_timer(server_name, remaining_calls):
|
||||
server = jabber_search_server_by_name(server_name)
|
||||
if server:
|
||||
server.ping_time_out()
|
||||
return weechat.WEECHAT_RC_OK
|
||||
|
||||
|
||||
def jabber_ping_timer(server_name, remaining_calls):
|
||||
server = jabber_search_server_by_name(server_name)
|
||||
if server:
|
||||
@@ -2027,6 +2072,7 @@ def jabber_ping_timer(server_name, remaining_calls):
|
||||
|
||||
# ==================================[ main ]==================================
|
||||
|
||||
|
||||
if __name__ == "__main__" and import_ok:
|
||||
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
|
||||
SCRIPT_LICENSE, SCRIPT_DESC,
|
||||
@@ -2046,6 +2092,7 @@ if __name__ == "__main__" and import_ok:
|
||||
|
||||
# ==================================[ end ]===================================
|
||||
|
||||
|
||||
def jabber_unload_script():
|
||||
""" Function called when script is unloaded. """
|
||||
global jabber_servers
|
||||
|
||||
Reference in New Issue
Block a user