plugins: Update use of tab.name to tab.jid where appropriate

Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <pep@bouah.net>
parent 200f2294
...@@ -95,7 +95,7 @@ class Plugin(BasePlugin): ...@@ -95,7 +95,7 @@ class Plugin(BasePlugin):
is_muctab = isinstance(tab, tabs.MucTab) is_muctab = isinstance(tab, tabs.MucTab)
msg_id = tab.last_sent_message["id"] msg_id = tab.last_sent_message["id"]
increment = self.config.get('refresh') 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) increment)
event = self.api.create_delayed_event(increment, self.delayed_event, event = self.api.create_delayed_event(increment, self.delayed_event,
roll) roll)
......
...@@ -376,7 +376,7 @@ class Plugin(BasePlugin): ...@@ -376,7 +376,7 @@ class Plugin(BasePlugin):
""" """
gateway = self.config.get('gateway', 'irc.poez.io') gateway = self.config.get('gateway', 'irc.poez.io')
current = self.api.current_tab() current = self.api.current_tab()
current_jid = common.safeJID(current.name) current_jid = current.jid
if not current_jid.server == gateway: if not current_jid.server == gateway:
self.api.information( self.api.information(
'The current tab does not appear to be an IRC one', 'Warning') 'The current tab does not appear to be an IRC one', 'Warning')
......
...@@ -68,7 +68,7 @@ class Plugin(BasePlugin): ...@@ -68,7 +68,7 @@ class Plugin(BasePlugin):
tab.command_say(args) tab.command_say(args)
is_muctab = isinstance(tab, tabs.MucTab) is_muctab = isinstance(tab, tabs.MucTab)
msg_id = tab.last_sent_message["id"] msg_id = tab.last_sent_message["id"]
jid = tab.name jid = tab.jid
event = self.api.create_delayed_event( event = self.api.create_delayed_event(
self.config.get("refresh"), self.delayed_event, jid, args, msg_id, self.config.get("refresh"), self.delayed_event, jid, args, msg_id,
......
...@@ -325,7 +325,7 @@ def hl(tab): ...@@ -325,7 +325,7 @@ def hl(tab):
if tab.state != 'current': if tab.state != 'current':
tab.state = 'private' tab.state = 'private'
conv_jid = safeJID(tab.name) conv_jid = tab.jid
if 'private' in config.get('beep_on', 'highlight private').split(): if 'private' in config.get('beep_on', 'highlight private').split():
if not config.get_by_tabname( if not config.get_by_tabname(
'disable_beep', conv_jid.bare, default=False): 'disable_beep', conv_jid.bare, default=False):
...@@ -806,7 +806,7 @@ class Plugin(BasePlugin): ...@@ -806,7 +806,7 @@ class Plugin(BasePlugin):
On message sent On message sent
""" """
name = tab.name name = tab.name
jid = safeJID(tab.name) jid = tab.jid
format_dict = { format_dict = {
'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID), 'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID),
...@@ -846,7 +846,7 @@ class Plugin(BasePlugin): ...@@ -846,7 +846,7 @@ class Plugin(BasePlugin):
elif not is_relevant(tab) and ctx and ( elif not is_relevant(tab) and ctx and (
ctx.state == STATE_ENCRYPTED ctx.state == STATE_ENCRYPTED
or ctx.getPolicy('REQUIRE_ENCRYPTION')): or ctx.getPolicy('REQUIRE_ENCRYPTION')):
contact = roster[tab.name] contact = roster[tab.jid.bare]
res = [] res = []
if contact: if contact:
res = [resource.jid for resource in contact.resources] res = [resource.jid for resource in contact.resources]
...@@ -884,13 +884,13 @@ class Plugin(BasePlugin): ...@@ -884,13 +884,13 @@ class Plugin(BasePlugin):
return self.core.command.help('otr') return self.core.command.help('otr')
action = args.pop(0) action = args.pop(0)
tab = self.api.current_tab() tab = self.api.current_tab()
name = tab.name name = tab.jid.full
format_dict = { format_dict = {
'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID), 'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID),
'info': '\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT), 'info': '\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT),
'normal': '\x19%s}' % dump_tuple(get_theme().COLOR_NORMAL_TEXT), 'normal': '\x19%s}' % dump_tuple(get_theme().COLOR_NORMAL_TEXT),
'jid': name, 'jid': tab.jid.full,
'bare_jid': safeJID(name).bare 'bare_jid': tab.jid.bare,
} }
if action == 'end': # close the session if action == 'end': # close the session
...@@ -991,12 +991,12 @@ class Plugin(BasePlugin): ...@@ -991,12 +991,12 @@ class Plugin(BasePlugin):
question = secret = None question = secret = None
tab = self.api.current_tab() tab = self.api.current_tab()
name = tab.name name = tab.jid.full
format_dict = { format_dict = {
'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID), 'jid_c': '\x19%s}' % dump_tuple(get_theme().COLOR_MUC_JID),
'info': '\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT), 'info': '\x19%s}' % dump_tuple(get_theme().COLOR_INFORMATION_TEXT),
'jid': name, 'jid': tab.jid.full,
'bare_jid': safeJID(name).bare 'bare_jid': tab.jid.bare,
} }
ctx = self.get_context(name) ctx = self.get_context(name)
......
...@@ -22,6 +22,7 @@ Command ...@@ -22,6 +22,7 @@ Command
the current interlocutor. the current interlocutor.
""" """
from slixmpp import InvalidJID
from poezio.decorators import command_args_parser from poezio.decorators import command_args_parser
from poezio.plugin import BasePlugin from poezio.plugin import BasePlugin
from poezio.roster import roster from poezio.roster import roster
...@@ -116,7 +117,7 @@ class Plugin(BasePlugin): ...@@ -116,7 +117,7 @@ class Plugin(BasePlugin):
def command_private_ping(self, arg): def command_private_ping(self, arg):
if arg: if arg:
return self.command_ping(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 @command_args_parser.raw
def command_muc_ping(self, arg): def command_muc_ping(self, arg):
...@@ -124,10 +125,13 @@ class Plugin(BasePlugin): ...@@ -124,10 +125,13 @@ class Plugin(BasePlugin):
return return
user = self.api.current_tab().get_user_by_name(arg) user = self.api.current_tab().get_user_by_name(arg)
if user: if user:
jid = safeJID(self.api.current_tab().name) jid = self.api.current_tab().jid
jid.resource = user.nick jid.resource = user.nick
else: else:
jid = safeJID(arg) try:
jid = JID(arg)
except InvalidJID:
return self.api.information('Invalid JID: %s' % arg, 'Error')
self.command_ping(jid.full) self.command_ping(jid.full)
@command_args_parser.raw @command_args_parser.raw
......
...@@ -112,7 +112,7 @@ def parse_runtime_tablist(tablist): ...@@ -112,7 +112,7 @@ def parse_runtime_tablist(tablist):
i += 1 i += 1
result = check_tab(tab) result = check_tab(tab)
if result: if result:
props.append((i, '%s:%s' % (result, tab.name))) props.append((i, '%s:%s' % (result, tab.jid.full)))
return props return props
......
...@@ -102,11 +102,11 @@ def replace_random_user(message, tab): ...@@ -102,11 +102,11 @@ def replace_random_user(message, tab):
if isinstance(tab, tabs.MucTab): if isinstance(tab, tabs.MucTab):
return random.choice(tab.users).nick return random.choice(tab.users).nick
elif isinstance(tab, tabs.PrivateTab): 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: else:
# that doesn’t make any sense. By why use this pattern in a # that doesn’t make any sense. By why use this pattern in a
# ConversationTab anyway? # ConversationTab anyway?
return str(tab.name) return tab.jid.full
def replace_dice(message, tab): def replace_dice(message, tab):
......
...@@ -39,7 +39,7 @@ class Plugin(BasePlugin): ...@@ -39,7 +39,7 @@ class Plugin(BasePlugin):
if not args and not isinstance(current_tab, MucTab): if not args and not isinstance(current_tab, MucTab):
return self.core.command_help('server_part') return self.core.command_help('server_part')
elif not args: elif not args:
jid = safeJID(current_tab.name).bare jid = current_tab.jid.bare
message = None message = None
elif len(args) == 1: elif len(args) == 1:
jid = safeJID(args[0]).domain jid = safeJID(args[0]).domain
...@@ -60,6 +60,6 @@ class Plugin(BasePlugin): ...@@ -60,6 +60,6 @@ class Plugin(BasePlugin):
serv_list = set() serv_list = set()
for tab in self.core.get_tabs(MucTab): for tab in self.core.get_tabs(MucTab):
if tab.joined: if tab.joined:
serv = safeJID(tab.name).server serv = tab.jid.server
serv_list.add(serv) serv_list.add(serv)
return Completion(the_input.new_completion, sorted(serv_list), 1, ' ') return Completion(the_input.new_completion, sorted(serv_list), 1, ' ')
...@@ -75,7 +75,7 @@ class Plugin(BasePlugin): ...@@ -75,7 +75,7 @@ class Plugin(BasePlugin):
if not self.tabs.get(tab): if not self.tabs.get(tab):
self.api.information('No message queued.', 'Info') self.api.information('No message queued.', 'Info')
return return
build = ['Messages queued for %s:' % tab.name] build = ['Messages queued for %s:' % tab.jid.bare]
for nick, messages in self.tabs[tab].items(): for nick, messages in self.tabs[tab].items():
build.append(' for %s:' % nick) build.append(' for %s:' % nick)
for message in messages: for message in messages:
......
...@@ -36,7 +36,7 @@ from datetime import datetime, timedelta ...@@ -36,7 +36,7 @@ from datetime import datetime, timedelta
class Plugin(BasePlugin): class Plugin(BasePlugin):
def init(self): def init(self):
self.api.add_event_handler("muc_msg", self.on_muc_msg) 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 # 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 # 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… # date of the message is not event kept in the Message object, so…
...@@ -66,8 +66,8 @@ class Plugin(BasePlugin): ...@@ -66,8 +66,8 @@ class Plugin(BasePlugin):
res += "%s seconds, " % seconds res += "%s seconds, " % seconds
return res[:-2] return res[:-2]
last_message_date = self.last_messages.get(tab.name) last_message_date = self.last_messages.get(tab.jid.bare)
self.last_messages[tab.name] = datetime.now() self.last_messages[tab.jid.bare] = datetime.now()
if last_message_date: if last_message_date:
delta = datetime.now() - last_message_date delta = datetime.now() - last_message_date
if delta >= timedelta(0, self.config.get('delay', 900)): if delta >= timedelta(0, self.config.get('delay', 900)):
......
...@@ -273,7 +273,7 @@ class Plugin(BasePlugin): ...@@ -273,7 +273,7 @@ class Plugin(BasePlugin):
if arg: if arg:
self.command_vcard(arg) self.command_vcard(arg)
return return
self.command_vcard(self.api.current_tab().name) self.command_vcard(self.api.current_tab().jid.full)
@command_args_parser.raw @command_args_parser.raw
def command_muc_vcard(self, arg): def command_muc_vcard(self, arg):
...@@ -282,10 +282,12 @@ class Plugin(BasePlugin): ...@@ -282,10 +282,12 @@ class Plugin(BasePlugin):
return return
user = self.api.current_tab().get_user_by_name(arg) user = self.api.current_tab().get_user_by_name(arg)
if user: if user:
# No need to use safeJID here, we already know the JID is valid. jid = self.api.current_tab().jid.bare + '/' + user.nick
jid = JID(self.api.current_tab().name + '/' + user.nick)
else: else:
jid = safeJID(arg) try:
jid = safeJID(arg)
except InvalidJID:
return self.api.information('Invalid JID: %s' % arg, 'Error')
self._get_vcard(jid) self._get_vcard(jid)
@command_args_parser.raw @command_args_parser.raw
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment