from src import ModuleManager, Utils class Module(ModuleManager.BaseModule): @Utils.hook("received.command.todo", usage="[item number]") def todo(self, event): """ Find out what's in your todo list """ 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])) else: event["stderr"].write("You do not have that many things in your todo") else: event["stderr"].write("Please provide a number") else: todo_count = len(todo) event["stdout"].write("There are %d items in your todo" % todo_count) @Utils.hook("received.command.todoadd", min_args=1, usage="") def todo_add(self, event): """ Add something to your todo list """ 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") @Utils.hook("received.command.tododel", min_args=1, usage="") def todo_del(self, event): """ Remove something from your todo list """ 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")