2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-04-05 13:26:46 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.todo")
|
2016-04-05 13:26:46 +00:00
|
|
|
def todo(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Find out what's in your todo list
|
|
|
|
:usage: [item number]
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2016-04-06 15:38:46 +00:00
|
|
|
todo = event["user"].get_setting("todo", [])
|
|
|
|
if event["args"]:
|
|
|
|
if event["args_split"][0].isdigit() and int(event["args_split"][0]) > 0:
|
|
|
|
index = int(event["args_split"][0])
|
|
|
|
if len(todo) >= index:
|
|
|
|
event["stdout"].write("Todo %d: %s" % (index, todo[index-1]))
|
2016-04-05 13:26:46 +00:00
|
|
|
else:
|
2016-04-06 15:38:46 +00:00
|
|
|
event["stderr"].write("You do not have that many things in your todo")
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Please provide a number")
|
2016-04-05 13:26:46 +00:00
|
|
|
else:
|
2016-04-06 15:38:46 +00:00
|
|
|
todo_count = len(todo)
|
2016-04-05 13:26:46 +00:00
|
|
|
event["stdout"].write("There are %d items in your todo" % todo_count)
|
2016-04-06 15:38:46 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.todoadd", min_args=1)
|
2016-04-06 15:38:46 +00:00
|
|
|
def todo_add(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Add something to your todo list
|
|
|
|
:usage: <description>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2016-04-06 15:38:46 +00:00
|
|
|
arg_lower = event["args"].lower()
|
|
|
|
todo = event["user"].get_setting("todo", [])
|
|
|
|
for item in todo:
|
|
|
|
if item.lower() == arg_lower:
|
|
|
|
event["stderr"].write(
|
|
|
|
"That is already in your todo")
|
|
|
|
return
|
|
|
|
todo.append(event["args"])
|
|
|
|
event["user"].set_setting("todo", todo)
|
|
|
|
event["stdout"].write("Saved")
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.tododel", min_args=1)
|
2016-04-06 15:38:46 +00:00
|
|
|
def todo_del(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Remove something from your todo list
|
|
|
|
:usage: <item number>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2016-04-06 15:38:46 +00:00
|
|
|
todo = event["user"].get_setting("todo", [])
|
|
|
|
if event["args_split"][0].isdigit() and int(event["args_split"][0]) > 0:
|
|
|
|
index = int(event["args_split"][0])
|
|
|
|
if len(todo) >= index:
|
|
|
|
todo.pop(index-1)
|
|
|
|
event["user"].set_setting("todo", todo)
|
|
|
|
event["stdout"].write("Todo item removed")
|
|
|
|
else:
|
|
|
|
event["stderr"].write("You do not have that many things in "
|
|
|
|
"your todo")
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Please provided a todo item number to remove")
|