From 7a1b2b982f431eb591d348fbb799a4d761a13c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 28 Apr 2019 01:02:49 +0100 Subject: plugins: Update use of tab.name to tab.jid where appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- plugins/dice.py | 2 +- plugins/irc.py | 2 +- plugins/marquee.py | 2 +- plugins/otr.py | 18 +++++++++--------- plugins/ping.py | 10 +++++++--- plugins/reorder.py | 2 +- plugins/replace.py | 4 ++-- plugins/server_part.py | 4 ++-- plugins/tell.py | 2 +- plugins/time_marker.py | 6 +++--- plugins/vcard.py | 10 ++++++---- 11 files changed, 34 insertions(+), 28 deletions(-) diff --git a/plugins/dice.py b/plugins/dice.py index 376ed26a..55fd87a7 100644 --- a/plugins/dice.py +++ b/plugins/dice.py @@ -95,7 +95,7 @@ class Plugin(BasePlugin): is_muctab = isinstance(tab, tabs.MucTab) msg_id = tab.last_sent_message["id"] increment = self.config.get('refresh') - roll = DiceRoll(duration, num_dice, is_muctab, tab.name, msg_id, + roll = DiceRoll(duration, num_dice, is_muctab, tab.jid, msg_id, increment) event = self.api.create_delayed_event(increment, self.delayed_event, roll) diff --git a/plugins/irc.py b/plugins/irc.py index eeef128c..9d981c91 100644 --- a/plugins/irc.py +++ b/plugins/irc.py @@ -376,7 +376,7 @@ class Plugin(BasePlugin): """ gateway = self.config.get('gateway', 'irc.poez.io') current = self.api.current_tab() - current_jid = common.safeJID(current.name) + current_jid = current.jid if not current_jid.server == gateway: self.api.information( 'The current tab does not appear to be an IRC one', 'Warning') diff --git a/plugins/marquee.py b/plugins/marquee.py index bad06301..60566b0d 100644 --- a/plugins/marquee.py +++ b/plugins/marquee.py @@ -68,7 +68,7 @@ class Plugin(BasePlugin): tab.command_say(args) is_muctab = isinstance(tab, tabs.MucTab) msg_id = tab.last_sent_message["id"] - jid = tab.name + jid = tab.jid event = self.api.create_delayed_event( self.config.get("refresh"), self.delayed_event, jid, args, msg_id, diff --git a/plugins/otr.py b/plugins/otr.py index 909a4ea5..2ddc332b 100644 --- a/plugins/otr.py +++ b/plugins/otr.py @@ -325,7 +325,7 @@ def hl(tab): if tab.state != 'current': tab.state = 'private' - conv_jid = safeJID(tab.name) + conv_jid = tab.jid if 'private' in config.get('beep_on', 'highlight private').split(): if not config.get_by_tabname( 'disable_beep', conv_jid.bare, default=False): @@ -806,7 +806,7 @@ class Plugin(BasePlugin): On message sent """ name = tab.name - jid = safeJID(tab.name) + jid = tab.jid format_dict = { 'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID), @@ -846,7 +846,7 @@ class Plugin(BasePlugin): elif not is_relevant(tab) and ctx and ( ctx.state == STATE_ENCRYPTED or ctx.getPolicy('REQUIRE_ENCRYPTION')): - contact = roster[tab.name] + contact = roster[tab.jid.bare] res = [] if contact: res = [resource.jid for resource in contact.resources] @@ -884,13 +884,13 @@ class Plugin(BasePlugin): return self.core.command.help('otr') action = args.pop(0) tab = self.api.current_tab() - name = tab.name + name = tab.jid.full format_dict = { 'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID), 'info': '\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT), 'normal': '\x19%s}' % dump_tuple(get_theme().COLOR_NORMAL_TEXT), - 'jid': name, - 'bare_jid': safeJID(name).bare + 'jid': tab.jid.full, + 'bare_jid': tab.jid.bare, } if action == 'end': # close the session @@ -991,12 +991,12 @@ class Plugin(BasePlugin): question = secret = None tab = self.api.current_tab() - name = tab.name + name = tab.jid.full format_dict = { 'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID), 'info': '\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT), - 'jid': name, - 'bare_jid': safeJID(name).bare + 'jid': tab.jid.full, + 'bare_jid': tab.jid.bare, } ctx = self.get_context(name) diff --git a/plugins/ping.py b/plugins/ping.py index 4868ccf9..b9bad4fe 100644 --- a/plugins/ping.py +++ b/plugins/ping.py @@ -22,6 +22,7 @@ Command the current interlocutor. """ +from slixmpp import InvalidJID from poezio.decorators import command_args_parser from poezio.plugin import BasePlugin from poezio.roster import roster @@ -116,7 +117,7 @@ class Plugin(BasePlugin): def command_private_ping(self, arg): if arg: return self.command_ping(arg) - self.command_ping(self.api.current_tab().name) + self.command_ping(self.api.current_tab().jid) @command_args_parser.raw def command_muc_ping(self, arg): @@ -124,10 +125,13 @@ class Plugin(BasePlugin): return user = self.api.current_tab().get_user_by_name(arg) if user: - jid = safeJID(self.api.current_tab().name) + jid = self.api.current_tab().jid jid.resource = user.nick else: - jid = safeJID(arg) + try: + jid = JID(arg) + except InvalidJID: + return self.api.information('Invalid JID: %s' % arg, 'Error') self.command_ping(jid.full) @command_args_parser.raw diff --git a/plugins/reorder.py b/plugins/reorder.py index 7308196d..32fa6639 100644 --- a/plugins/reorder.py +++ b/plugins/reorder.py @@ -112,7 +112,7 @@ def parse_runtime_tablist(tablist): i += 1 result = check_tab(tab) if result: - props.append((i, '%s:%s' % (result, tab.name))) + props.append((i, '%s:%s' % (result, tab.jid.full))) return props diff --git a/plugins/replace.py b/plugins/replace.py index 7e259dab..9646a817 100644 --- a/plugins/replace.py +++ b/plugins/replace.py @@ -102,11 +102,11 @@ def replace_random_user(message, tab): if isinstance(tab, tabs.MucTab): return random.choice(tab.users).nick elif isinstance(tab, tabs.PrivateTab): - return random.choice([JID(tab.name).resource, tab.own_nick]) + return random.choice([tab.jid.resource, tab.own_nick]) else: # that doesn’t make any sense. By why use this pattern in a # ConversationTab anyway? - return str(tab.name) + return tab.jid.full def replace_dice(message, tab): diff --git a/plugins/server_part.py b/plugins/server_part.py index 7a71d94b..f29b4099 100644 --- a/plugins/server_part.py +++ b/plugins/server_part.py @@ -39,7 +39,7 @@ class Plugin(BasePlugin): if not args and not isinstance(current_tab, MucTab): return self.core.command_help('server_part') elif not args: - jid = safeJID(current_tab.name).bare + jid = current_tab.jid.bare message = None elif len(args) == 1: jid = safeJID(args[0]).domain @@ -60,6 +60,6 @@ class Plugin(BasePlugin): serv_list = set() for tab in self.core.get_tabs(MucTab): if tab.joined: - serv = safeJID(tab.name).server + serv = tab.jid.server serv_list.add(serv) return Completion(the_input.new_completion, sorted(serv_list), 1, ' ') diff --git a/plugins/tell.py b/plugins/tell.py index 43a91d8b..614c1ef5 100644 --- a/plugins/tell.py +++ b/plugins/tell.py @@ -75,7 +75,7 @@ class Plugin(BasePlugin): if not self.tabs.get(tab): self.api.information('No message queued.', 'Info') return - build = ['Messages queued for %s:' % tab.name] + build = ['Messages queued for %s:' % tab.jid.bare] for nick, messages in self.tabs[tab].items(): build.append(' for %s:' % nick) for message in messages: diff --git a/plugins/time_marker.py b/plugins/time_marker.py index bd6af1c4..76f7e589 100644 --- a/plugins/time_marker.py +++ b/plugins/time_marker.py @@ -36,7 +36,7 @@ from datetime import datetime, timedelta class Plugin(BasePlugin): def init(self): self.api.add_event_handler("muc_msg", self.on_muc_msg) - # Dict of MucTab.name: last_message date, so we don’t have to + # Dict of MucTab.jid.bare: last_message date, so we don’t have to # retrieve the messages of the given muc to look for the last # message’s date each time. Also, now that I think about it, the # date of the message is not event kept in the Message object, so… @@ -66,8 +66,8 @@ class Plugin(BasePlugin): res += "%s seconds, " % seconds return res[:-2] - last_message_date = self.last_messages.get(tab.name) - self.last_messages[tab.name] = datetime.now() + last_message_date = self.last_messages.get(tab.jid.bare) + self.last_messages[tab.jid.bare] = datetime.now() if last_message_date: delta = datetime.now() - last_message_date if delta >= timedelta(0, self.config.get('delay', 900)): diff --git a/plugins/vcard.py b/plugins/vcard.py index 643dd569..09dcda28 100644 --- a/plugins/vcard.py +++ b/plugins/vcard.py @@ -273,7 +273,7 @@ class Plugin(BasePlugin): if arg: self.command_vcard(arg) return - self.command_vcard(self.api.current_tab().name) + self.command_vcard(self.api.current_tab().jid.full) @command_args_parser.raw def command_muc_vcard(self, arg): @@ -282,10 +282,12 @@ class Plugin(BasePlugin): return user = self.api.current_tab().get_user_by_name(arg) if user: - # No need to use safeJID here, we already know the JID is valid. - jid = JID(self.api.current_tab().name + '/' + user.nick) + jid = self.api.current_tab().jid.bare + '/' + user.nick else: - jid = safeJID(arg) + try: + jid = safeJID(arg) + except InvalidJID: + return self.api.information('Invalid JID: %s' % arg, 'Error') self._get_vcard(jid) @command_args_parser.raw -- cgit v1.2.3