added todo.py.

This commit is contained in:
jesopo 2016-04-05 14:26:46 +01:00
parent f9ce711b25
commit f19389ec8c
No known key found for this signature in database
GPG key ID: 0BBDEB2AEFCFFCB3
2 changed files with 50 additions and 1 deletions

View file

@ -40,7 +40,6 @@ class Module(object):
"api_key": self.bot.config["lastfm-api-key"],
"user": username, "format": "json"}, json=True)
tags = []
print(info_page.keys())
if "toptags" in info_page["track"]:
for tag in info_page["track"]["toptags"]["tag"]:
tags.append(tag["name"])

50
modules/todo.py Normal file
View file

@ -0,0 +1,50 @@
class Module(object):
def __init__(self, bot):
self.bot = bot
bot.events.on("received").on("command").on("todo").hook(
self.todo)
def todo(self, event):
if len(event["args_split"]) > 1:
action = event["args_split"][0].lower()
arg = " ".join(event["args_split"][1:])
arg_lower = arg.lower()
todo = event["user"].get_setting("todo", [])
if action == "add":
for item in todo:
if item.lower() == arg_lower:
event["stderr"].write(
"That is already in your todo")
return
todo.append(arg)
event["user"].set_setting("todo", list(todo))
event["stdout"].write("Saved")
elif action == "remove":
if event["args_split"][1].isdigit():
index = int(event["args_split"][1])
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")
elif action == "show":
if event["args_split"][1].isdigit():
index = int(event["args_split"][1])
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 todo item number to show")
elif len(event["args_split"]) == 1:
event["stderr"].write("Please provided an action and an argument")
else:
todo_count = len(event["user"].get_setting("todo", []))
event["stdout"].write("There are %d items in your todo" % todo_count)