summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-03-08 22:53:35 +0100
committermathieui <mathieui@mathieui.net>2013-03-08 22:53:35 +0100
commit9885203c6799c121f5bc8a733dc1937fe8c1b4d6 (patch)
tree4190635a7c9c78d2dce1a4c8357ccb887f12b8af
parentdbde08a5267cf003d8a4a9c16f5b18275e9a4bd1 (diff)
downloadpoezio-9885203c6799c121f5bc8a733dc1937fe8c1b4d6.tar.gz
poezio-9885203c6799c121f5bc8a733dc1937fe8c1b4d6.tar.bz2
poezio-9885203c6799c121f5bc8a733dc1937fe8c1b4d6.tar.xz
poezio-9885203c6799c121f5bc8a733dc1937fe8c1b4d6.zip
Update the plugins to use the PluginAPI
Also: - Add get_conversation_messages() to PluginAPI - Make plugins_autoload colon-separated instead of space-separated (for consistency) - Replace a JID() with a safeJID() in the uptime plugin
-rw-r--r--data/default_config.cfg2
-rw-r--r--doc/en/configure.txt2
-rw-r--r--plugins/admin.py18
-rw-r--r--plugins/alias.py11
-rw-r--r--plugins/amsg.py2
-rw-r--r--plugins/day_change.py4
-rw-r--r--plugins/display_corrections.py10
-rw-r--r--plugins/double.py2
-rw-r--r--plugins/exec.py16
-rw-r--r--plugins/figlet.py6
-rw-r--r--plugins/iq_show.py2
-rw-r--r--plugins/link.py8
-rw-r--r--plugins/mpd_client.py6
-rw-r--r--plugins/otr.py24
-rw-r--r--plugins/pacokick.py6
-rw-r--r--plugins/ping.py18
-rw-r--r--plugins/quote.py12
-rw-r--r--plugins/rainbow.py6
-rw-r--r--plugins/reminder.py18
-rw-r--r--plugins/replace.py6
-rw-r--r--plugins/revstr.py2
-rw-r--r--plugins/send_delayed.py6
-rw-r--r--plugins/shuffle.py2
-rw-r--r--plugins/simple_notify.py10
-rw-r--r--plugins/status.py4
-rw-r--r--plugins/tell.py16
-rw-r--r--plugins/test.py18
-rw-r--r--plugins/time_marker.py2
-rw-r--r--plugins/uptime.py11
-rw-r--r--src/core.py8
-rw-r--r--src/plugin.py12
31 files changed, 142 insertions, 128 deletions
diff --git a/data/default_config.cfg b/data/default_config.cfg
index 681d4dd5..abafe4ae 100644
--- a/data/default_config.cfg
+++ b/data/default_config.cfg
@@ -222,7 +222,7 @@ plugins_dir =
# $XDG_CONFIG_HOME/poezio/plugins. You can specify another directory here.
plugins_conf_dir =
-# Space separated list of plugins to load on startup
+# Colon-separated list of plugins to load on startup
plugins_autoload =
# the full path to the photo (avatar) you want to use
diff --git a/doc/en/configure.txt b/doc/en/configure.txt
index 02cd454d..6eff81a5 100644
--- a/doc/en/configure.txt
+++ b/doc/en/configure.txt
@@ -253,7 +253,7 @@ section of this documentation.
*plugins_autoload*:: [empty]
- Space separated list of plugins to load on startup.
+ Colon-separated list of plugins to load on startup.
*plugins_conf_dir*:: [empty]
diff --git a/plugins/admin.py b/plugins/admin.py
index 0f61007b..fac34fdb 100644
--- a/plugins/admin.py
+++ b/plugins/admin.py
@@ -14,49 +14,49 @@ class Plugin(BasePlugin):
"""
def init(self):
for role in ('visitor', 'participant' , 'moderator'):
- self.add_tab_command(MucTab, role, self.role(role),
+ self.api.add_tab_command(MucTab, role, self.role(role),
help='Set the role of a nick to %s' % role,
usage= '<nick>',
short='Set the role to %s' % role,
completion=self.complete_nick)
for aff in ('member', 'owner', 'admin'):
- self.add_tab_command(MucTab, aff, self.affiliation(aff),
+ self.api.add_tab_command(MucTab, aff, self.affiliation(aff),
usage='<nick>',
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'),
+ self.api.add_tab_command(MucTab, 'noaffiliation', self.affiliation('none'),
usage='<nick>',
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'),
+ self.api.add_tab_command(MucTab, 'voice', self.affiliation('member'),
usage='<nick>',
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'),
+ self.api.add_tab_command(MucTab, 'op', self.role('moderator'),
usage='<nick>',
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'),
+ self.api.add_tab_command(MucTab, 'mute', self.role('visitor'),
usage='<nick>',
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)
+ return lambda args: self.api.current_tab().command_role(args+' '+role)
def affiliation(self, affiliation):
- return lambda args: self.core.current_tab().command_affiliation(
+ return lambda args: self.api.current_tab().command_affiliation(
args+' '+affiliation)
def complete_nick(self, the_input):
- tab = self.core.current_tab()
+ tab = self.api.current_tab()
compare_users = lambda x: x.last_talked
word_list = [user.nick for user in sorted(tab.users, key=compare_users, reverse=True)\
if user.nick != tab.own_nick]
diff --git a/plugins/alias.py b/plugins/alias.py
index 4d4a3bf4..a3843f35 100644
--- a/plugins/alias.py
+++ b/plugins/alias.py
@@ -10,11 +10,11 @@ from common import shell_split
class Plugin(BasePlugin):
def init(self):
- self.add_command('alias', self.command_alias,
+ self.api.add_command('alias', self.command_alias,
usage='<alias> <command> [args]',
short='Create an alias command',
help='Create an alias for <command> with [args].')
- self.add_command('unalias', self.command_unalias,
+ self.api.add_command('unalias', self.command_unalias,
usage='<alias>',
help='Remove a previously created alias',
short='Remove an alias',
@@ -36,8 +36,9 @@ class Plugin(BasePlugin):
if alias in self.core.commands or alias in self.commands:
self.api.information('Alias: command already exists', 'Error')
return
- self.commands[alias] = lambda arg: self.get_command(command)(tmp_args.format(*shell_split(arg)))
- self.add_command(alias, self.commands[alias], 'This command is an alias for /%s %s' %( command, tmp_args))
+
+ self.commands[alias] = lambda arg: self.get_command(command)(tmp_args + arg)
+ self.api.add_command(alias, self.commands[alias], 'This command is an alias for /%s %s' %( command, tmp_args))
self.api.information('Alias /%s successfuly created' % alias, 'Info')
def command_unalias(self, alias):
@@ -46,7 +47,7 @@ class Plugin(BasePlugin):
"""
if alias in self.commands:
del self.commands[alias]
- self.del_command(alias)
+ self.api.del_command(alias)
self.api.information('Alias /%s successfuly deleted' % alias, 'Info')
def completion_unalias(self, the_input):
diff --git a/plugins/amsg.py b/plugins/amsg.py
index a002b11e..57a37255 100644
--- a/plugins/amsg.py
+++ b/plugins/amsg.py
@@ -5,7 +5,7 @@ from tabs import MucTab
class Plugin(BasePlugin):
def init(self):
- self.add_command('amsg', self.command_amsg,
+ self.api.add_command('amsg', self.command_amsg,
usage='<message>',
short='Broadcast a message',
help='Broadcast the message to all the joined rooms.')
diff --git a/plugins/day_change.py b/plugins/day_change.py
index 14924684..179bfd98 100644
--- a/plugins/day_change.py
+++ b/plugins/day_change.py
@@ -9,13 +9,13 @@ class Plugin(BasePlugin):
self.schedule_event()
def cleanup(self):
- self.core.remove_timed_event(self.next_event)
+ self.api.remove_timed_event(self.next_event)
def schedule_event(self):
day_change = datetime.datetime.combine(datetime.date.today(), datetime.time())
day_change += datetime.timedelta(1)
self.next_event = timed_events.TimedEvent(day_change, self.day_change)
- self.core.add_timed_event(self.next_event)
+ self.api.add_timed_event(self.next_event)
def day_change(self):
msg = datetime.date.today().strftime(_("Day changed to %x"))
diff --git a/plugins/display_corrections.py b/plugins/display_corrections.py
index 6e122bfe..cad5a327 100644
--- a/plugins/display_corrections.py
+++ b/plugins/display_corrections.py
@@ -8,14 +8,14 @@ import tabs
class Plugin(BasePlugin):
def init(self):
for tab_type in (tabs.MucTab, tabs.PrivateTab, tabs.ConversationTab):
- self.add_tab_command(tab_type, 'display_corrections',
+ self.api.add_tab_command(tab_type, 'display_corrections',
handler=self.command_display_corrections,
usage='<number>',
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()
+ messages = self.api.get_conversation_messages()
if not messages:
return None
for message in messages[::-1]:
@@ -32,7 +32,7 @@ class Plugin(BasePlugin):
try:
nb = int(args[0])
except:
- return self.core.command_help('display_corrections')
+ return self.api.run_command('/help display_corrections')
else:
nb = 1
message = self.find_corrected(nb)
@@ -41,9 +41,9 @@ class Plugin(BasePlugin):
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')
+ self.api.information('Older versions:\n' + '\n'.join(display[::-1]), 'Info')
else:
- self.core.information('No corrected message found.', 'Warning')
+ self.api.information('No corrected message found.', 'Warning')
def cleanup(self):
del self.config
diff --git a/plugins/double.py b/plugins/double.py
index 04728bbf..597ab242 100644
--- a/plugins/double.py
+++ b/plugins/double.py
@@ -2,7 +2,7 @@ from plugin import BasePlugin
class Plugin(BasePlugin):
def init(self):
- self.add_event_handler('muc_say', self.double)
+ self.api.add_event_handler('muc_say', self.double)
def double(self, msg, tab):
split = msg['body'].split()
diff --git a/plugins/exec.py b/plugins/exec.py
index bf7d7c38..4dbe9590 100644
--- a/plugins/exec.py
+++ b/plugins/exec.py
@@ -8,7 +8,7 @@ import subprocess
class Plugin(BasePlugin):
def init(self):
- self.add_command('exec', self.command_exec,
+ self.api.add_command('exec', self.command_exec,
usage='[-o|-O] <command>',
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')
@@ -22,20 +22,20 @@ class Plugin(BasePlugin):
command = args[1]
arg = args[0]
else:
- self.core.command_help('exec')
+ self.api.run_command('/help exec')
return
try:
process = subprocess.Popen(['sh', '-c', command], stdout=subprocess.PIPE)
except OSError as e:
- self.core.information('Failed to execute command: %s' % (e,), 'Error')
+ self.api.information('Failed to execute command: %s' % (e,), 'Error')
return
result = process.communicate()[0].decode('utf-8')
if arg and arg == '-o':
- if not self.core.send_message('%s' % (result,)):
- self.core.information('Cannot send result (%s), this is not a conversation tab' % result)
+ if not self.api.send_message('%s' % (result,)):
+ self.api.information('Cannot send result (%s), this is not a conversation tab' % result)
elif arg and arg == '-O':
- if not self.core.send_message('%s:\n%s' % (command, result)):
- self.core.information('Cannot send result (%s), this is not a conversation tab' % result)
+ if not self.api.send_message('%s:\n%s' % (command, result)):
+ self.api.information('Cannot send result (%s), this is not a conversation tab' % result)
else:
- self.core.information('%s:\n%s' % (command, result), 'Info')
+ self.api.information('%s:\n%s' % (command, result), 'Info')
return
diff --git a/plugins/figlet.py b/plugins/figlet.py
index 0fda098e..eaf8dab3 100644
--- a/plugins/figlet.py
+++ b/plugins/figlet.py
@@ -3,9 +3,9 @@ import subprocess
class Plugin(BasePlugin):
def init(self):
- self.add_event_handler('muc_say', self.figletize)
- self.add_event_handler('conversation_say', self.figletize)
- self.add_event_handler('private_say', self.figletize)
+ self.api.add_event_handler('muc_say', self.figletize)
+ self.api.add_event_handler('conversation_say', self.figletize)
+ self.api.add_event_handler('private_say', self.figletize)
def figletize(self, msg, tab):
process = subprocess.Popen(['figlet', '--', msg['body']], stdout=subprocess.PIPE)
diff --git a/plugins/iq_show.py b/plugins/iq_show.py
index 77d50d6c..06d06d8e 100644
--- a/plugins/iq_show.py
+++ b/plugins/iq_show.py
@@ -7,7 +7,7 @@ class Plugin(BasePlugin):
self.core.xmpp.register_handler(Callback('Iq_show', StanzaPath('iq'), self.handle_iq))
def handle_iq(self, iq):
- self.core.information('%s' % iq, 'Iq')
+ self.api.information('%s' % iq, 'Iq')
def cleanup(self):
self.core.xmpp.remove_handler('Iq_show')
diff --git a/plugins/link.py b/plugins/link.py
index 0d88fba2..9e8b6f97 100644
--- a/plugins/link.py
+++ b/plugins/link.py
@@ -13,13 +13,13 @@ url_pattern = re.compile(r'\b(http[s]?://(?:\S+))\b', re.I|re.U)
class Plugin(BasePlugin):
def init(self):
for _class in (tabs.MucTab, tabs.PrivateTab, tabs.ConversationTab):
- self.add_tab_command(_class, 'link', self.command_link,
+ self.api.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()
+ messages = self.api.get_conversation_messages()
if not messages:
return None
for message in messages[::-1]:
@@ -38,14 +38,14 @@ class Plugin(BasePlugin):
try:
nb = int(args[0])
except:
- return self.core.command_help('link')
+ return self.api.run_command('/help link')
else:
nb = 1
link = self.find_link(nb)
if link:
self.core.exec_command([self.config.get('browser', 'firefox'), link])
else:
- self.core.information('No URL found.', 'Warning')
+ self.api.information('No URL found.', 'Warning')
def cleanup(self):
del self.config
diff --git a/plugins/mpd_client.py b/plugins/mpd_client.py
index 47bbdf29..c215e971 100644
--- a/plugins/mpd_client.py
+++ b/plugins/mpd_client.py
@@ -9,7 +9,7 @@ import mpd
class Plugin(BasePlugin):
def init(self):
for _class in (tabs.ConversationTab, tabs.MucTab, tabs.PrivateTab):
- self.add_tab_command(_class, 'mpd', self.command_mpd,
+ self.api.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',
@@ -34,8 +34,8 @@ class Plugin(BasePlugin):
current_time = float(c.status()['elapsed'])
pourcentage = int(current_time / float(current['time']) * 10)
s += ' \x192}[\x191}' + '-'*(pourcentage-1) + '\x193}+' + '\x191}' + '-' * (10-pourcentage-1) + '\x192}]\x19o'
- if not self.core.send_message('%s' % (s,)):
- self.core.information('Cannot send result (%s)' % s, 'Error')
+ if not self.api.send_message('%s' % (s,)):
+ self.api.information('Cannot send result (%s)' % s, 'Error')
def completion_mpd(self, the_input):
return the_input.auto_completion(['full'], quotify=False)
diff --git a/plugins/otr.py b/plugins/otr.py
index f3a1d7a2..4e900b84 100644
--- a/plugins/otr.py
+++ b/plugins/otr.py
@@ -13,10 +13,10 @@ class Plugin(BasePlugin):
def init(self):
self.contacts = {}
# a dict of {full-JID: OTR object}
- self.add_event_handler('conversation_say_after', self.on_conversation_say)
- self.add_event_handler('conversation_msg', self.on_conversation_msg)
+ self.api.add_event_handler('conversation_say_after', self.on_conversation_say)
+ self.api.add_event_handler('conversation_msg', self.on_conversation_msg)
- self.add_tab_command(ConversationTab, 'otr', self.command_otr,
+ self.api.add_tab_command(ConversationTab, 'otr', self.command_otr,
usage='<start|end|fpr>',
help='Start or stop OTR for the current conversation.',
short='Manage OTR status',
@@ -113,27 +113,27 @@ class Plugin(BasePlugin):
"""
args = args.split()
if not args:
- return self.core.command_help("otr")
- if isinstance(self.core.current_tab(), ConversationTab):
- jid = JID(self.core.current_tab().get_name())
+ return self.api.run_command("/help otr")
+ if isinstance(self.api.current_tab(), ConversationTab):
+ jid = JID(self.api.current_tab().get_name())
command = args[0]
if command == 'start':
- otr_state = self.get_otr(self.core.current_tab())
- self.otr_say(self.core.current_tab(), otr_state.start().decode())
+ otr_state = self.get_otr(self.api.current_tab())
+ self.otr_say(self.api.current_tab(), otr_state.start().decode())
elif command == 'end':
- otr_state = self.get_otr(self.core.current_tab())
+ otr_state = self.get_otr(self.api.current_tab())
msg = otr_state.end()
if msg is not None:
- self.otr_say(self.core.current_tab(), msg.decode())
+ self.otr_say(self.api.current_tab(), msg.decode())
elif command == 'fpr':
- otr_state = self.get_otr(self.core.current_tab())
+ otr_state = self.get_otr(self.api.current_tab())
our = otr_state.our_fpr
if our:
our = hex(int.from_bytes(our, 'big'))[2:].ljust(40).upper()
their = otr_state.their_fpr
if their:
their = hex(int.from_bytes(their, 'big'))[2:].ljust(40).upper()
- self.core.current_tab().add_message('Your: %s Their: %s' % (our, their))
+ self.api.current_tab().add_message('Your: %s Their: %s' % (our, their))
self.core.refresh_window()
def otr_completion(self, the_input):
diff --git a/plugins/pacokick.py b/plugins/pacokick.py
index 053e6c22..358df013 100644
--- a/plugins/pacokick.py
+++ b/plugins/pacokick.py
@@ -5,13 +5,13 @@ from plugin import BasePlugin
class Plugin(BasePlugin):
def init(self):
- self.add_command('pacokick', self.command_kick,
+ self.api.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()
+ tab = self.api.current_tab()
if isinstance(tab, MucTab):
kickable = list(filter(lambda x: x.affiliation in ('none', 'member'), tab.users))
if kickable:
@@ -20,4 +20,4 @@ class Plugin(BasePlugin):
to_kick = to_kick.nick
tab.command_kick(to_kick + ' ' +arg)
else:
- self.core.information('No one to kick :(', 'Info')
+ self.api.information('No one to kick :(', 'Info')
diff --git a/plugins/ping.py b/plugins/ping.py
index 22401a25..faf3e97d 100644
--- a/plugins/ping.py
+++ b/plugins/ping.py
@@ -8,18 +8,18 @@ import tabs
class Plugin(BasePlugin):
def init(self):
self.core.xmpp.register_plugin('xep_0199')
- self.add_command('ping', self.command_ping,
+ self.api.add_command('ping', self.command_ping,
usage='<jid>',
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,
+ self.api.add_tab_command(tabs.MucTab, 'ping', self.command_muc_ping,
usage='<jid|nick>',
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,
+ self.api.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',
@@ -34,12 +34,12 @@ class Plugin(BasePlugin):
except:
delay = None
if delay is not None:
- self.core.information('%s responded to ping after %s s' % (jid, round(delay, 4)), 'Info')
+ self.api.information('%s responded to ping after %s s' % (jid, round(delay, 4)), 'Info')
else:
- self.core.information('%s did not respond to ping' % jid, 'Info')
+ self.api.information('%s did not respond to ping' % jid, 'Info')
def completion_muc_ping(self, the_input):
- users = [user.nick for user in self.core.current_tab().users]
+ users = [user.nick for user in self.api.current_tab().users]
l = [contact.bare_jid for contact in roster.get_contacts()]
users.extend(l)
return the_input.auto_completion(users, '', quotify=False)
@@ -47,14 +47,14 @@ class Plugin(BasePlugin):
def command_private_ping(self, arg):
if arg:
return self.command_ping(arg)
- self.command_ping(self.core.current_tab().get_name())
+ self.command_ping(self.api.current_tab().get_name())
def command_muc_ping(self, arg):
if not arg.strip():
return
- user = self.core.current_tab().get_user_by_name(arg)
+ user = self.api.current_tab().get_user_by_name(arg)
if user:
- jid = safeJID(self.core.current_tab().get_name())
+ jid = safeJID(self.api.current_tab().get_name())
jid.resource = user.nick
else:
jid = safeJID(arg)
diff --git a/plugins/quote.py b/plugins/quote.py
index ebd9b15e..9b1fd9ad 100644
--- a/plugins/quote.py
+++ b/plugins/quote.py
@@ -13,7 +13,7 @@ log = logging.getLogger(__name__)
class Plugin(BasePlugin):
def init(self):
for _class in (tabs.MucTab, tabs.ConversationTab, tabs.PrivateTab):
- self.add_tab_command(_class, 'quote', self.command_quote,
+ self.api.add_tab_command(_class, 'quote', self.command_quote,
usage='<timestamp>',
help='Takes the message received at <timestamp> and insert it in the input, to quote it.',
short='Quote a message from a timestamp',
@@ -24,9 +24,9 @@ class Plugin(BasePlugin):
if len(args) in (1, 2):
timestamp = args[-1]
else:
- return self.core.command_help('quote')
+ return self.api.run_command('/help quote')
if re.match(timestamp_re, timestamp) is None:
- return self.core.information('Timestamp has a wrong format.', 'Warning')
+ return self.api.information('Timestamp has a wrong format.', 'Warning')
message = self.find_message_with_timestamp(timestamp)
if message:
before = self.config.get('before_quote', '') % {'nick': message.nickname or '',
@@ -37,12 +37,12 @@ class Plugin(BasePlugin):
'quote': clean_text(message.txt),
'after': after.replace('\\n', '\n').replace('[SP]', ' ')})
else:
- self.core.information('No message found for timestamp %s.' % timestamp, 'Warning')
+ self.api.information('No message found for timestamp %s.' % timestamp, 'Warning')
def find_message_with_timestamp(self, timestamp):
# TODO: handle messages with the same
# timestamp but not the same day
- messages = self.core.get_conversation_messages()
+ messages = self.api.get_conversation_messages()
if not messages:
return None
for message in messages[::-1]:
@@ -57,7 +57,7 @@ class Plugin(BasePlugin):
return msg.nickname.lower().startswith(nick.lower())
def time_match(msg):
return msg.str_time.endswith(time)
- messages = self.core.get_conversation_messages()
+ messages = self.api.get_conversation_messages()
if not messages:
return
text = the_input.get_text()
diff --git a/plugins/rainbow.py b/plugins/rainbow.py
index 3c4813d0..4a188b33 100644
--- a/plugins/rainbow.py
+++ b/plugins/rainbow.py
@@ -12,9 +12,9 @@ def rand_color():
class Plugin(BasePlugin):
def init(self):
- self.add_event_handler('muc_say', self.rainbowize)
- self.add_event_handler('private_say', self.rainbowize)
- self.add_event_handler('conversation_say', self.rainbowize)
+ self.api.add_event_handler('muc_say', self.rainbowize)
+ self.api.add_event_handler('private_say', self.rainbowize)
+ self.api.add_event_handler('conversation_say', self.rainbowize)
def rainbowize(self, msg, tab):
msg['body'] = ''.join(['%s%s' % (rand_color(),char,) for char in xhtml.clean_text(msg['body'])])
diff --git a/plugins/reminder.py b/plugins/reminder.py
index 03711906..16a3f710 100644
--- a/plugins/reminder.py
+++ b/plugins/reminder.py
@@ -6,17 +6,17 @@ import timed_events
class Plugin(BasePlugin):
def init(self):
- self.add_command('remind', self.command_remind,
+ self.api.add_command('remind', self.command_remind,
usage='<seconds> <todo>',
help='Remind you of <todo> every <time> seconds.',
short='Remind you of a task',
completion=self.completion_remind)
- self.add_command('done', self.command_done,
+ self.api.add_command('done', self.command_done,
usage='<id>',
help='Stop reminding you do the task identified by <id>.',
short='Remove a task',
completion=self.completion_done)
- self.add_command('tasks', self.command_tasks,
+ self.api.add_command('tasks', self.command_tasks,
usage='',
help='List all the current tasks and their ids.',
short='List current tasks')
@@ -46,8 +46,8 @@ class Plugin(BasePlugin):
self.tasks[self.count] = (time, args[1])
timed_event = timed_events.DelayedEvent(time, self.remind, self.count)
- self.core.add_timed_event(timed_event)
- self.core.information('Task %s added: %s every %s.' % (self.count, args[1],
+ self.api.add_timed_event(timed_event)
+ self.api.information('Task %s added: %s every %s.' % (self.count, args[1],
common.parse_secs_to_str(time)), 'Info')
self.count += 1
@@ -71,7 +71,7 @@ class Plugin(BasePlugin):
if not id in self.tasks:
return
- self.core.information('Task %s: %s [DONE]' % (id, self.tasks[id][1]), 'Info')
+ self.api.information('Task %s: %s [DONE]' % (id, self.tasks[id][1]), 'Info')
del self.tasks[id]
def command_tasks(self, arg, nocommand=None):
@@ -83,16 +83,16 @@ class Plugin(BasePlugin):
s += 'Task %s: %s every %s.\n' % (key, repr(self.tasks[key][1]),
common.parse_secs_to_str(self.tasks[key][0]))
if s:
- self.core.information(s, 'Info')
+ self.api.information(s, 'Info')
def remind(self, id=0):
if not id in self.tasks:
return
- self.core.information('Task %s: %s' % (id, self.tasks[id][1]), 'Info')
+ self.api.information('Task %s: %s' % (id, self.tasks[id][1]), 'Info')
if self.config.get('beep', '') == 'true':
curses.beep()
timed_event = timed_events.DelayedEvent(self.tasks[id][0], self.remind, id)
- self.core.add_timed_event(timed_event)
+ self.api.add_timed_event(timed_event)
def cleanup(self):
if self.tasks:
diff --git a/plugins/replace.py b/plugins/replace.py
index 5fcc971f..abf79648 100644
--- a/plugins/replace.py
+++ b/plugins/replace.py
@@ -13,9 +13,9 @@ from sleekxmpp.xmlstream.stanzabase import JID
class Plugin(BasePlugin):
def init(self):
self.patterns = {}
- self.add_event_handler('conversation_say', self.replace_pattern)
- self.add_event_handler('muc_say', self.replace_pattern)
- self.add_event_handler('private_say', self.replace_pattern)
+ self.api.add_event_handler('conversation_say', self.replace_pattern)
+ self.api.add_event_handler('muc_say', self.replace_pattern)
+ self.api.add_event_handler('private_say', self.replace_pattern)
self.patterns['time'] = replace_time
self.patterns['date'] = replace_date
self.patterns['datetime'] = replace_datetime
diff --git a/plugins/revstr.py b/plugins/revstr.py
index d66e6411..98a6ea1a 100644
--- a/plugins/revstr.py
+++ b/plugins/revstr.py
@@ -2,7 +2,7 @@ from plugin import BasePlugin
class Plugin(BasePlugin):
def init(self):
- self.add_event_handler('muc_say', self.revstr)
+ self.api.add_event_handler('muc_say', self.revstr)
def revstr(self, msg, tab):
msg['body'] = msg['body'][::-1]
diff --git a/plugins/send_delayed.py b/plugins/send_delayed.py
index 253bb027..3f678708 100644
--- a/plugins/send_delayed.py
+++ b/plugins/send_delayed.py
@@ -7,7 +7,7 @@ class Plugin(BasePlugin):
def init(self):
for _class in (tabs.PrivateTab, tabs.ConversationTab, tabs.MucTab):
- self.add_tab_command(_class, 'send_delayed', self.command_delayed,
+ self.api.add_tab_command(_class, 'send_delayed', self.command_delayed,
usage='<delay> <message>',
help='Send <message> with a delay of <delay> seconds.',
short='Send a message later',
@@ -21,9 +21,9 @@ class Plugin(BasePlugin):
if not delay:
return
- tab = self.core.current_tab()
+ tab = self.api.current_tab()
timed_event = timed_events.DelayedEvent(delay, self.say, (tab, args[1]))
- self.core.add_timed_event(timed_event)
+ self.api.add_timed_event(timed_event)
def completion_delay(self, the_input):
txt = the_input.get_text()
diff --git a/plugins/shuffle.py b/plugins/shuffle.py
index beba0769..edf13083 100644
--- a/plugins/shuffle.py
+++ b/plugins/shuffle.py
@@ -3,7 +3,7 @@ from random import shuffle
class Plugin(BasePlugin):
def init(self):
- self.add_event_handler('muc_say', self.shuffle)
+ self.api.add_event_handler('muc_say', self.shuffle)
def shuffle(self, msg, tab):
split = msg['body'].split()
diff --git a/plugins/simple_notify.py b/plugins/simple_notify.py
index d274e0ee..62b1f81a 100644
--- a/plugins/simple_notify.py
+++ b/plugins/simple_notify.py
@@ -5,9 +5,9 @@ import shlex
class Plugin(BasePlugin):
def init(self):
- self.add_event_handler('private_msg', self.on_private_msg)
- self.add_event_handler('conversation_msg', self.on_conversation_msg)
- self.add_event_handler('highlight', self.on_highlight)
+ self.api.add_event_handler('private_msg', self.on_private_msg)
+ self.api.add_event_handler('conversation_msg', self.on_conversation_msg)
+ self.api.add_event_handler('highlight', self.on_highlight)
def on_private_msg(self, message, tab):
fro = message['from']
@@ -27,7 +27,7 @@ class Plugin(BasePlugin):
return
command_str = self.config.get('command', '').strip()
if not command_str:
- self.core.information('No notification command was provided in the configuration file', 'Warning')
+ self.api.information('No notification command was provided in the configuration file', 'Warning')
return
command = [arg % {'body': body.replace('\n', ' '), 'from': fro} for arg in shlex.split(command_str)]
self.core.exec_command(command)
@@ -36,4 +36,4 @@ class Plugin(BasePlugin):
return
after_command = [arg % {'body': body.replace('\n', ' '), 'from': fro} for arg in shlex.split(after_command_str)]
delayed_event = DelayedEvent(self.config.get('delay', 1), self.core.exec_command, after_command)
- self.core.add_timed_event(delayed_event)
+ self.api.add_timed_event(delayed_event)
diff --git a/plugins/status.py b/plugins/status.py
index 38a26d91..7ff55382 100644
--- a/plugins/status.py
+++ b/plugins/status.py
@@ -6,8 +6,8 @@ class Plugin(BasePlugin):
"""
def init(self):
for st in ('dnd', 'busy', 'afk', 'chat', 'xa', 'away', 'available'):
- self.add_command(st,
- lambda line,st=st: self.core.command_status(st + ' "'+line+'"'),
+ self.api.add_command(st,
+ lambda line,st=st: self.api.run_command('/status' + st + ' "'+line+'"'),
usage='[status message]',
short='Set your status as %s' % st,
help='Set your status as %s' % st)
diff --git a/plugins/tell.py b/plugins/tell.py
index f2ed49c8..d4d722af 100644
--- a/plugins/tell.py
+++ b/plugins/tell.py
@@ -4,16 +4,16 @@ import common
class Plugin(BasePlugin):
def init(self):
- self.add_tab_command(tabs.MucTab, 'tell', self.command_tell,
+ self.api.add_tab_command(tabs.MucTab, 'tell', self.command_tell,
usage='<nick> <message>',
help='Will tell <nick> of <message> when he next joins.',
short='Send a message when someone joins')
- self.add_tab_command(tabs.MucTab, 'untell', self.command_untell,
+ self.api.add_tab_command(tabs.MucTab, 'untell', self.command_untell,
usage='<nick>',
help='Remove the planned messages from /tell.',
short='Cancel a /tell message',
completion=self.completion_untell)
- self.add_event_handler('muc_join', self.on_join)
+ self.api.add_event_handler('muc_join', self.on_join)
# {tab -> {nick -> [messages]}
self.tabs = {}
@@ -31,20 +31,20 @@ class Plugin(BasePlugin):
"""/tell <nick> <message>"""
arg = common.shell_split(args)
if len(arg) != 2:
- self.core.command_help('tell')
+ self.command_help('tell')
return
nick, msg = arg
- tab = self.core.current_tab()
+ tab = self.api.current_tab()
if not tab in self.tabs:
self.tabs[tab] = {}
if not nick in self.tabs[tab]:
self.tabs[tab][nick] = []
self.tabs[tab][nick].append(msg)
- self.core.information('Will tell %s' % nick, 'Info')
+ self.api.information('Will tell %s' % nick, 'Info')
def command_untell(self, args):
"""/untell <nick>"""
- tab = self.core.current_tab()
+ tab = self.api.current_tab()
if not tab in self.tabs:
return
nick = args
@@ -53,7 +53,7 @@ class Plugin(BasePlugin):
del self.tabs[tab][nick]
def completion_untell(self, the_input):
- tab = self.core.current_tab()
+ tab = self.api.current_tab()
if not tab in self.tabs:
return the_input.auto_completion([], '')
return the_input.auto_completion(list(self.tabs[tab]), '')
diff --git a/plugins/test.py b/plugins/test.py
index dcb2f7f5..0873ba10 100644
--- a/plugins/test.py
+++ b/plugins/test.py
@@ -3,20 +3,20 @@ import tabs
class Plugin(BasePlugin):
def init(self):
- self.add_command('plugintest', self.command_plugintest, 'Test command')
- self.add_tab_command(tabs.MucTab, 'plugintest', self.command_tab_plugintest, 'Test command')
- self.add_event_handler('message', self.on_message)
- self.core.information("Plugin loaded")
+ self.api.add_command('plugintest', self.command_plugintest, 'Test command')
+ self.api.add_tab_command(tabs.MucTab, 'plugintest', self.command_tab_plugintest, 'Test command')
+ self.api.add_sleek_event_handler('message', self.on_message)
+ self.api.information("Plugin loaded")
def cleanup(self):
- self.core.information("Plugin unloaded")
+ self.api.information("Plugin unloaded")
def on_message(self, message):
- self.core.information("Test plugin received message: {}".format(message))
+ self.api.information("Test plugin received message: {}".format(message))
def command_tab_plugintest(self, args):
- self.core.information("Command for MucTabs! With args {}".format(args))
- self.del_tab_command(tabs.MucTab, 'plugintest')
+ self.api.information("Command for MucTabs! With args {}".format(args))
+ self.api.del_tab_command(tabs.MucTab, 'plugintest')
def command_plugintest(self, args):
- self.core.information("Command! With args {}".format(args))
+ self.api.information("Command! With args {}".format(args))
diff --git a/plugins/time_marker.py b/plugins/time_marker.py
index 02917533..2801ff47 100644
--- a/plugins/time_marker.py
+++ b/plugins/time_marker.py
@@ -16,7 +16,7 @@ from datetime import datetime, timedelta
class Plugin(BasePlugin):
def init(self):
- self.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
# 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
diff --git a/plugins/uptime.py b/plugins/uptime.py
index 5390f9f7..cc47b46f 100644
--- a/plugins/uptime.py
+++ b/plugins/uptime.py
@@ -1,12 +1,11 @@
from plugin import BasePlugin
import tabs
-from common import parse_secs_to_str
+from common import parse_secs_to_str, safeJID
from sleekxmpp.xmlstream import ET
-from sleekxmpp.xmlstream.stanzabase import JID
class Plugin(BasePlugin):
def init(self):
- self.add_command('uptime', self.command_uptime,
+ self.api.add_command('uptime', self.command_uptime,
usage='<jid>',
help='Ask for the uptime of a server or component (see XEP-0012).',
short='Get the uptime')
@@ -14,10 +13,10 @@ class Plugin(BasePlugin):
def command_uptime(self, arg):
def callback(iq):
for query in iq.xml.getiterator('{jabber:iq:last}query'):
- self.core.information('Server %s online since %s' % (iq['from'], parse_secs_to_str(int(query.attrib['seconds']))), 'Info')
+ self.api.information('Server %s online since %s' % (iq['from'], parse_secs_to_str(int(query.attrib['seconds']))), 'Info')
return
- self.core.information('Could not retrieve uptime', 'Error')
- jid = JID(arg)
+ self.api.information('Could not retrieve uptime', 'Error')
+ jid = safeJID(arg)
if not jid.server:
return
iq = self.core.xmpp.makeIqGet(ito=jid.server)
diff --git a/src/core.py b/src/core.py
index 03f892b6..db8c257a 100644
--- a/src/core.py
+++ b/src/core.py
@@ -300,8 +300,12 @@ class Core(object):
Load the plugins on startup.
"""
plugins = config.get('plugins_autoload', '')
- for plugin in plugins.split():
- self.plugin_manager.load(plugin)
+ if ':' in plugins:
+ for plugin in plugins.split(':'):
+ self.plugin_manager.load(plugin)
+ else:
+ for plugin in plugins.split():
+ self.plugin_manager.load(plugin)
self.plugins_autoloaded = True
def start(self):
diff --git a/src/plugin.py b/src/plugin.py
index 2ef83510..9687c1d2 100644
--- a/src/plugin.py
+++ b/src/plugin.py
@@ -119,6 +119,16 @@ class PluginAPI(object):
"""
return self.core.send_message(*args, **kwargs)
+ def get_conversation_messages(self, _, *args, **kwargs):
+ """
+ Get all the Messages of the current Tab.
+
+ :returns: The list of :py:class:`text_buffer.Message` objects.
+ :returns: None if the Tab does not inherit from ChatTab.
+ :rtype: :py:class:`list`
+ """
+ return self.core.get_conversation_messages()
+
def add_timed_event(self, _, *args, **kwargs):
"""
Schedule a timed event.
@@ -331,7 +341,7 @@ class PluginAPI(object):
A list of the SleekXMPP events can be found here
http://sleekxmpp.com/event_index.html
"""
- self.core.xmmp.add_event_handler(event_name, handler)
+ self.core.xmpp.add_event_handler(event_name, handler)
def del_sleek_event_handler(self, module, event_name, handler):
"""