diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2012-12-26 17:58:16 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2012-12-29 13:14:50 +0100 |
commit | 1313e7be3800d330824e1a8021e78bba5ddffe45 (patch) | |
tree | ef5c704498dd180654bf6919101ee46f6e603c5e /plugins | |
parent | 65e097f4107e0c095a9818f5d7f0851b292c9a84 (diff) | |
download | poezio-1313e7be3800d330824e1a8021e78bba5ddffe45.tar.gz poezio-1313e7be3800d330824e1a8021e78bba5ddffe45.tar.bz2 poezio-1313e7be3800d330824e1a8021e78bba5ddffe45.tar.xz poezio-1313e7be3800d330824e1a8021e78bba5ddffe45.zip |
Add a /display_corrections plugin.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/display_corrections.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/plugins/display_corrections.py b/plugins/display_corrections.py new file mode 100644 index 00000000..9937387f --- /dev/null +++ b/plugins/display_corrections.py @@ -0,0 +1,46 @@ +# A plugin that adds the /display_corrections command, to view the previous +# versions of a corrected message. + +from plugin import BasePlugin +from common import shell_split +import tabs + +class Plugin(BasePlugin): + def init(self): + usage = 'Usage: /display_corrections <number>\nDisplay_corrections: display all the corrections of the number-th last corrected message.' + for tab_type in (tabs.MucTab, tabs.PrivateTab, tabs.ConversationTab): + self.add_tab_command(tab_type, 'display_corrections', self.command_display_corrections, usage) + + def find_corrected(self, nb): + messages = self.core.get_conversation_messages() + if not messages: + return None + for message in messages[::-1]: + if message.old_message: + if nb == 1: + return message + else: + nb -= 1 + return None + + def command_display_corrections(self, args): + args = shell_split(args) + if len(args) == 1: + try: + nb = int(args[0]) + except: + return self.core.command_help('display_corrections') + else: + nb = 1 + message = self.find_corrected(nb) + if message: + display = [] + while message: + display.append('%s %s%s%s %s' % (message.str_time, '* ' if message.me else '', message.nickname, '' if message.me else '>', message.txt)) + message = message.old_message + self.core.information('Older versions:\n' + '\n'.join(display[::-1]), 'Info') + else: + self.core.information('No corrected message found.', 'Warning') + + def cleanup(self): + del self.config |