Fix the quote plugin

(broken when refactoring messages)
This commit is contained in:
mathieui 2021-02-11 18:45:32 +01:00
parent 5c6b2adeb2
commit 67c5bee9da

View file

@ -45,8 +45,10 @@ Options
""" """
from poezio.core.structs import Completion from poezio.core.structs import Completion
from poezio.ui.types import Message
from poezio.plugin import BasePlugin from poezio.plugin import BasePlugin
from poezio.xhtml import clean_text from poezio.xhtml import clean_text
from poezio.theming import get_theme
from poezio import common from poezio import common
from poezio import tabs from poezio import tabs
@ -74,13 +76,14 @@ class Plugin(BasePlugin):
return self.api.run_command('/help quote') return self.api.run_command('/help quote')
message = self.find_message(message) message = self.find_message(message)
if message: if message:
str_time = message.time.strftime(get_theme().SHORT_TIME_FORMAT)
before = self.config.get('before_quote', '') % { before = self.config.get('before_quote', '') % {
'nick': message.nickname or '', 'nick': message.nickname or '',
'time': message.str_time 'time': str_time,
} }
after = self.config.get('after_quote', '') % { after = self.config.get('after_quote', '') % {
'nick': message.nickname or '', 'nick': message.nickname or '',
'time': message.str_time 'time': str_time,
} }
self.core.insert_input_text( self.core.insert_input_text(
'%(before)s%(quote)s%(after)s' % { '%(before)s%(quote)s%(after)s' % {
@ -96,7 +99,7 @@ class Plugin(BasePlugin):
if not messages: if not messages:
return None return None
for message in messages[::-1]: for message in messages[::-1]:
if clean_text(message.txt) == txt: if isinstance(message, Message) and clean_text(message.txt) == txt:
return message return message
return None return None
@ -114,5 +117,8 @@ class Plugin(BasePlugin):
messages = list(filter(message_match, messages)) messages = list(filter(message_match, messages))
elif len(args) > 1: elif len(args) > 1:
return False return False
return Completion(the_input.auto_completion, return Completion(
[clean_text(msg.txt) for msg in messages[::-1]], '') the_input.auto_completion,
[clean_text(msg.txt) for msg in messages[::-1] if isinstance(msg, Message)],
''
)