diff options
-rw-r--r-- | plugins/gpg/__init__.py | 6 | ||||
-rw-r--r-- | plugins/irc.py | 16 | ||||
-rw-r--r-- | plugins/otr.py | 4 | ||||
-rw-r--r-- | plugins/ping.py | 2 | ||||
-rw-r--r-- | plugins/screen_detach.py | 2 | ||||
-rw-r--r-- | plugins/tell.py | 2 | ||||
-rw-r--r-- | poezio/core/commands.py | 578 | ||||
-rw-r--r-- | poezio/core/core.py | 160 | ||||
-rw-r--r-- | poezio/tabs/basetabs.py | 2 | ||||
-rw-r--r-- | poezio/tabs/conversationtab.py | 4 | ||||
-rw-r--r-- | poezio/tabs/muclisttab.py | 2 | ||||
-rw-r--r-- | poezio/tabs/muctab.py | 26 | ||||
-rw-r--r-- | poezio/tabs/privatetab.py | 2 | ||||
-rw-r--r-- | poezio/tabs/rostertab.py | 22 | ||||
-rw-r--r-- | poezio/tabs/xmltab.py | 4 |
15 files changed, 399 insertions, 433 deletions
diff --git a/plugins/gpg/__init__.py b/plugins/gpg/__init__.py index 0f441653..3e1f8b0b 100644 --- a/plugins/gpg/__init__.py +++ b/plugins/gpg/__init__.py @@ -194,7 +194,7 @@ class Plugin(BasePlugin): that we cannot/do not want to encrypt/decrypt messages. """ current_presence = self.core.get_status() - self.core.command_status('%s %s' % (current_presence.show or 'available', current_presence.message or '',)) + self.core.command.status('%s %s' % (current_presence.show or 'available', current_presence.message or '',)) def on_normal_presence(self, presence): """ @@ -293,7 +293,7 @@ class Plugin(BasePlugin): """ args = args.split() if not args: - return self.core.command_help("gpg") + return self.core.command.help("gpg") if len(args) >= 2: jid = JID(args[1]) else: @@ -313,7 +313,7 @@ class Plugin(BasePlugin): self.contacts[JID(jid).full] = 'disabled' elif command == 'setkey': if len(args) != 3: - return self.core.command_help("gpg") + return self.core.command.help("gpg") if not self.config.has_section('keys'): self.config.add_section('keys') self.config.set(jid.bare, args[2], 'keys') diff --git a/plugins/irc.py b/plugins/irc.py index fe172481..9a67ffe4 100644 --- a/plugins/irc.py +++ b/plugins/irc.py @@ -178,7 +178,7 @@ class Plugin(BasePlugin): rooms = self.config.get_by_tabname('rooms', server, default='').split(':') for room in rooms: room = '{}%{}@{}/{}'.format(room, server, gateway, nick) - self.core.command_join(room) + self.core.command.join(room) def initial_connect(self): gateway = self.config.get('gateway', 'irc.poez.io') @@ -204,7 +204,7 @@ class Plugin(BasePlugin): delayed = self.api.create_delayed_event(5, self.join, gw, sect) self.api.add_timed_event(delayed) if not already_opened: - self.core.command_join(room_suffix + '/' + nick) + self.core.command.join(room_suffix + '/' + nick) delayed = self.api.create_delayed_event(5, login, gateway, section, login_nick, login_command, room_suffix[1:]) @@ -278,7 +278,7 @@ class Plugin(BasePlugin): /irc_join <room or server> """ if not args: - return self.core.command_help('irc_join') + return self.core.command.help('irc_join') sections = self.config.sections() if 'irc' in sections: sections.remove('irc') @@ -294,7 +294,7 @@ class Plugin(BasePlugin): server. """ if args is None: - return self.core.command_help('irc_query') + return self.core.command.help('irc_query') current_tab_info = self.get_current_tab_irc_info() if not current_tab_info: return @@ -305,9 +305,9 @@ class Plugin(BasePlugin): message = args[1] jid = '{}!{}@{}'.format(nickname, server, gateway) if message: - self.core.command_message('{} "{}"'.format(jid, message)) + self.core.command.message('{} "{}"'.format(jid, message)) else: - self.core.command_message('{}'.format(jid)) + self.core.command.message('{}'.format(jid)) def join_server_rooms(self, section): """ @@ -324,7 +324,7 @@ class Plugin(BasePlugin): suffix = '%{}@{}{}'.format(section, gateway, nick) for room in rooms: - self.core.command_join(room + suffix) + self.core.command.join(room + suffix) def join_room(self, name): """ @@ -339,7 +339,7 @@ class Plugin(BasePlugin): if self.config.get_by_tabname('nickname', server): room += '/' + self.config.get_by_tabname('nickname', server) - self.core.command_join(room) + self.core.command.join(room) def get_current_tab_irc_info(self): """ diff --git a/plugins/otr.py b/plugins/otr.py index 2d59d544..72c80093 100644 --- a/plugins/otr.py +++ b/plugins/otr.py @@ -810,7 +810,7 @@ class Plugin(BasePlugin): """ args = common.shell_split(arg) if not args: - return self.core.command_help('otr') + return self.core.command.help('otr') action = args.pop(0) tab = self.api.current_tab() name = tab.name @@ -920,7 +920,7 @@ class Plugin(BasePlugin): /otrsmp <ask|answer|abort> [question] [secret] """ if args is None or not args: - return self.core.command_help('otrsmp') + return self.core.command.help('otrsmp') length = len(args) action = args.pop(0) if length == 2: diff --git a/plugins/ping.py b/plugins/ping.py index c04f085c..fd3d467c 100644 --- a/plugins/ping.py +++ b/plugins/ping.py @@ -58,7 +58,7 @@ class Plugin(BasePlugin): @command_args_parser.raw def command_ping(self, arg): if not arg: - return self.core.command_help('ping') + return self.core.command.help('ping') jid = safeJID(arg) start = time.time() def callback(iq): diff --git a/plugins/screen_detach.py b/plugins/screen_detach.py index 793575d8..e6c02a88 100644 --- a/plugins/screen_detach.py +++ b/plugins/screen_detach.py @@ -99,7 +99,7 @@ class Plugin(BasePlugin, pyinotify.Notifier): if attached != self.attached: self.attached = attached status = 'available' if self.attached else 'away' - self.core.command_status(status) + self.core.command.status(status) if self.config.get('use_csi'): if self.attached: self.core.xmpp.plugin['xep_0352'].send_active() diff --git a/plugins/tell.py b/plugins/tell.py index 16cecacc..76c9d2f0 100644 --- a/plugins/tell.py +++ b/plugins/tell.py @@ -52,7 +52,7 @@ class Plugin(BasePlugin): def command_tell(self, args): """/tell <nick> <message>""" if args is None: - self.core.command_help('tell') + self.core.command.help('tell') return nick, msg = args tab = self.api.current_tab() diff --git a/poezio/core/commands.py b/poezio/core/commands.py index 14e09300..a3bbcb42 100644 --- a/poezio/core/commands.py +++ b/poezio/core/commands.py @@ -35,7 +35,7 @@ class CommandCore: self.core = core @command_args_parser.quoted(0, 1) - def command_help(self, args): + def help(self, args): """ /help [command_name] """ @@ -43,27 +43,27 @@ class CommandCore: color = dump_tuple(get_theme().COLOR_HELP_COMMANDS) acc = [] buff = ['Global commands:'] - for command in self.commands: - if isinstance(self.commands[command], Command): + for name, command in enumerate(self.core.commands): + if isinstance(command, Command): acc.append(' \x19%s}%s\x19o - %s' % ( color, - command, - self.commands[command].short_desc)) + name, + command.short_desc)) else: - acc.append(' \x19%s}%s\x19o' % (color, command)) + acc.append(' \x19%s}%s\x19o' % (color, name)) acc = sorted(acc) buff.extend(acc) acc = [] buff.append('Tab-specific commands:') - commands = self.current_tab().commands - for command in commands: - if isinstance(commands[command], Command): + tab_commands = self.core.current_tab().commands + for name, command in enumerate(tab_commands): + if isinstance(command, Command): acc.append(' \x19%s}%s\x19o - %s' % ( color, - command, - commands[command].short_desc)) + name, + command.short_desc)) else: - acc.append(' \x19%s}%s\x19o' % (color, command)) + acc.append(' \x19%s}%s\x19o' % (color, name)) acc = sorted(acc) buff.extend(acc) @@ -72,22 +72,23 @@ class CommandCore: else: command = args[0].lstrip('/').strip() - if command in self.current_tab().commands: - tup = self.current_tab().commands[command] - elif command in self.commands: - tup = self.commands[command] + tab_commands = self.core.current_tab().commands + if command in tab_commands: + tup = tab_commands[command] + elif command in self.core.commands: + tup = self.core.commands[command] else: - self.information('Unknown command: %s' % command, 'Error') + self.core.information('Unknown command: %s' % command, 'Error') return if isinstance(tup, Command): msg = 'Usage: /%s %s\n' % (command, tup.usage) msg += tup.desc else: msg = tup[1] - self.information(msg, 'Help') + self.core.information(msg, 'Help') @command_args_parser.quoted(1) - def command_runkey(self, args): + def runkey(self, args): """ /runkey <key> """ @@ -97,71 +98,71 @@ class CommandCore: return '\n' return key if args is None: - return self.command_help('runkey') + return self.help('runkey') char = args[0] - func = self.key_func.get(char, None) + func = self.core.key_func.get(char, None) if func: func() else: - res = self.do_command(replace_line_breaks(char), False) + res = self.core.do_command(replace_line_breaks(char), False) if res: - self.refresh_window() + self.core.refresh_window() @command_args_parser.quoted(1, 1, [None]) - def command_status(self, args): + def status(self, args): """ /status <status> [msg] """ if args is None: - return self.command_help('status') + return self.help('status') if not args[0] in POSSIBLE_SHOW.keys(): - return self.command_help('status') + return self.help('status') show = POSSIBLE_SHOW[args[0]] msg = args[1] - pres = self.xmpp.make_presence() + pres = self.core.xmpp.make_presence() if msg: pres['status'] = msg pres['type'] = show - self.events.trigger('send_normal_presence', pres) + self.core.events.trigger('send_normal_presence', pres) pres.send() - current = self.current_tab() + current = self.core.current_tab() is_muctab = isinstance(current, tabs.MucTab) if is_muctab and current.joined and show in ('away', 'xa'): current.send_chat_state('inactive') - for tab in self.tabs: + for tab in self.core.tabs: if isinstance(tab, tabs.MucTab) and tab.joined: - muc.change_show(self.xmpp, tab.name, tab.own_nick, show, msg) + muc.change_show(self.core.xmpp, tab.name, tab.own_nick, show, msg) if hasattr(tab, 'directed_presence'): del tab.directed_presence - self.set_status(show, msg) + self.core.set_status(show, msg) if is_muctab and current.joined and show not in ('away', 'xa'): current.send_chat_state('active') @command_args_parser.quoted(1, 2, [None, None]) - def command_presence(self, args): + def presence(self, args): """ /presence <JID> [type] [status] """ if args is None: - return self.command_help('presence') + return self.help('presence') jid, type, status = args[0], args[1], args[2] - if jid == '.' and isinstance(self.current_tab(), tabs.ChatTab): - jid = self.current_tab().name + if jid == '.' and isinstance(self.core.current_tab(), tabs.ChatTab): + jid = self.core.current_tab().name if type == 'available': type = None try: - pres = self.xmpp.make_presence(pto=jid, ptype=type, pstatus=status) - self.events.trigger('send_normal_presence', pres) + pres = self.core.xmpp.make_presence(pto=jid, ptype=type, pstatus=status) + self.core.events.trigger('send_normal_presence', pres) pres.send() except: - self.information('Could not send directed presence', 'Error') + self.core.information('Could not send directed presence', 'Error') log.debug('Could not send directed presence to %s', jid, exc_info=True) return - tab = self.get_tab_by_name(jid) + tab = self.core.get_tab_by_name(jid) if tab: if type in ('xa', 'away'): tab.directed_presence = False @@ -169,67 +170,67 @@ class CommandCore: else: tab.directed_presence = True chatstate = 'active' - if tab == self.current_tab(): + if tab == self.core.current_tab(): tab.send_chat_state(chatstate, True) if isinstance(tab, tabs.MucTab): for private in tab.privates: private.directed_presence = tab.directed_presence - if self.current_tab() in tab.privates: - self.current_tab().send_chat_state(chatstate, True) + if self.core.current_tab() in tab.privates: + self.core.current_tab().send_chat_state(chatstate, True) @command_args_parser.quoted(1) - def command_theme(self, args=None): + def theme(self, args=None): """/theme <theme name>""" if args is None: - return self.command_help('theme') - self.command_set('theme %s' % (args[0],)) + return self.help('theme') + self.set('theme %s' % (args[0],)) @command_args_parser.quoted(1) - def command_win(self, args): + def win(self, args): """ /win <number> """ if args is None: - return self.command_help('win') + return self.help('win') nb = args[0] try: nb = int(nb) except ValueError: pass - if self.current_tab_nb == nb: + if self.core.current_tab_nb == nb: return - self.previous_tab_nb = self.current_tab_nb - old_tab = self.current_tab() + self.core.previous_tab_nb = self.core.current_tab_nb + old_tab = self.core.current_tab() if isinstance(nb, int): - if 0 <= nb < len(self.tabs): - if not self.tabs[nb]: + if 0 <= nb < len(self.core.tabs): + if not self.core.tabs[nb]: return - self.current_tab_nb = nb + self.core.current_tab_nb = nb else: matchs = [] - for tab in self.tabs: + for tab in self.core.tabs: for name in tab.matching_names(): if nb.lower() in name[1].lower(): matchs.append((name[0], tab)) - self.current_tab_nb = tab.nb + self.core.current_tab_nb = tab.nb if not matchs: return tab = min(matchs, key=lambda m: m[0])[1] - self.current_tab_nb = tab.nb + self.core.current_tab_nb = tab.nb old_tab.on_lose_focus() - self.current_tab().on_gain_focus() - self.refresh_window() + self.core.current_tab().on_gain_focus() + self.core.refresh_window() @command_args_parser.quoted(2) - def command_move_tab(self, args): + def move_tab(self, args): """ /move_tab old_pos new_pos """ if args is None: - return self.command_help('move_tab') + return self.help('move_tab') - current_tab = self.current_tab() + current_tab = self.core.current_tab() if args[0] == '.': args[0] = current_tab.nb if args[1] == '.': @@ -242,83 +243,83 @@ class CommandCore: ref = int(value) except ValueError: old_tab = None - for tab in self.tabs: + for tab in self.core.tabs: if not old_tab and value == tab.name: old_tab = tab if not old_tab: - self.information("Tab %s does not exist" % args[0], "Error") + self.core.information("Tab %s does not exist" % args[0], "Error") return None ref = old_tab.nb return ref old = get_nb_from_value(args[0]) new = get_nb_from_value(args[1]) if new is None or old is None: - return self.information('Unable to move the tab.', 'Info') - result = self.insert_tab(old, new) + return self.core.information('Unable to move the tab.', 'Info') + result = self.core.insert_tab(old, new) if not result: - self.information('Unable to move the tab.', 'Info') + self.core.information('Unable to move the tab.', 'Info') else: - self.current_tab_nb = self.tabs.index(current_tab) - self.refresh_window() + self.core.current_tab_nb = self.core.tabs.index(current_tab) + self.core.refresh_window() @command_args_parser.quoted(0, 1) - def command_list(self, args): + def list(self, args): """ /list [server] Opens a MucListTab containing the list of the room in the specified server """ if args is None: - return self.command_help('list') + return self.help('list') elif args: jid = safeJID(args[0]) else: - if not isinstance(self.current_tab(), tabs.MucTab): - return self.information('Please provide a server', 'Error') - jid = safeJID(self.current_tab().name).server + if not isinstance(self.core.current_tab(), tabs.MucTab): + return self.core.information('Please provide a server', 'Error') + jid = safeJID(self.core.current_tab().name).server list_tab = tabs.MucListTab(jid) - self.add_tab(list_tab, True) + self.core.add_tab(list_tab, True) cb = list_tab.on_muc_list_item_received - self.xmpp.plugin['xep_0030'].get_items(jid=jid, - callback=cb) + self.core.xmpp.plugin['xep_0030'].get_items(jid=jid, + callback=cb) @command_args_parser.quoted(1) - def command_version(self, args): + def version(self, args): """ /version <jid> """ def callback(res): "Callback for /version" if not res: - return self.information('Could not get the software' - ' version from %s' % jid, - 'Warning') + return self.core.information('Could not get the software' + ' version from %s' % jid, + 'Warning') version = '%s is running %s version %s on %s' % ( jid, res.get('name') or 'an unknown software', res.get('version') or 'unknown', res.get('os') or 'an unknown platform') - self.information(version, 'Info') + self.core.information(version, 'Info') if args is None: - return self.command_help('version') + return self.help('version') jid = safeJID(args[0]) if jid.resource or jid not in roster: - fixes.get_version(self.xmpp, jid, callback=callback) + fixes.get_version(self.core.xmpp, jid, callback=callback) elif jid in roster: for resource in roster[jid].resources: - fixes.get_version(self.xmpp, resource.jid, callback=callback) + fixes.get_version(self.core.xmpp, resource.jid, callback=callback) else: - fixes.get_version(self.xmpp, jid, callback=callback) + fixes.get_version(self.core.xmpp, jid, callback=callback) @command_args_parser.quoted(0, 2) - def command_join(self, args): + def join(self, args): """ /join [room][/nick] [password] """ password = None if len(args) == 0: - tab = self.current_tab() + tab = self.core.current_tab() if not isinstance(tab, (tabs.MucTab, tabs.PrivateTab)): return room = safeJID(tab.name).bare @@ -333,11 +334,11 @@ class CommandCore: if info == '' and len(args[0]) > 1 and args[0][0] == '/': nick = args[0][1:] elif info.resource == '': - nick = self.own_nick + nick = self.core.own_nick else: nick = info.resource if info.bare == '': # happens with /join /nickname, which is OK - tab = self.current_tab() + tab = self.core.current_tab() if not isinstance(tab, tabs.MucTab): return room = tab.name @@ -349,25 +350,25 @@ class CommandCore: # use the server of the current room if available # check if the current room's name has a server if room.find('@') == -1 and not server_root: - if isinstance(self.current_tab(), tabs.MucTab) and\ - self.current_tab().name.find('@') != -1: - domain = safeJID(self.current_tab().name).domain + tab = self.core.current_tab() + if isinstance(tab, tabs.MucTab) and\ + tab.name.find('@') != -1: + domain = safeJID(tab.name).domain room += '@%s' % domain else: room = args[0] room = room.lower() - if room in self.pending_invites: - del self.pending_invites[room] - tab = self.get_tab_by_name(room, tabs.MucTab) + if room in self.core.pending_invites: + del self.core.pending_invites[room] + tab = self.core.get_tab_by_name(room, tabs.MucTab) if tab is not None: - self.focus_tab_named(tab.name) + self.core.focus_tab_named(tab.name) if tab.own_nick == nick and tab.joined: - self.information('/join: Nothing to do.', 'Info') + self.core.information('/join: Nothing to do.', 'Info') else: tab.command_part('') tab.own_nick = nick tab.join() - return if room.startswith('@'): @@ -381,70 +382,71 @@ class CommandCore: tab.password = password tab.join() else: - tab = self.open_new_room(room, nick, password=password) + tab = self.core.open_new_room(room, nick, password=password) tab.join() if tab.joined: - self.enable_private_tabs(room) + self.core.enable_private_tabs(room) tab.state = "normal" - if tab == self.current_tab(): + if tab == self.core.current_tab(): tab.refresh() - self.doupdate() + self.core.doupdate() @command_args_parser.quoted(0, 2) - def command_bookmark_local(self, args): + def bookmark_local(self, args): """ /bookmark_local [room][/nick] [password] """ - if not args and not isinstance(self.current_tab(), tabs.MucTab): + if not args and not isinstance(self.core.current_tab(), tabs.MucTab): return password = args[1] if len(args) > 1 else None jid = args[0] if args else None - _add_bookmark(self, jid, True, password, 'local') + self._add_bookmark(jid, True, password, 'local') @command_args_parser.quoted(0, 3) - def command_bookmark(self, args): + def bookmark(self, args): """ /bookmark [room][/nick] [autojoin] [password] """ - if not args and not isinstance(self.current_tab(), tabs.MucTab): + if not args and not isinstance(self.core.current_tab(), tabs.MucTab): return jid = args[0] if args else '' password = args[2] if len(args) > 2 else None if not config.get('use_remote_bookmarks'): - return _add_bookmark(self, jid, True, password, 'local') + return self._add_bookmark(jid, True, password, 'local') if len(args) > 1: autojoin = False if args[1].lower() != 'true' else True else: autojoin = True - _add_bookmark(self, jid, autojoin, password, 'remote') + self._add_bookmark(jid, autojoin, password, 'remote') def _add_bookmark(self, jid, autojoin, password, method): nick = None if not jid: - tab = self.current_tab() + tab = self.core.current_tab() roomname = tab.name - if tab.joined and tab.own_nick != self.own_nick: + if tab.joined and tab.own_nick != self.core.own_nick: nick = tab.own_nick if password is None and tab.password is not None: password = tab.password elif jid == '*': - return _add_wildcard_bookmarks(self, method) + return self._add_wildcard_bookmarks(method) else: info = safeJID(jid) roomname, nick = info.bare, info.resource if roomname == '': - if not isinstance(self.current_tab(), tabs.MucTab): + tab = self.core.current_tab() + if not isinstance(tab, tabs.MucTab): return - roomname = self.current_tab().name - bookmark = self.bookmarks[roomname] + roomname = tab.name + bookmark = self.core.bookmarks[roomname] if bookmark is None: bookmark = Bookmark(roomname) - self.bookmarks.append(bookmark) + self.core.bookmarks.append(bookmark) bookmark.method = method bookmark.autojoin = autojoin if nick: @@ -453,16 +455,16 @@ class CommandCore: bookmark.password = password def callback(iq): if iq["type"] != "error": - self.information('Bookmark added.', 'Info') + self.core.information('Bookmark added.', 'Info') else: - self.information("Could not add the bookmarks.", "Info") - self.bookmarks.save_local() - self.bookmarks.save_remote(self.xmpp, callback) + self.core.information("Could not add the bookmarks.", "Info") + self.core.bookmarks.save_local() + self.core.bookmarks.save_remote(self.core.xmpp, callback) def _add_wildcard_bookmarks(self, method): new_bookmarks = [] - for tab in self.get_tabs(tabs.MucTab): - bookmark = self.bookmarks[tab.name] + for tab in self.core.get_tabs(tabs.MucTab): + bookmark = self.core.bookmarks[tab.name] if not bookmark: bookmark = Bookmark(tab.name, autojoin=True, method=method) @@ -470,58 +472,58 @@ class CommandCore: else: bookmark.method = method new_bookmarks.append(bookmark) - self.bookmarks.remove(bookmark) - new_bookmarks.extend(self.bookmarks.bookmarks) - self.bookmarks.set(new_bookmarks) + self.core.bookmarks.remove(bookmark) + new_bookmarks.extend(self.core.bookmarks.bookmarks) + self.core.bookmarks.set(new_bookmarks) def _cb(iq): if iq["type"] != "error": - self.information("Bookmarks saved.", "Info") + self.core.information("Bookmarks saved.", "Info") else: - self.information("Could not save the remote bookmarks.", "Info") - self.bookmarks.save_local() - self.bookmarks.save_remote(self.xmpp, _cb) + self.core.information("Could not save the remote bookmarks.", "Info") + self.core.bookmarks.save_local() + self.core.bookmarks.save_remote(self.core.xmpp, _cb) @command_args_parser.ignored - def command_bookmarks(self): + def bookmarks(self): """/bookmarks""" - tab = self.get_tab_by_name('Bookmarks', tabs.BookmarksTab) - old_tab = self.current_tab() + tab = self.core.get_tab_by_name('Bookmarks', tabs.BookmarksTab) + old_tab = self.core.current_tab() if tab: - self.current_tab_nb = tab.nb + self.core.current_tab_nb = tab.nb else: - tab = tabs.BookmarksTab(self.bookmarks) - self.tabs.append(tab) - self.current_tab_nb = tab.nb + tab = tabs.BookmarksTab(self.core.bookmarks) + self.core.tabs.append(tab) + self.core.current_tab_nb = tab.nb old_tab.on_lose_focus() tab.on_gain_focus() - self.refresh_window() + self.core.refresh_window() @command_args_parser.quoted(0, 1) - def command_remove_bookmark(self, args): + def remove_bookmark(self, args): """/remove_bookmark [jid]""" def cb(success): if success: - self.information('Bookmark deleted', 'Info') + self.core.information('Bookmark deleted', 'Info') else: - self.information('Error while deleting the bookmark', 'Error') + self.core.information('Error while deleting the bookmark', 'Error') if not args: - tab = self.current_tab() - if isinstance(tab, tabs.MucTab) and self.bookmarks[tab.name]: - self.bookmarks.remove(tab.name) - self.bookmarks.save(self.xmpp, callback=cb) + tab = self.core.current_tab() + if isinstance(tab, tabs.MucTab) and self.core.bookmarks[tab.name]: + self.core.bookmarks.remove(tab.name) + self.core.bookmarks.save(self.core.xmpp, callback=cb) else: - self.information('No bookmark to remove', 'Info') + self.core.information('No bookmark to remove', 'Info') else: - if self.bookmarks[args[0]]: - self.bookmarks.remove(args[0]) - self.bookmarks.save(self.xmpp, callback=cb) + if self.core.bookmarks[args[0]]: + self.core.bookmarks.remove(args[0]) + self.core.bookmarks.save(self.core.xmpp, callback=cb) else: - self.information('No bookmark to remove', 'Info') + self.core.information('No bookmark to remove', 'Info') @command_args_parser.quoted(0, 3) - def command_set(self, args): + def set(self, args): """ /set [module|][section] <option> [value] """ @@ -552,12 +554,12 @@ class CommandCore: if not section: section = plugin_name option = args[1] - if not plugin_name in self.plugin_manager.plugins: - file_name = self.plugin_manager.plugins_conf_dir + if not plugin_name in self.core.plugin_manager.plugins: + file_name = self.core.plugin_manager.plugins_conf_dir file_name = os.path.join(file_name, plugin_name + '.cfg') plugin_config = PluginConfig(file_name, plugin_name) else: - plugin_config = self.plugin_manager.plugins[plugin_name].config + plugin_config = self.core.plugin_manager.plugins[plugin_name].config value = plugin_config.get(option, default='', section=section) info = ('%s=%s' % (option, value), 'Info') else: @@ -571,7 +573,7 @@ class CommandCore: option = args[0] value = args[1] info = config.set_and_save(option, value) - self.trigger_configuration_change(option, value) + self.core.trigger_configuration_change(option, value) elif len(args) == 3: if '|' in args[0]: plugin_name, section = args[0].split('|')[:2] @@ -579,19 +581,19 @@ class CommandCore: section = plugin_name option = args[1] value = args[2] - if not plugin_name in self.plugin_manager.plugins: - file_name = self.plugin_manager.plugins_conf_dir + if not plugin_name in self.core.plugin_manager.plugins: + file_name = self.core.plugin_manager.plugins_conf_dir file_name = os.path.join(file_name, plugin_name + '.cfg') plugin_config = PluginConfig(file_name, plugin_name) else: - plugin_config = self.plugin_manager.plugins[plugin_name].config + plugin_config = self.core.plugin_manager.plugins[plugin_name].config info = plugin_config.set_and_save(option, value, section) else: if args[0] == '.': - name = safeJID(self.current_tab().name).bare + name = safeJID(self.core.current_tab().name).bare if not name: - self.information('Invalid tab to use the "." argument.', - 'Error') + self.core.information('Invalid tab to use the "." argument.', + 'Error') return section = name else: @@ -599,13 +601,13 @@ class CommandCore: option = args[1] value = args[2] info = config.set_and_save(option, value, section) - self.trigger_configuration_change(option, value) + self.core.trigger_configuration_change(option, value) elif len(args) > 3: - return self.command_help('set') - self.information(*info) + return self.help('set') + self.core.information(*info) @command_args_parser.quoted(1, 2) - def command_set_default(self, args): + def set_default(self, args): """ /set_default [section] <option> """ @@ -616,33 +618,33 @@ class CommandCore: section = args[0] option = args[1] else: - return self.command_help('set_default') + return self.help('set_default') default_config = DEFAULT_CONFIG.get(section, tuple()) if option not in default_config: info = ("Option %s has no default value" % (option), "Error") - return self.information(*info) - self.command_set('%s %s %s' % (section, option, default_config[option])) + return self.core.information(*info) + self.set('%s %s %s' % (section, option, default_config[option])) @command_args_parser.quoted(1) - def command_toggle(self, args): + def toggle(self, args): """ /toggle <option> shortcut for /set <option> toggle """ if args is None: - return self.command_help('toggle') + return self.help('toggle') if args[0]: - self.command_set('%s toggle' % args[0]) + self.set('%s toggle' % args[0]) @command_args_parser.quoted(1, 1) - def command_server_cycle(self, args): + def server_cycle(self, args): """ Do a /cycle on each room of the given server. If none, do it on the current tab """ - tab = self.current_tab() + tab = self.core.current_tab() message = "" if args: domain = args[0] @@ -652,8 +654,8 @@ class CommandCore: if isinstance(tab, tabs.MucTab): domain = safeJID(tab.name).domain else: - return self.information("No server specified", "Error") - for tab in self.get_tabs(tabs.MucTab): + return self.core.information("No server specified", "Error") + for tab in self.core.get_tabs(tabs.MucTab): if tab.name.endswith(domain): if tab.joined: muc.leave_groupchat(tab.core.xmpp, @@ -662,12 +664,12 @@ class CommandCore: message) tab.joined = False if tab.name == domain: - self.command_join('"@%s/%s"' %(tab.name, tab.own_nick)) + self.join('"@%s/%s"' %(tab.name, tab.own_nick)) else: - self.command_join('"%s/%s"' %(tab.name, tab.own_nick)) + self.join('"%s/%s"' %(tab.name, tab.own_nick)) @command_args_parser.quoted(1) - def command_last_activity(self, args): + def last_activity(self, args): """ /last_activity <jid> """ @@ -675,11 +677,11 @@ class CommandCore: "Callback for the last activity" if iq['type'] != 'result': if iq['error']['type'] == 'auth': - self.information('You are not allowed to see the ' - 'activity of this contact.', - 'Error') + self.core.information('You are not allowed to see the ' + 'activity of this contact.', + 'Error') else: - self.information('Error retrieving the activity', 'Error') + self.core.information('Error retrieving the activity', 'Error') return seconds = iq['last_activity']['seconds'] status = iq['last_activity']['status'] @@ -693,48 +695,48 @@ class CommandCore: from_, common.parse_secs_to_str(seconds), (' and his/her last status was %s' % status) if status else '') - self.information(msg, 'Info') + self.core.information(msg, 'Info') if args is None: - return self.command_help('last_activity') + return self.help('last_activity') jid = safeJID(args[0]) - self.xmpp.plugin['xep_0012'].get_last_activity(jid, + self.core.xmpp.plugin['xep_0012'].get_last_activity(jid, callback=callback) @command_args_parser.quoted(0, 2) - def command_mood(self, args): + def mood(self, args): """ /mood [<mood> [text]] """ if not args: - return self.xmpp.plugin['xep_0107'].stop() + return self.core.xmpp.plugin['xep_0107'].stop() mood = args[0] if mood not in pep.MOODS: - return self.information('%s is not a correct value for a mood.' - % mood, - 'Error') + return self.core.information('%s is not a correct value for a mood.' + % mood, + 'Error') if len(args) == 2: text = args[1] else: text = None - self.xmpp.plugin['xep_0107'].publish_mood(mood, text, - callback=dumb_callback) + self.core.xmpp.plugin['xep_0107'].publish_mood(mood, text, + callback=dumb_callback) @command_args_parser.quoted(0, 3) - def command_activity(self, args): + def activity(self, args): """ /activity [<general> [specific] [text]] """ length = len(args) if not length: - return self.xmpp.plugin['xep_0108'].stop() + return self.core.xmpp.plugin['xep_0108'].stop() general = args[0] if general not in pep.ACTIVITIES: - return self.information('%s is not a correct value for an activity' - % general, - 'Error') + return self.core.information('%s is not a correct value for an activity' + % general, + 'Error') specific = None text = None if length == 2: @@ -746,123 +748,123 @@ class CommandCore: specific = args[1] text = args[2] if specific and specific not in pep.ACTIVITIES[general]: - return self.information('%s is not a correct value ' - 'for an activity' % specific, - 'Error') - self.xmpp.plugin['xep_0108'].publish_activity(general, specific, text, - callback=dumb_callback) + return self.core.information('%s is not a correct value ' + 'for an activity' % specific, + 'Error') + self.core.xmpp.plugin['xep_0108'].publish_activity(general, specific, text, + callback=dumb_callback) @command_args_parser.quoted(0, 2) - def command_gaming(self, args): + def gaming(self, args): """ /gaming [<game name> [server address]] """ if not args: - return self.xmpp.plugin['xep_0196'].stop() + return self.core.xmpp.plugin['xep_0196'].stop() name = args[0] if len(args) > 1: address = args[1] else: address = None - return self.xmpp.plugin['xep_0196'].publish_gaming(name=name, - server_address=address, - callback=dumb_callback) + return self.core.xmpp.plugin['xep_0196'].publish_gaming(name=name, + server_address=address, + callback=dumb_callback) @command_args_parser.quoted(2, 1, [None]) - def command_invite(self, args): + def invite(self, args): """/invite <to> <room> [reason]""" if args is None: - return self.command_help('invite') + return self.help('invite') reason = args[2] to = safeJID(args[0]) room = safeJID(args[1]).bare - self.invite(to.full, room, reason=reason) - self.information('Invited %s to %s' % (to.bare, room), 'Info') + self.core.invite(to.full, room, reason=reason) + self.core.information('Invited %s to %s' % (to.bare, room), 'Info') @command_args_parser.quoted(1, 1, ['']) - def command_decline(self, args): + def decline(self, args): """/decline <room@server.tld> [reason]""" if args is None: - return self.command_help('decline') + return self.help('decline') jid = safeJID(args[0]) - if jid.bare not in self.pending_invites: + if jid.bare not in self.core.pending_invites: return reason = args[1] - del self.pending_invites[jid.bare] - self.xmpp.plugin['xep_0045'].decline_invite(jid.bare, - self.pending_invites[jid.bare], - reason) + del self.core.pending_invites[jid.bare] + self.core.xmpp.plugin['xep_0045'].decline_invite(jid.bare, + self.core.pending_invites[jid.bare], + reason) ### Commands without a completion in this class ### @command_args_parser.ignored - def command_invitations(self): + def invitations(self): """/invitations""" build = "" - for invite in self.pending_invites: + for invite in self.core.pending_invites: build += "%s by %s" % (invite, - safeJID(self.pending_invites[invite]).bare) - if self.pending_invites: + safeJID(self.core.pending_invites[invite]).bare) + if self.core.pending_invites: build = "You are invited to the following rooms:\n" + build else: build = "You do not have any pending invitations." - self.information(build, 'Info') + self.core.information(build, 'Info') @command_args_parser.quoted(0, 1, [None]) - def command_quit(self, args): + def quit(self, args): """ /quit [message] """ - if not self.xmpp.is_connected(): - self.exit() + if not self.core.xmpp.is_connected(): + self.core.exit() return msg = args[0] if config.get('enable_user_mood'): - self.xmpp.plugin['xep_0107'].stop() + self.core.xmpp.plugin['xep_0107'].stop() if config.get('enable_user_activity'): - self.xmpp.plugin['xep_0108'].stop() + self.core.xmpp.plugin['xep_0108'].stop() if config.get('enable_user_gaming'): - self.xmpp.plugin['xep_0196'].stop() - self.save_config() - self.plugin_manager.disable_plugins() - self.disconnect(msg) - self.xmpp.add_event_handler("disconnected", self.exit, disposable=True) + self.core.xmpp.plugin['xep_0196'].stop() + self.core.save_config() + self.core.plugin_manager.disable_plugins() + self.core.disconnect(msg) + self.core.xmpp.add_event_handler("disconnected", self.core.exit, disposable=True) @command_args_parser.quoted(0, 1, ['']) - def command_destroy_room(self, args): + def destroy_room(self, args): """ /destroy_room [JID] """ room = safeJID(args[0]).bare if room: - muc.destroy_room(self.xmpp, room) - elif isinstance(self.current_tab(), tabs.MucTab) and not args[0]: - muc.destroy_room(self.xmpp, self.current_tab().general_jid) + muc.destroy_room(self.core.xmpp, room) + elif isinstance(self.core.current_tab(), tabs.MucTab) and not args[0]: + muc.destroy_room(self.core.xmpp, self.core.current_tab().general_jid) else: - self.information('Invalid JID: "%s"' % args[0], 'Error') + self.core.information('Invalid JID: "%s"' % args[0], 'Error') @command_args_parser.quoted(1, 1, ['']) - def command_bind(self, args): + def bind(self, args): """ Bind a key. """ if args is None: - return self.command_help('bind') + return self.help('bind') if not config.silent_set(args[0], args[1], section='bindings'): - self.information('Unable to write in the config file', 'Error') + self.core.information('Unable to write in the config file', 'Error') if args[1]: - self.information('%s is now bound to %s' % (args[0], args[1]), 'Info') + self.core.information('%s is now bound to %s' % (args[0], args[1]), 'Info') else: - self.information('%s is now unbound' % args[0], 'Info') + self.core.information('%s is now unbound' % args[0], 'Info') @command_args_parser.raw - def command_rawxml(self, args): + def rawxml(self, args): """ /rawxml <xml stanza> """ @@ -872,19 +874,19 @@ class CommandCore: stanza = args try: - stanza = StanzaBase(self.xmpp, xml=ET.fromstring(stanza)) + stanza = StanzaBase(self.core.xmpp, xml=ET.fromstring(stanza)) if stanza.xml.tag == 'iq' and stanza.xml.attrib.get('type') in ('get', 'set'): iq_id = stanza.xml.attrib.get('id') if not iq_id: - iq_id = self.xmpp.new_id() + iq_id = self.core.xmpp.new_id() stanza['id'] = iq_id def iqfunc(iq): "handler for an iq reply" - self.information('%s' % iq, 'Iq') - self.xmpp.remove_handler('Iq %s' % iq_id) + self.core.information('%s' % iq, 'Iq') + self.core.xmpp.remove_handler('Iq %s' % iq_id) - self.xmpp.register_handler( + self.core.xmpp.register_handler( Callback('Iq %s' % iq_id, StanzaPath('iq@id=%s' % iq_id), iqfunc @@ -895,92 +897,92 @@ class CommandCore: stanza.send() except: - self.information('Could not send custom stanza', 'Error') + self.core.information('Could not send custom stanza', 'Error') log.debug('/rawxml: Could not send custom stanza (%s)', - repr(stanza), - exc_info=True) + repr(stanza), + exc_info=True) @command_args_parser.quoted(1, 256) - def command_load(self, args): + def load(self, args): """ /load <plugin> [<otherplugin> …] # TODO: being able to load more than 256 plugins at once, hihi. """ for plugin in args: - self.plugin_manager.load(plugin) + self.core.plugin_manager.load(plugin) @command_args_parser.quoted(1, 256) - def command_unload(self, args): + def unload(self, args): """ /unload <plugin> [<otherplugin> …] """ for plugin in args: - self.plugin_manager.unload(plugin) + self.core.plugin_manager.unload(plugin) @command_args_parser.ignored - def command_plugins(self): + def plugins(self): """ /plugins """ - self.information("Plugins currently in use: %s" % - repr(list(self.plugin_manager.plugins.keys())), - 'Info') + self.core.information("Plugins currently in use: %s" % + repr(list(self.core.plugin_manager.plugins.keys())), + 'Info') @command_args_parser.quoted(1, 1) - def command_message(self, args): + def message(self, args): """ /message <jid> [message] """ if args is None: - return self.command_help('message') + return self.help('message') jid = safeJID(args[0]) if not jid.user and not jid.domain and not jid.resource: - return self.information('Invalid JID.', 'Error') - tab = self.get_conversation_by_jid(jid.full, False, fallback_barejid=False) - muc = self.get_tab_by_name(jid.bare, typ=tabs.MucTab) + return self.core.information('Invalid JID.', 'Error') + tab = self.core.get_conversation_by_jid(jid.full, False, fallback_barejid=False) + muc = self.core.get_tab_by_name(jid.bare, typ=tabs.MucTab) if not tab and not muc: - tab = self.open_conversation_window(jid.full, focus=True) + tab = self.core.open_conversation_window(jid.full, focus=True) elif muc: - tab = self.get_tab_by_name(jid.full, typ=tabs.PrivateTab) + tab = self.core.get_tab_by_name(jid.full, typ=tabs.PrivateTab) if tab: - self.focus_tab_named(tab.name) + self.core.focus_tab_named(tab.name) else: - tab = self.open_private_window(jid.bare, jid.resource) + tab = self.core.open_private_window(jid.bare, jid.resource) else: - self.focus_tab_named(tab.name) + self.core.focus_tab_named(tab.name) if len(args) == 2: tab.command_say(args[1]) @command_args_parser.ignored - def command_xml_tab(self): + def xml_tab(self): """/xml_tab""" - xml_tab = self.focus_tab_named('XMLTab', tabs.XMLTab) + xml_tab = self.core.focus_tab_named('XMLTab', tabs.XMLTab) if not xml_tab: tab = tabs.XMLTab() - self.add_tab(tab, True) - self.xml_tab = tab + self.core.add_tab(tab, True) + self.core.xml_tab = tab @command_args_parser.quoted(1) - def command_adhoc(self, args): + def adhoc(self, args): if not args: - return self.command_help('ad-hoc') + return self.help('ad-hoc') jid = safeJID(args[0]) list_tab = tabs.AdhocCommandsListTab(jid) - self.add_tab(list_tab, True) + self.core.add_tab(list_tab, True) cb = list_tab.on_list_received - self.xmpp.plugin['xep_0050'].get_commands(jid=jid, local=False, - callback=cb) + self.core.xmpp.plugin['xep_0050'].get_commands(jid=jid, local=False, + callback=cb) @command_args_parser.ignored - def command_self(self): + def self(self_): """ /self """ - status = self.get_status() + status = self_.core.get_status() show, message = status.show, status.message - nick = self.own_nick - jid = self.xmpp.boundjid.full + nick = self_.core.own_nick + jid = self_.core.xmpp.boundjid.full info = ('Your JID is %s\nYour current status is "%s" (%s)' '\nYour default nickname is %s\nYou are running poezio %s' % ( jid, @@ -988,16 +990,16 @@ class CommandCore: show if show else 'available', nick, config_opts.version)) - self.information(info, 'Info') + self_.core.information(info, 'Info') @command_args_parser.ignored - def command_reload(self): + def reload(self): """ /reload """ - self.reload_config() + self.core.reload_config() - def dumb_callback(*args, **kwargs): - "mock callback" +def dumb_callback(*args, **kwargs): + "mock callback" diff --git a/poezio/core/core.py b/poezio/core/core.py index e4cc2340..cccc1dd0 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -43,7 +43,7 @@ from theming import get_theme import keyboard from . completions import CompletionCore -from . import commands +from . commands import CommandCore from . import handlers from . structs import POSSIBLE_SHOW, DEPRECATED_ERRORS, \ ERROR_AND_STATUS_CODES, Command, Status @@ -56,6 +56,7 @@ class Core(object): def __init__(self): self.completion = CompletionCore(self) + self.command = CommandCore(self) # All uncaught exception are given to this callback, instead # of being displayed on the screen and exiting the program. sys.excepthook = self.on_exception @@ -162,14 +163,14 @@ class Core(object): 'M-C': self.scroll_info_down, 'M-k': self.escape_next_key, ######## actions mappings ########## - '_bookmark': self.command_bookmark, - '_bookmark_local': self.command_bookmark_local, + '_bookmark': self.command.bookmark, + '_bookmark_local': self.command.bookmark_local, '_close_tab': self.close_tab, '_disconnect': self.disconnect, - '_quit': self.command_quit, + '_quit': self.command.quit, '_redraw_screen': self.full_screen_redraw, - '_reload_theme': self.command_theme, - '_remove_bookmark': self.command_remove_bookmark, + '_reload_theme': self.command.theme, + '_remove_bookmark': self.command.remove_bookmark, '_room_left': self.rotate_rooms_left, '_room_right': self.rotate_rooms_right, '_show_roster': self.go_to_roster, @@ -177,19 +178,19 @@ class Core(object): '_scroll_up': self.scroll_page_up, '_scroll_info_up': self.scroll_info_up, '_scroll_info_down': self.scroll_info_down, - '_server_cycle': self.command_server_cycle, - '_show_bookmarks': self.command_bookmarks, + '_server_cycle': self.command.server_cycle, + '_show_bookmarks': self.command.bookmarks, '_show_important_room': self.go_to_important_room, - '_show_invitations': self.command_invitations, - '_show_plugins': self.command_plugins, - '_show_xmltab': self.command_xml_tab, + '_show_invitations': self.command.invitations, + '_show_plugins': self.command.plugins, + '_show_xmltab': self.command.xml_tab, '_toggle_pane': self.toggle_left_pane, ###### status actions ###### - '_available': lambda: self.command_status('available'), - '_away': lambda: self.command_status('away'), - '_chat': lambda: self.command_status('chat'), - '_dnd': lambda: self.command_status('dnd'), - '_xa': lambda: self.command_status('xa'), + '_available': lambda: self.command.status('available'), + '_away': lambda: self.command.status('away'), + '_chat': lambda: self.command.status('chat'), + '_dnd': lambda: self.command.status('dnd'), + '_xa': lambda: self.command.status('xa'), ##### Custom actions ######## '_exc_': self.try_execute, } @@ -645,7 +646,7 @@ class Core(object): if self.current_tab().nb == nb and config.get('go_to_previous_tab_on_alt_number'): self.go_to_previous_tab() else: - self.command_win('%d' % nb) + self.command.win('%d' % nb) # search for keyboard shortcut func = self.key_func.get(char, None) if func: @@ -1021,7 +1022,7 @@ class Core(object): """ self.tabs.append(new_tab) if focus: - self.command_win("%s" % new_tab.nb) + self.command.win("%s" % new_tab.nb) def insert_tab_nogaps(self, old_pos, new_pos): """ @@ -1141,7 +1142,7 @@ class Core(object): if len(self.room_number_jump) == 2: arg = "".join(self.room_number_jump) self.room_number_jump.clear() - self.command_win(arg) + self.command.win(arg) else: # We need to read more digits keyboard.continuation_keys_callback = read_next_digit @@ -1149,11 +1150,11 @@ class Core(object): def go_to_roster(self): "Select the roster as the current tab" - self.command_win('0') + self.command.win('0') def go_to_previous_tab(self): "Go to the previous tab" - self.command_win('%s' % (self.previous_tab_nb,)) + self.command.win('%s' % (self.previous_tab_nb,)) def go_to_important_room(self): """ @@ -1182,7 +1183,7 @@ class Core(object): if (tab.nb < self.current_tab_nb and tab_refs[state][-1].nb > self.current_tab_nb): continue - self.command_win('%s' % tab.nb) + self.command.win('%s' % tab.nb) return return @@ -1191,7 +1192,7 @@ class Core(object): for tab in self.tabs: if tab.name == tab_name: if (type_ and (isinstance(tab, type_))) or not type_: - self.command_win('%s' % (tab.nb,)) + self.command.win('%s' % (tab.nb,)) return True return False @@ -1242,7 +1243,7 @@ class Core(object): # if the room exists, focus it and return for tab in self.get_tabs(tabs.PrivateTab): if tab.name == complete_jid: - self.command_win('%s' % tab.nb) + self.command.win('%s' % tab.nb) return tab # create the new tab tab = self.get_tab_by_name(room_name, tabs.MucTab) @@ -1727,11 +1728,11 @@ class Core(object): """ Register the commands when poezio starts """ - self.register_command('help', self.command_help, + self.register_command('help', self.command.help, usage='[command]', shortdesc='\\_o< KOIN KOIN KOIN', completion=self.completion.help) - self.register_command('join', self.command_join, + self.register_command('join', self.command.join, usage="[room_name][@server][/nick] [password]", desc="Join the specified room. You can specify a nickname " "after a slash (/). If no nickname is specified, you will" @@ -1746,22 +1747,22 @@ class Core(object): ".tld/my_nick password\n/join / password", shortdesc='Join a room', completion=self.completion.join) - self.register_command('exit', self.command_quit, + self.register_command('exit', self.command.quit, desc='Just disconnect from the server and exit poezio.', shortdesc='Exit poezio.') - self.register_command('quit', self.command_quit, + self.register_command('quit', self.command.quit, desc='Just disconnect from the server and exit poezio.', shortdesc='Exit poezio.') self.register_command('next', self.rotate_rooms_right, shortdesc='Go to the next room.') self.register_command('prev', self.rotate_rooms_left, shortdesc='Go to the previous room.') - self.register_command('win', self.command_win, + self.register_command('win', self.command.win, usage='<number or name>', shortdesc='Go to the specified room', completion=self.completion.win) self.commands['w'] = self.commands['win'] - self.register_command('move_tab', self.command_move_tab, + self.register_command('move_tab', self.command.move_tab, usage='<source> <destination>', desc="Insert the <source> tab at the position of " "<destination>. This will make the following tabs shift in" @@ -1771,14 +1772,14 @@ class Core(object): "tab.", shortdesc='Move a tab.', completion=self.completion.move_tab) - self.register_command('destroy_room', self.command_destroy_room, + self.register_command('destroy_room', self.command.destroy_room, usage='[room JID]', desc='Try to destroy the room [room JID], or the current' ' tab if it is a multi-user chat and [room JID] is ' 'not given.', shortdesc='Destroy a room.', completion=None) - self.register_command('show', self.command_status, + self.register_command('show', self.command.status, usage='<availability> [status message]', desc="Sets your availability and (optionally) your status " "message. The <availability> argument is one of \"available" @@ -1787,7 +1788,7 @@ class Core(object): shortdesc='Change your availability.', completion=self.completion.status) self.commands['status'] = self.commands['show'] - self.register_command('bookmark_local', self.command_bookmark_local, + self.register_command('bookmark_local', self.command.bookmark_local, usage="[roomname][/nick] [password]", desc="Bookmark Local: Bookmark locally the specified room " "(you will then auto-join it on each poezio start). This" @@ -1798,7 +1799,7 @@ class Core(object): "(instead of default_nick)", shortdesc='Bookmark a room locally.', completion=self.completion.bookmark_local) - self.register_command('bookmark', self.command_bookmark, + self.register_command('bookmark', self.command.bookmark, usage="[roomname][/nick] [autojoin] [password]", desc="Bookmark: Bookmark online the specified room (you " "will then auto-join it on each poezio start if autojoin" @@ -1809,7 +1810,7 @@ class Core(object): "currently using in this room (instead of default_nick).", shortdesc="Bookmark a room online.", completion=self.completion.bookmark) - self.register_command('set', self.command_set, + self.register_command('set', self.command.set, usage="[plugin|][section] <option> [value]", desc="Set the value of an option in your configuration file." " You can, for example, change your default nickname by " @@ -1820,7 +1821,7 @@ class Core(object): "used as a special value to toggle a boolean option.", shortdesc="Set the value of an option", completion=self.completion.set) - self.register_command('set_default', self.command_set_default, + self.register_command('set_default', self.command.set_default, usage="[section] <option>", desc="Set the default value of an option. For example, " "`/set_default resource` will reset the resource " @@ -1828,104 +1829,104 @@ class Core(object): "sections by doing `/set_default section option`.", shortdesc="Set the default value of an option", completion=self.completion.set_default) - self.register_command('toggle', self.command_toggle, + self.register_command('toggle', self.command.toggle, usage='<option>', desc='Shortcut for /set <option> toggle', shortdesc='Toggle an option', completion=self.completion.toggle) - self.register_command('theme', self.command_theme, + self.register_command('theme', self.command.theme, usage='[theme name]', desc="Reload the theme defined in the config file. If theme" "_name is provided, set that theme before reloading it.", shortdesc='Load a theme', completion=self.completion.theme) - self.register_command('list', self.command_list, + self.register_command('list', self.command.list, usage='[server]', desc="Get the list of public chatrooms" " on the specified server.", shortdesc='List the rooms.', completion=self.completion.list) - self.register_command('message', self.command_message, + self.register_command('message', self.command.message, usage='<jid> [optional message]', desc="Open a conversation with the specified JID (even if it" " is not in our roster), and send a message to it, if the " "message is specified.", shortdesc='Send a message', completion=self.completion.message) - self.register_command('version', self.command_version, + self.register_command('version', self.command.version, usage='<jid>', desc="Get the software version of the given JID (usually its" " XMPP client and Operating System).", shortdesc='Get the software version of a JID.', completion=self.completion.version) - self.register_command('server_cycle', self.command_server_cycle, + self.register_command('server_cycle', self.command.server_cycle, usage='[domain] [message]', desc='Disconnect and reconnect in all the rooms in domain.', shortdesc='Cycle a range of rooms', completion=self.completion.server_cycle) - self.register_command('bind', self.command_bind, + self.register_command('bind', self.command.bind, usage='<key> <equ>', desc="Bind a key to another key or to a “command”. For " "example \"/bind ^H KEY_UP\" makes Control + h do the" " same same as the Up key.", completion=self.completion.bind, shortdesc='Bind a key to another key.') - self.register_command('load', self.command_load, + self.register_command('load', self.command.load, usage='<plugin> [<otherplugin> …]', shortdesc='Load the specified plugin(s)', completion=self.plugin_manager.completion_load) - self.register_command('unload', self.command_unload, + self.register_command('unload', self.command.unload, usage='<plugin> [<otherplugin> …]', shortdesc='Unload the specified plugin(s)', completion=self.plugin_manager.completion_unload) - self.register_command('plugins', self.command_plugins, + self.register_command('plugins', self.command.plugins, shortdesc='Show the plugins in use.') - self.register_command('presence', self.command_presence, + self.register_command('presence', self.command.presence, usage='<JID> [type] [status]', desc="Send a directed presence to <JID> and using" " [type] and [status] if provided.", shortdesc='Send a directed presence.', completion=self.completion.presence) - self.register_command('rawxml', self.command_rawxml, + self.register_command('rawxml', self.command.rawxml, usage='<xml>', shortdesc='Send a custom xml stanza.') - self.register_command('invite', self.command_invite, + self.register_command('invite', self.command.invite, usage='<jid> <room> [reason]', desc='Invite jid in room with reason.', shortdesc='Invite someone in a room.', completion=self.completion.invite) - self.register_command('invitations', self.command_invitations, + self.register_command('invitations', self.command.invitations, shortdesc='Show the pending invitations.') - self.register_command('bookmarks', self.command_bookmarks, + self.register_command('bookmarks', self.command.bookmarks, shortdesc='Show the current bookmarks.') - self.register_command('remove_bookmark', self.command_remove_bookmark, + self.register_command('remove_bookmark', self.command.remove_bookmark, usage='[jid]', desc="Remove the specified bookmark, or the " "bookmark on the current tab, if any.", shortdesc='Remove a bookmark', completion=self.completion.remove_bookmark) - self.register_command('xml_tab', self.command_xml_tab, + self.register_command('xml_tab', self.command.xml_tab, shortdesc='Open an XML tab.') - self.register_command('runkey', self.command_runkey, + self.register_command('runkey', self.command.runkey, usage='<key>', shortdesc='Execute the action defined for <key>.', completion=self.completion.runkey) - self.register_command('self', self.command_self, + self.register_command('self', self.command.self, shortdesc='Remind you of who you are.') - self.register_command('last_activity', self.command_last_activity, + self.register_command('last_activity', self.command.last_activity, usage='<jid>', desc='Informs you of the last activity of a JID.', shortdesc='Get the activity of someone.', completion=self.completion.last_activity) - self.register_command('ad-hoc', self.command_adhoc, + self.register_command('ad-hoc', self.command.adhoc, usage='<jid>', shortdesc='List available ad-hoc commands on the given jid') - self.register_command('reload', self.command_reload, + self.register_command('reload', self.command.reload, shortdesc='Reload the config. You can achieve the same by ' 'sending SIGUSR1 to poezio.') if config.get('enable_user_activity'): - self.register_command('activity', self.command_activity, + self.register_command('activity', self.command.activity, usage='[<general> [specific] [text]]', desc='Send your current activity to your contacts ' '(use the completion). Nothing means ' @@ -1933,7 +1934,7 @@ class Core(object): shortdesc='Send your activity.', completion=self.completion.activity) if config.get('enable_user_mood'): - self.register_command('mood', self.command_mood, + self.register_command('mood', self.command.mood, usage='[<mood> [text]]', desc='Send your current mood to your contacts ' '(use the completion). Nothing means ' @@ -1941,7 +1942,7 @@ class Core(object): shortdesc='Send your mood.', completion=self.completion.mood) if config.get('enable_user_gaming'): - self.register_command('gaming', self.command_gaming, + self.register_command('gaming', self.command.gaming, usage='[<game name> [server address]]', desc='Send your current gaming activity to ' 'your contacts. Nothing means "stop ' @@ -2012,43 +2013,6 @@ class Core(object): cancel_adhoc_command = handlers.cancel_adhoc_command validate_adhoc_step = handlers.validate_adhoc_step terminate_adhoc_command = handlers.terminate_adhoc_command - command_help = commands.command_help - command_runkey = commands.command_runkey - command_status = commands.command_status - command_presence = commands.command_presence - command_theme = commands.command_theme - command_win = commands.command_win - command_move_tab = commands.command_move_tab - command_list = commands.command_list - command_version = commands.command_version - command_join = commands.command_join - command_bookmark_local = commands.command_bookmark_local - command_bookmark = commands.command_bookmark - command_bookmarks = commands.command_bookmarks - command_destroy_room = commands.command_destroy_room - command_remove_bookmark = commands.command_remove_bookmark - command_set = commands.command_set - command_set_default = commands.command_set_default - command_toggle = commands.command_toggle - command_server_cycle = commands.command_server_cycle - command_last_activity = commands.command_last_activity - command_mood = commands.command_mood - command_activity = commands.command_activity - command_gaming = commands.command_gaming - command_invite = commands.command_invite - command_decline = commands.command_decline - command_invitations = commands.command_invitations - command_quit = commands.command_quit - command_bind = commands.command_bind - command_rawxml = commands.command_rawxml - command_load = commands.command_load - command_unload = commands.command_unload - command_plugins = commands.command_plugins - command_message = commands.command_message - command_xml_tab = commands.command_xml_tab - command_adhoc = commands.command_adhoc - command_self = commands.command_self - command_reload = commands.command_reload diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py index 5f0bc138..29da6fea 100644 --- a/poezio/tabs/basetabs.py +++ b/poezio/tabs/basetabs.py @@ -648,7 +648,7 @@ class ChatTab(Tab): /correct <fixed message> """ if not line: - self.core.command_help('correct') + self.core.command.help('correct') return if not self.last_sent_message: self.core.information('There is no message to correct.') diff --git a/poezio/tabs/conversationtab.py b/poezio/tabs/conversationtab.py index dd93bcd5..5451520f 100644 --- a/poezio/tabs/conversationtab.py +++ b/poezio/tabs/conversationtab.py @@ -155,7 +155,7 @@ class ConversationTab(OneToOneTab): /last_activity [jid] """ if args and args[0]: - return self.core.command_last_activity(args[0]) + return self.core.command.last_activity(args[0]) def callback(iq): if iq['type'] != 'result': @@ -223,7 +223,7 @@ class ConversationTab(OneToOneTab): res.get('os') or 'an unknown platform') self.core.information(version, 'Info') if args: - return self.core.command_version(args[0]) + return self.core.command.version(args[0]) jid = safeJID(self.name) if not jid.resource: if jid in roster: diff --git a/poezio/tabs/muclisttab.py b/poezio/tabs/muclisttab.py index 92d55190..0013fc9a 100644 --- a/poezio/tabs/muclisttab.py +++ b/poezio/tabs/muclisttab.py @@ -66,5 +66,5 @@ class MucListTab(ListTab): row = self.listview.get_selected_row() if not row: return - self.core.command_join(row[1]) + self.core.command.join(row[1]) diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 1f3ec6d8..28161a6d 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -326,9 +326,9 @@ class MucTab(ChatTab): def command_invite(self, args): """/invite <jid> [reason]""" if args is None: - return self.core.command_help('invite') + return self.core.command.help('invite') jid, reason = args - self.core.command_invite('%s %s "%s"' % (jid, self.name, reason)) + self.core.command.invite('%s %s "%s"' % (jid, self.name, reason)) def completion_invite(self, the_input): """Completion for /invite""" @@ -352,7 +352,7 @@ class MucTab(ChatTab): /info <nick> """ if args is None: - return self.core.command_help('info') + return self.core.command.help('info') nick = args[0] user = self.get_user_by_name(nick) if not user: @@ -494,7 +494,7 @@ class MucTab(ChatTab): User "random" to attribute a random color. """ if args is None: - return self.core.command_help('color') + return self.core.command.help('color') nick = args[0] color = args[1].lower() user = self.get_user_by_name(nick) @@ -544,7 +544,7 @@ class MucTab(ChatTab): res.get('os') or 'an unknown platform') self.core.information(version, 'Info') if args is None: - return self.core.command_help('version') + return self.core.command.help('version') nick = args[0] if nick in [user.nick for user in self.users]: jid = safeJID(self.name).bare @@ -560,7 +560,7 @@ class MucTab(ChatTab): /nick <nickname> """ if args is None: - return self.core.command_help('nick') + return self.core.command.help('nick') nick = args[0] if not self.joined: return self.core.information('/nick only works in joined rooms', @@ -632,7 +632,7 @@ class MucTab(ChatTab): /query <nick> [message] """ if args is None: - return self.core.command_help('query') + return self.core.command.help('query') nick = args[0] r = None for user in self.users: @@ -719,7 +719,7 @@ class MucTab(ChatTab): /kick <nick> [reason] """ if args is None: - return self.core.command_help('kick') + return self.core.command.help('kick') if len(args) == 2: msg = ' "%s"' % args[1] else: @@ -735,7 +735,7 @@ class MucTab(ChatTab): if iq['type'] == 'error': self.core.room_error(iq, self.name) if args is None: - return self.core.command_help('ban') + return self.core.command.help('ban') if len(args) > 1: msg = args[1] else: @@ -765,7 +765,7 @@ class MucTab(ChatTab): self.core.room_error(iq, self.name) if args is None: - return self.core.command_help('role') + return self.core.command.help('role') nick, role, reason = args[0], args[1].lower(), args[2] @@ -792,7 +792,7 @@ class MucTab(ChatTab): self.core.room_error(iq, self.name) if args is None: - return self.core.command_help('affiliation') + return self.core.command.help('affiliation') nick, affiliation = args[0], args[1].lower() @@ -867,7 +867,7 @@ class MucTab(ChatTab): /ignore <nick> """ if args is None: - return self.core.command_help('ignore') + return self.core.command.help('ignore') nick = args[0] user = self.get_user_by_name(nick) @@ -885,7 +885,7 @@ class MucTab(ChatTab): /unignore <nick> """ if args is None: - return self.core.command_help('unignore') + return self.core.command.help('unignore') nick = args[0] user = self.get_user_by_name(nick) diff --git a/poezio/tabs/privatetab.py b/poezio/tabs/privatetab.py index a715a922..e12f9fde 100644 --- a/poezio/tabs/privatetab.py +++ b/poezio/tabs/privatetab.py @@ -204,7 +204,7 @@ class PrivateTab(OneToOneTab): res.get('os') or 'an unknown platform') self.core.information(version, 'Info') if args: - return self.core.command_version(args[0]) + return self.core.command.version(args[0]) jid = safeJID(self.name) fixes.get_version(self.core.xmpp, jid, callback=callback) diff --git a/poezio/tabs/rostertab.py b/poezio/tabs/rostertab.py index f81d7ad0..f628d055 100644 --- a/poezio/tabs/rostertab.py +++ b/poezio/tabs/rostertab.py @@ -230,7 +230,7 @@ class RosterInfoTab(Tab): /cert_add <name> <certfile> [cert-management] """ if not args or len(args) < 2: - return self.core.command_help('cert_add') + return self.core.command.help('cert_add') def cb(iq): if iq['type'] == 'error': self.core.information('Unable to add the certificate.', 'Error') @@ -284,7 +284,7 @@ class RosterInfoTab(Tab): /cert_disable <name> """ if not args: - return self.core.command_help('cert_disable') + return self.core.command.help('cert_disable') def cb(iq): if iq['type'] == 'error': self.core.information('Unable to disable the certificate.', 'Error') @@ -301,7 +301,7 @@ class RosterInfoTab(Tab): /cert_revoke <name> """ if not args: - return self.core.command_help('cert_revoke') + return self.core.command.help('cert_revoke') def cb(iq): if iq['type'] == 'error': self.core.information('Unable to revoke the certificate.', 'Error') @@ -319,7 +319,7 @@ class RosterInfoTab(Tab): /cert_fetch <name> <path> """ if not args or len(args) < 2: - return self.core.command_help('cert_fetch') + return self.core.command.help('cert_fetch') def cb(iq): if iq['type'] == 'error': self.core.information('Unable to fetch the certificate.', @@ -485,7 +485,7 @@ class RosterInfoTab(Tab): else: self.core.information('No JID selected.', 'Error') return - self.core.command_last_activity(jid) + self.core.command.last_activity(jid) def resize(self): self.need_resize = False @@ -646,7 +646,7 @@ class RosterInfoTab(Tab): self.core.information('The name could not be set.', 'Error') log.debug('Error in /name:\n%s', iq) if args is None: - return self.core.command_help('name') + return self.core.command.help('name') jid = safeJID(args[0]).bare name = args[1] if len(args) == 2 else '' @@ -668,7 +668,7 @@ class RosterInfoTab(Tab): Add the specified JID to the specified group """ if args is None: - return self.core.command_help('groupadd') + return self.core.command.help('groupadd') jid = safeJID(args[0]).bare group = args[1] @@ -708,7 +708,7 @@ class RosterInfoTab(Tab): Remove the specified JID from the first specified group and add it to the second one """ if args is None: - return self.core.command_help('groupmove') + return self.core.command.help('groupmove') jid = safeJID(args[0]).bare group_from = args[1] group_to = args[2] @@ -763,7 +763,7 @@ class RosterInfoTab(Tab): Remove the specified JID from the specified group """ if args is None: - return self.core.command_help('groupremove') + return self.core.command.help('groupremove') jid = safeJID(args[0]).bare group = args[1] @@ -1125,9 +1125,9 @@ class RosterInfoTab(Tab): selected_row = self.roster_win.get_selected_row() if isinstance(selected_row, Contact): for resource in selected_row.resources: - self.core.command_version(str(resource.jid)) + self.core.command.version(str(resource.jid)) elif isinstance(selected_row, Resource): - self.core.command_version(str(selected_row.jid)) + self.core.command.version(str(selected_row.jid)) else: self.core.information('Nothing to get versions from', 'Info') diff --git a/poezio/tabs/xmltab.py b/poezio/tabs/xmltab.py index b063ad35..331c1558 100644 --- a/poezio/tabs/xmltab.py +++ b/poezio/tabs/xmltab.py @@ -203,7 +203,7 @@ class XMLTab(Tab): def command_filter_id(self, args): """/filter_id <id>""" if args is None: - return self.core.command_help('filter_id') + return self.core.command.help('filter_id') self.update_filters(matcher.MatcherId(args[0])) self.refresh() @@ -234,7 +234,7 @@ class XMLTab(Tab): def command_dump(self, args): """/dump <filename>""" if args is None: - return self.core.command_help('dump') + return self.core.command.help('dump') if self.filters: xml = self.filtered_buffer.messages[:] else: |