From e1956533a6e04d7ba2afdbc841b48804a84120b3 Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 1 Mar 2013 19:25:31 +0100 Subject: Fix #2231 (update the plugins to use the new help system) And fix some imprecisions/mistakes in the help. --- plugins/admin.py | 40 ++++++---- plugins/ai.py | 177 ----------------------------------------- plugins/alias.py | 16 +++- plugins/amsg.py | 5 +- plugins/display_corrections.py | 7 +- plugins/exec.py | 5 +- plugins/gpg/__init__.py | 6 +- plugins/link.py | 8 +- plugins/mpd_client.py | 9 ++- plugins/otr.py | 6 +- plugins/pacokick.py | 5 +- plugins/ping.py | 20 ++++- plugins/quote.py | 9 ++- plugins/reminder.py | 17 +++- plugins/send_delayed.py | 9 ++- plugins/status.py | 20 ++--- plugins/tell.py | 10 ++- plugins/uptime.py | 5 +- 18 files changed, 137 insertions(+), 237 deletions(-) delete mode 100644 plugins/ai.py diff --git a/plugins/admin.py b/plugins/admin.py index cb9ee37b..0f61007b 100644 --- a/plugins/admin.py +++ b/plugins/admin.py @@ -13,28 +13,40 @@ class Plugin(BasePlugin): /noaffiliation """ def init(self): - for role in ['visitor', 'participant' , 'moderator']: + for role in ('visitor', 'participant' , 'moderator'): self.add_tab_command(MucTab, role, self.role(role), - '/%s \n%s: Set the role of a nick to %s.' % - (role, role.capitalize(), role), self.complete_nick) + help='Set the role of a nick to %s' % role, + usage= '', + short='Set the role to %s' % role, + completion=self.complete_nick) - for aff in ['member', 'owner', 'admin']: + for aff in ('member', 'owner', 'admin'): self.add_tab_command(MucTab, aff, self.affiliation(aff), - '/%s \n%s: set the affiliation of a nick to %s' % - (aff, aff.capitalize(), aff), self.complete_nick) + usage='', + help='Set the affiliation of a nick to %s' % aff, + short='Set the affiliation to %s' % aff, + completion=self.complete_nick) self.add_tab_command(MucTab, 'noaffiliation', self.affiliation('none'), - '/noaffiliation \nNoAffiliation: set the affiliation of a nick to none.', - self.complete_nick) + usage='', + help='Set the affiliation of a nick to none.', + short='Set the affiliation to none.', + completion=self.complete_nick) self.add_tab_command(MucTab, 'voice', self.affiliation('member'), - '/voice \nVoice: set the affiliation of a nick to member.', - self.complete_nick) + usage='', + help='Set the affiliation of a nick to member.', + short='Set the affiliation to member.', + completion=self.complete_nick) self.add_tab_command(MucTab, 'op', self.role('moderator'), - '/op \nOp: set the role of a nick to moderator.', - self.complete_nick) + usage='', + help='Set the role of a nick to moderator.', + short='Set the role to moderator.', + completion=self.complete_nick) self.add_tab_command(MucTab, 'mute', self.role('visitor'), - '/mute \nMute: set the role of a nick to visitor.', - self.complete_nick) + usage='', + help='Set the role of a nick to visitor.', + short='Set the role to visitor.', + completion=self.complete_nick) def role(self, role): return lambda args: self.core.current_tab().command_role(args+' '+role) diff --git a/plugins/ai.py b/plugins/ai.py deleted file mode 100644 index 62ae2a96..00000000 --- a/plugins/ai.py +++ /dev/null @@ -1,177 +0,0 @@ -""" -Recreational plugin. - -Message parser that can generate sentences based on what he has already seen -before. - -""" -from plugin import BasePlugin -from random import choice -from re import split as rsplit -import pickle -import tabs - -class Dico(object): - def __init__(self): - self.start_words = [] - self.end_words = [] - self.words = {} - - def add_next(self, word, next): - w = self.words[word] - if next in w: - w[next] += 1 - else: - w[next] = 1 - - def add_word(self, word): - if not word in self.words: - self.words[word] = {} - - def select_next(self, word): - d = sorted(self.words[word], key=lambda w: self.words[word][w], reverse=True) - if not d: - return '' - nexts = d[:10] - for i in range(0, len(d) // 10): - nexts.append(choice(d[9:])) - return choice(nexts) - - def create_sentence(self, length): - if not self.start_words: - return '' - current = choice(self.start_words) - i = 1 - sent = current.capitalize() - while current and self.words[current] and i < length: - current = self.select_next(current) - sent += " " + current - i += 1 - return sent - - def save(self, fname): - file = open(fname, 'wb') - pickle.dump(self, file) - file.close - -spaces = '  ' -end_sentence = ['.', '?', '!'] - -def end_re(): - r = '(' - for i in end_sentence[:]: - end_sentence.append('%s ' % i) - i = '\%s'% i - r += '%s$|%s |' % (i, i) - r = r[:-1] - r += ')' - return r - -end = end_re() - - -class Analyzer(object): - dico = None - def __init__(self): - pass - - def parse(self, text): - text = text.replace('\n', '') - res = rsplit(end, text) - for i in res[:]: - if i == '': - continue - elif i in end_sentence: - continue - self.analyze(i) - - def analyze(self, text): - prev = None - for word in rsplit('[%s]'%spaces, text): - if word in spaces: continue - word = word.lower() - self.dico.add_word(word) - if prev: - self.dico.add_next(prev, word) - else: - self.dico.start_words.append(word) - prev = word - -class Plugin(BasePlugin): - def init(self): - self.add_event_handler('groupchat_message', self.on_groupchat_message) - self.add_tab_command(tabs.MucTab, 'random', self.command_random, '/random [n]\nRandom: Send a random message, if n is provided and is integer > 1, the message will have a maximum number of n words', None) - self.add_tab_command(tabs.MucTab, 'start', self.command_start, '/start\nStart: Start parsing the messages', None) - self.add_tab_command(tabs.MucTab, 'stop', self.command_stop, '/stop\nStop: Stop parsing the messages', None) - self.add_tab_command(tabs.MucTab, 'flush', self.command_flush, '/flush\nFlush: Flush the database', None) - self.add_tab_command(tabs.MucTab, 'save', self.command_save, '/save \nSave: Save the database to a file', None) - self.add_tab_command(tabs.MucTab, 'load_db', self.command_load_db, '/load_db \nLoad: Load the database from a file', None) - self.tabs = {} - self.analyzer = Analyzer() - - def command_start(self, arg): - name = self.core.current_tab().get_name() - if not name in self.tabs: - self.tabs[name] = Dico() - self.core.information('Started analyzing in %s' % name, 'Info') - else: - self.core.information('Already started', 'Info') - - def command_stop(self, arg): - name = self.core.current_tab().get_name() - if name in self.tabs: - del self.tabs[name] - self.core.information('Stopped analyzing in %s' % name, 'Info') - else: - self.core.information('Nothing to stop', 'Info') - - def command_save(self, arg): - name = self.core.current_tab().get_name() - if name in self.tabs: - try: - self.tabs[name].save(arg) - except: - self.core.information('Could not save the file', 'Info') - else: - self.core.information('Nothing to save', 'Info') - - def command_flush(self, arg): - name = self.core.current_tab().get_name() - if name in self.tabs: - del self.tabs[name] - self.tabs[name] = Dico() - self.core.information('Database flushed', 'Info') - else: - self.core.information('Nothing to flush', 'Info') - - def command_load_db(self, arg): - name = self.core.current_tab().get_name() - try: - file = open(arg, 'rb') - self.tabs[name] = pickle.load(file) - file.close() - self.core.information('File loaded', 'Info') - except: - self.core.information('Could not load the file', 'Info') - - def on_groupchat_message(self, message): - if not message['body']: - return - jid = message['from'] - if jid.bare not in self.tabs or jid.resource == self.core.current_tab().own_nick: - return - jid = jid.bare - - self.analyzer.dico = self.tabs[jid] - self.analyzer.parse(message['body']) - - def command_random(self, arg): - name = self.core.current_tab().get_name() - try: - i = int(arg) - if i < 1: - i = 1 - except: - i = 25 - if name in self.tabs: - self.core.send_message(self.tabs[name].create_sentence(i)) diff --git a/plugins/alias.py b/plugins/alias.py index 5a35d1c6..163e4c26 100644 --- a/plugins/alias.py +++ b/plugins/alias.py @@ -10,8 +10,15 @@ from common import parse_command_args_to_alias as parse class Plugin(BasePlugin): def init(self): - self.add_command('alias', self.command_alias, '/alias \nAlias: create an alias command') - self.add_command('unalias', self.command_unalias, '/unalias \nUnalias: remove a previously created alias') + self.add_command('alias', self.command_alias, + usage=' [args]', + short='Create an alias command', + help='Create an alias for with [args].') + self.add_command('unalias', self.command_unalias, + usage='', + help='Remove a previously created alias', + short='Remove an alias', + completion=self.completion_unalias) self.commands = {} def command_alias(self, line): @@ -42,6 +49,11 @@ class Plugin(BasePlugin): self.del_command(alias) self.core.information('Alias /%s successfuly deleted' % alias, 'Info') + def completion_unalias(self, the_input): + aliases = [alias for alias in self.commands] + aliases.sort() + return the_input.auto_completion(aliases, '', quotify=False) + def get_command(self, name): """Returns the function associated with a command""" def dummy(args): diff --git a/plugins/amsg.py b/plugins/amsg.py index 697f793f..a002b11e 100644 --- a/plugins/amsg.py +++ b/plugins/amsg.py @@ -5,7 +5,10 @@ from tabs import MucTab class Plugin(BasePlugin): def init(self): - self.add_command('amsg', self.command_amsg, "Usage: /amsg \nAmsg: Broadcast the message to all the joined rooms.") + self.add_command('amsg', self.command_amsg, + usage='', + short='Broadcast a message', + help='Broadcast the message to all the joined rooms.') def command_amsg(self, args): for room in self.core.tabs: diff --git a/plugins/display_corrections.py b/plugins/display_corrections.py index 9937387f..6e122bfe 100644 --- a/plugins/display_corrections.py +++ b/plugins/display_corrections.py @@ -7,9 +7,12 @@ 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) + self.add_tab_command(tab_type, 'display_corrections', + handler=self.command_display_corrections, + usage='', + help='Display all the corrections of the number-th last corrected message.', + short='Display the corrections of a message') def find_corrected(self, nb): messages = self.core.get_conversation_messages() diff --git a/plugins/exec.py b/plugins/exec.py index c729b555..bf7d7c38 100644 --- a/plugins/exec.py +++ b/plugins/exec.py @@ -8,7 +8,10 @@ import subprocess class Plugin(BasePlugin): def init(self): - self.add_command('exec', self.command_exec, "Usage: /exec [-o|-O] \nExec: Execute a shell command and prints the result in the information buffer. The command should be ONE argument, that means it should be between \"\". The first argument (before the command) can be -o or -O. If -o is specified, it sends the result in the current conversation. If -O is specified, it sends the command and its result in the current conversation.\nExample: /exec -O \"uptime\" will send “uptime\n20:36:19 up 3:47, 4 users, load average: 0.09, 0.13, 0.09” in the current conversation.") + self.add_command('exec', self.command_exec, + usage='[-o|-O] ', + help='Execute a shell command and prints the result in the information buffer. The command should be ONE argument, that means it should be between \"\". The first argument (before the command) can be -o or -O. If -o is specified, it sends the result in the current conversation. If -O is specified, it sends the command and its result in the current conversation.\nExample: /exec -O \"uptime\" will send “uptime\n20:36:19 up 3:47, 4 users, load average: 0.09, 0.13, 0.09” in the current conversation.', + short='Execute a command') def command_exec(self, args): args = common.shell_split(args) diff --git a/plugins/gpg/__init__.py b/plugins/gpg/__init__.py index a60cbbdb..9fa8ee13 100644 --- a/plugins/gpg/__init__.py +++ b/plugins/gpg/__init__.py @@ -56,7 +56,11 @@ class Plugin(BasePlugin): self.add_event_handler('conversation_say_after', self.on_conversation_say) self.add_event_handler('conversation_msg', self.on_conversation_msg) - self.add_command('gpg', self.command_gpg, "Usage: /gpg [JID] [keyid]\nGpg: Force or disable gpg encryption with the fulljid of the current conversation. The setkey argument lets you associate a keyid with the given bare JID.", self.gpg_completion) + self.add_tab_command(ConversationTab, 'gpg', self.command_gpg, + usage=' [jid] [keyid]', + help='Force or disable gpg encryption with the fulljid of the current conversation. The setkey argument lets you associate a keyid with the given bare JID.', + short='Manage the GPG status', + completion=self.gpg_completion) ConversationTab.add_information_element('gpg', self.display_encryption_status) def cleanup(self): diff --git a/plugins/link.py b/plugins/link.py index 427d718a..0d88fba2 100644 --- a/plugins/link.py +++ b/plugins/link.py @@ -12,9 +12,11 @@ url_pattern = re.compile(r'\b(http[s]?://(?:\S+))\b', re.I|re.U) class Plugin(BasePlugin): def init(self): - self.add_tab_command(tabs.MucTab, 'link', self.command_link, "Usage: /link\nLink: opens the last link from the conversation into a browser.") - self.add_tab_command(tabs.PrivateTab, 'link', self.command_link, "Usage: /link\nLink: opens the last link from the conversation into a browser.") - self.add_tab_command(tabs.ConversationTab, 'link', self.command_link, "Usage: /link\nLink: opens the last link from the conversation into a browser.") + for _class in (tabs.MucTab, tabs.PrivateTab, tabs.ConversationTab): + self.add_tab_command(_class, 'link', self.command_link, + usage='[num]', + help='Opens the last link from the conversation into a browser.\nIf [num] is given, then it will open the num-th link displayed.', + short='Open links into a browser') def find_link(self, nb): messages = self.core.get_conversation_messages() diff --git a/plugins/mpd_client.py b/plugins/mpd_client.py index e71c8a5f..47bbdf29 100644 --- a/plugins/mpd_client.py +++ b/plugins/mpd_client.py @@ -8,9 +8,12 @@ import mpd class Plugin(BasePlugin): def init(self): - self.add_tab_command(tabs.ConversationTab, 'mpd', self.command_mpd, "Usage: /mpd [full]\nMpd: sends a message showing the current song of an MPD instance. If full is provided, the message is more verbose.", self.completion_mpd) - self.add_tab_command(tabs.MucTab, 'mpd', self.command_mpd, "Usage: /mpd [full]\nMpd: sends a message showing the current song of an MPD instance. If full is provided, the message is more verbose.", self.completion_mpd) - self.add_tab_command(tabs.PrivateTab, 'mpd', self.command_mpd, "Usage: /mpd [full]\nMpd: sends a message showing the current song of an MPD instance. If full is provided, the message is more verbose.", self.completion_mpd) + for _class in (tabs.ConversationTab, tabs.MucTab, tabs.PrivateTab): + self.add_tab_command(_class, 'mpd', self.command_mpd, + usage='[full]', + help='Sends a message showing the current song of an MPD instance. If full is provided, the message is more verbose.', + short='Send the MPD status', + completion=self.completion_mpd) def command_mpd(self, args): args = shell_split(args) diff --git a/plugins/otr.py b/plugins/otr.py index 51e9a8d4..f3a1d7a2 100644 --- a/plugins/otr.py +++ b/plugins/otr.py @@ -16,7 +16,11 @@ class Plugin(BasePlugin): self.add_event_handler('conversation_say_after', self.on_conversation_say) self.add_event_handler('conversation_msg', self.on_conversation_msg) - self.add_tab_command(ConversationTab, 'otr', self.command_otr, "Usage: /otr \notr: Start or stop OTR for the current conversation", self.otr_completion) + self.add_tab_command(ConversationTab, 'otr', self.command_otr, + usage='', + help='Start or stop OTR for the current conversation.', + short='Manage OTR status', + completion=self.otr_completion) ConversationTab.add_information_element('otr', self.display_encryption_status) def cleanup(self): diff --git a/plugins/pacokick.py b/plugins/pacokick.py index 3ecef7a8..053e6c22 100644 --- a/plugins/pacokick.py +++ b/plugins/pacokick.py @@ -5,7 +5,10 @@ from plugin import BasePlugin class Plugin(BasePlugin): def init(self): - self.add_command('pacokick', self.command_kick, '/pacokick [reason]\nPacokick: kick a random user.') + self.add_command('pacokick', self.command_kick, + usage='', + help='Kick a random user.', + short='Kick a random user') def command_kick(self, arg): tab = self.core.current_tab() diff --git a/plugins/ping.py b/plugins/ping.py index fdecd8e0..22401a25 100644 --- a/plugins/ping.py +++ b/plugins/ping.py @@ -8,10 +8,22 @@ import tabs class Plugin(BasePlugin): def init(self): self.core.xmpp.register_plugin('xep_0199') - self.add_command('ping', self.command_ping, '/ping \nPing: Send a XMPP ping to jid (see XEP-0199).', self.completion_ping) - self.add_tab_command(tabs.MucTab, 'ping', self.command_muc_ping, '/ping \nPing: Send a XMPP ping to jid or nick (see XEP-0199)', self.completion_muc_ping) - self.add_tab_command(tabs.PrivateTab, 'ping', self.command_private_ping, '/ping\nPing: Send a XMPP ping to the current interlocutor (see XEP-0199)') - self.add_tab_command(tabs.ConversationTab, 'ping', self.command_private_ping, '/ping\nPing: Send a XMPP ping to the current interlocutor (see XEP-0199)', self.completion_ping) + self.add_command('ping', self.command_ping, + usage='', + help='Send a XMPP ping to jid (see XEP-0199).', + short='Send a ping', + completion=self.completion_ping) + self.add_tab_command(tabs.MucTab, 'ping', self.command_muc_ping, + usage='', + help='Send a XMPP ping to jid or nick (see XEP-0199).', + short='Send a ping.', + completion=self.completion_muc_ping) + for _class in (tabs.PrivateTab, tabs.ConversationTab): + self.add_tab_command(_class, 'ping', self.command_private_ping, + usage='[jid]', + help='Send a XMPP ping to the current interlocutor or the given JID.', + short='Send a ping', + completion=self.completion_ping) def command_ping(self, arg): if not arg: diff --git a/plugins/quote.py b/plugins/quote.py index 50c390f2..ebd9b15e 100644 --- a/plugins/quote.py +++ b/plugins/quote.py @@ -12,9 +12,12 @@ log = logging.getLogger(__name__) class Plugin(BasePlugin): def init(self): - self.add_tab_command(tabs.MucTab, 'quote', self.command_quote, "Usage: /quote \nQuote: takes the message received at and insert it in the input, to quote it.", self.completion_quote) - self.add_tab_command(tabs.ConversationTab, 'quote', self.command_quote, "Usage: /quote \nQuote: takes the message received at and insert it in the input, to quote it.", self.completion_quote) - self.add_tab_command(tabs.PrivateTab, 'quote', self.command_quote, "Usage: /quote \nQuote: takes the message received at and insert it in the input, to quote it.", self.completion_quote) + for _class in (tabs.MucTab, tabs.ConversationTab, tabs.PrivateTab): + self.add_tab_command(_class, 'quote', self.command_quote, + usage='', + help='Takes the message received at and insert it in the input, to quote it.', + short='Quote a message from a timestamp', + completion=self.completion_quote) def command_quote(self, args): args = common.shell_split(args) diff --git a/plugins/reminder.py b/plugins/reminder.py index 2e3fd20d..03711906 100644 --- a/plugins/reminder.py +++ b/plugins/reminder.py @@ -6,9 +6,20 @@ import timed_events class Plugin(BasePlugin): def init(self): - self.add_command('remind', self.command_remind, "Usage: /remind