Merge branch 'master' of http://git.louiz.org/poezio
This commit is contained in:
commit
4e201be745
3 changed files with 59 additions and 11 deletions
|
@ -6,12 +6,25 @@ import timed_events
|
||||||
class Plugin(BasePlugin):
|
class Plugin(BasePlugin):
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
self.add_command('remind', self.command_remind, "Usage: /reminder <time in seconds> <todo>\nReminder: remind you of <todo> every <time> seconds..", None)
|
self.add_command('remind', self.command_remind, "Usage: /reminder <time in seconds> <todo>\nReminder: remind you of <todo> every <time> seconds..", self.completion_remind)
|
||||||
self.add_command('done', self.command_done, "Usage: /done <id>\nDone: Stop reminding you do the task identified by <id>", None)
|
self.add_command('done', self.command_done, "Usage: /done <id>\nDone: Stop reminding you do the task identified by <id>", self.completion_done)
|
||||||
self.add_command('tasks', self.command_tasks, "Usage: /tasks\nTasks: List all the current tasks and their ids.", None)
|
self.add_command('tasks', self.command_tasks, "Usage: /tasks\nTasks: List all the current tasks and their ids.", None)
|
||||||
self.tasks = {}
|
self.tasks = {}
|
||||||
self.count = 0
|
self.count = 0
|
||||||
|
|
||||||
|
for option in self.config.options(self.__module__):
|
||||||
|
id, secs = option.split(',')
|
||||||
|
id = int(id)
|
||||||
|
if id > self.count:
|
||||||
|
self.count = id
|
||||||
|
value = self.config.get(option, '')
|
||||||
|
self.tasks[id] = (int(secs), value)
|
||||||
|
self.config.remove_section(self.__module__)
|
||||||
|
self.config.add_section(self.__module__)
|
||||||
|
if self.tasks:
|
||||||
|
self.count += 1
|
||||||
|
self.command_tasks('', nocommand=True)
|
||||||
|
|
||||||
def command_remind(self, arg):
|
def command_remind(self, arg):
|
||||||
args = common.shell_split(arg)
|
args = common.shell_split(arg)
|
||||||
if len(args) < 2:
|
if len(args) < 2:
|
||||||
|
@ -24,8 +37,21 @@ class Plugin(BasePlugin):
|
||||||
self.tasks[self.count] = (time, args[1])
|
self.tasks[self.count] = (time, args[1])
|
||||||
timed_event = timed_events.DelayedEvent(time, self.remind, self.count)
|
timed_event = timed_events.DelayedEvent(time, self.remind, self.count)
|
||||||
self.core.add_timed_event(timed_event)
|
self.core.add_timed_event(timed_event)
|
||||||
|
self.core.information('Task %s added: %s every %s seconds.' % (self.count, args[1], time), 'Info')
|
||||||
self.count += 1
|
self.count += 1
|
||||||
|
|
||||||
|
def completion_remind(self, the_input):
|
||||||
|
txt = the_input.get_text()
|
||||||
|
args = common.shell_split(txt)
|
||||||
|
n = len(args)
|
||||||
|
if txt.endswith(' '):
|
||||||
|
n += 1
|
||||||
|
if n == 2:
|
||||||
|
return the_input.auto_completion(["60", "300", "600", "900", "3600", "36000", "86400"], '')
|
||||||
|
|
||||||
|
def completion_done(self, the_input):
|
||||||
|
return the_input.auto_completion(["%s" % key for key in self.tasks], '')
|
||||||
|
|
||||||
def command_done(self, arg="0"):
|
def command_done(self, arg="0"):
|
||||||
try:
|
try:
|
||||||
id = int(arg)
|
id = int(arg)
|
||||||
|
@ -34,12 +60,16 @@ class Plugin(BasePlugin):
|
||||||
if not id in self.tasks:
|
if not id in self.tasks:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.core.information('Task %s: %s [DONE]' % (id, self.tasks[id][1]), 'Info')
|
||||||
del self.tasks[id]
|
del self.tasks[id]
|
||||||
|
|
||||||
def command_tasks(self, arg):
|
def command_tasks(self, arg, nocommand=None):
|
||||||
s = ''
|
if nocommand:
|
||||||
|
s = 'The following tasks were loaded:\n'
|
||||||
|
else:
|
||||||
|
s = 'The following tasks are active:\n'
|
||||||
for key in self.tasks:
|
for key in self.tasks:
|
||||||
s += '%s: %s\n' % key, self.tasks[key][1]
|
s += 'Task %s: %s every %s seconds.\n' % (key, repr(self.tasks[key][1]), self.tasks[key][0])
|
||||||
if s:
|
if s:
|
||||||
self.core.information(s, 'Info')
|
self.core.information(s, 'Info')
|
||||||
|
|
||||||
|
@ -52,5 +82,10 @@ class Plugin(BasePlugin):
|
||||||
timed_event = timed_events.DelayedEvent(self.tasks[id][0], self.remind, id)
|
timed_event = timed_events.DelayedEvent(self.tasks[id][0], self.remind, id)
|
||||||
self.core.add_timed_event(timed_event)
|
self.core.add_timed_event(timed_event)
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
|
if self.tasks:
|
||||||
|
self.config.remove_section(self.__module__)
|
||||||
|
self.config.add_section(self.__module__)
|
||||||
|
for task in self.tasks:
|
||||||
|
self.config.set('%s,%s' % (task, self.tasks[task][0]), self.tasks[task][1])
|
||||||
|
self.config.write()
|
||||||
|
|
|
@ -16,6 +16,11 @@ class PluginConfig(config.Config):
|
||||||
section = self.module_name
|
section = self.module_name
|
||||||
return config.Config.get(self, option, default, section)
|
return config.Config.get(self, option, default, section)
|
||||||
|
|
||||||
|
def set(self, option, default, section=None):
|
||||||
|
if not section:
|
||||||
|
section = self.module_name
|
||||||
|
return config.Config.set(self, option, default, section)
|
||||||
|
|
||||||
def read(self):
|
def read(self):
|
||||||
"""Read the config file"""
|
"""Read the config file"""
|
||||||
RawConfigParser.read(self, self.file_name)
|
RawConfigParser.read(self, self.file_name)
|
||||||
|
|
16
src/tabs.py
16
src/tabs.py
|
@ -152,10 +152,10 @@ class Tab(object):
|
||||||
if len(txt.split()) > 1 or\
|
if len(txt.split()) > 1 or\
|
||||||
(txt.endswith(' ') and not the_input.last_completion):
|
(txt.endswith(' ') and not the_input.last_completion):
|
||||||
command_name = txt.split()[0][1:]
|
command_name = txt.split()[0][1:]
|
||||||
if command_name in self.core.commands:
|
if command_name in self.commands:
|
||||||
command = self.core.commands[command_name]
|
|
||||||
elif command_name in self.commands:
|
|
||||||
command = self.commands[command_name]
|
command = self.commands[command_name]
|
||||||
|
elif command_name in self.core.commands:
|
||||||
|
command = self.core.commands[command_name]
|
||||||
else: # Unknown command, cannot complete
|
else: # Unknown command, cannot complete
|
||||||
return False
|
return False
|
||||||
if command[2] is None:
|
if command[2] is None:
|
||||||
|
@ -494,12 +494,20 @@ class MucTab(ChatTab):
|
||||||
self.commands['cycle'] = (self.command_cycle, _('Usage: /cycle [message]\nCycle: Leave the current room and rejoin it immediately.'), None)
|
self.commands['cycle'] = (self.command_cycle, _('Usage: /cycle [message]\nCycle: Leave the current room and rejoin it immediately.'), None)
|
||||||
self.commands['info'] = (self.command_info, _('Usage: /info <nickname>\nInfo: Display some information about the user in the MUC: its/his/her role, affiliation, status and status message.'), self.completion_ignore)
|
self.commands['info'] = (self.command_info, _('Usage: /info <nickname>\nInfo: Display some information about the user in the MUC: its/his/her role, affiliation, status and status message.'), self.completion_ignore)
|
||||||
self.commands['configure'] = (self.command_configure, _('Usage: /configure\nConfigure: Configure the current room, through a form.'), None)
|
self.commands['configure'] = (self.command_configure, _('Usage: /configure\nConfigure: Configure the current room, through a form.'), None)
|
||||||
self.commands['version'] = (self.command_version, _('Usage: /version <jid or nick>\nVersion: Get the software version of the given JID or nick in room (usually its XMPP client and Operating System).'), None)
|
self.commands['version'] = (self.command_version, _('Usage: /version <jid or nick>\nVersion: Get the software version of the given JID or nick in room (usually its XMPP client and Operating System).'), self.completion_version)
|
||||||
self.commands['names'] = (self.command_names, _('Usage: /names\nNames: Get the list of the users in the room, and the list of the people assuming the different roles.'), None)
|
self.commands['names'] = (self.command_names, _('Usage: /names\nNames: Get the list of the users in the room, and the list of the people assuming the different roles.'), None)
|
||||||
self.resize()
|
self.resize()
|
||||||
self.update_commands()
|
self.update_commands()
|
||||||
self.update_keys()
|
self.update_keys()
|
||||||
|
|
||||||
|
def completion_version(self, the_input):
|
||||||
|
"""Completion for /version"""
|
||||||
|
userlist = [user.nick for user in self.users]
|
||||||
|
userlist.remove(self.own_nick)
|
||||||
|
contact_list = [contact.bare_jid for contact in roster.get_contacts()]
|
||||||
|
userlist.extend(contact_list)
|
||||||
|
return the_input.auto_completion(userlist, '')
|
||||||
|
|
||||||
def completion_nick(self, the_input):
|
def completion_nick(self, the_input):
|
||||||
"""Completion for /nick"""
|
"""Completion for /nick"""
|
||||||
nicks = [os.environ.get('USER'), config.get('default_nick', ''), self.core.get_bookmark_nickname(self.get_name())]
|
nicks = [os.environ.get('USER'), config.get('default_nick', ''), self.core.get_bookmark_nickname(self.get_name())]
|
||||||
|
|
Loading…
Reference in a new issue