From 1313e7be3800d330824e1a8021e78bba5ddffe45 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 26 Dec 2012 17:58:16 +0100 Subject: Add a /display_corrections plugin. --- doc/en/plugins/display_corrections.txt | 32 +++++++++++++++++++++++ doc/en/plugins/index.txt | 5 ++++ plugins/display_corrections.py | 46 ++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 doc/en/plugins/display_corrections.txt create mode 100644 plugins/display_corrections.py diff --git a/doc/en/plugins/display_corrections.txt b/doc/en/plugins/display_corrections.txt new file mode 100644 index 00000000..570556b2 --- /dev/null +++ b/doc/en/plugins/display_corrections.txt @@ -0,0 +1,32 @@ +Display corrections +=================== + +Lists old versions of a corrected message. + +Installation +------------ + +============================ + + /load display\_corrections + +============================ + + +Usage +----- +This plugin adds a _/display\_corrections command that will display a list of +old versions of a message. + + +_/display\_corrections_ without argument will list the last corrected message, +if any is found. If an integer argument is given, /display\_corrections will +go back gradually in the buffer to list the previous corrected messages, and so +on. + + +If you are scrolling in the buffer, poezio will list the corrected messages +starting from the first you can see. (although there are some problems with +multiline messages). + + diff --git a/doc/en/plugins/index.txt b/doc/en/plugins/index.txt index be5332b2..1c009998 100644 --- a/doc/en/plugins/index.txt +++ b/doc/en/plugins/index.txt @@ -70,6 +70,11 @@ Plugins index Logs the day change inside the buffers, to keep track of the days when backlogging. +*Display corrections*:: link:display_corrections.html[Display corrections +plugin] + + Lists old versions of a corrected message. + *Exec*:: link:exec.html[System command plugin] Runs a system command an optionally sends the output as a message. 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 \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 -- cgit v1.2.3