2016-04-15 14:49:38 -07:00
|
|
|
from __future__ import print_function
|
2016-06-05 13:28:28 -07:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
# don't convert to ascii in py2.7 when creating string to return
|
|
|
|
|
2014-11-21 21:25:27 -08:00
|
|
|
import os
|
|
|
|
import pickle
|
|
|
|
|
2014-11-18 10:20:15 -08:00
|
|
|
outputs = []
|
|
|
|
crontabs = []
|
|
|
|
|
|
|
|
tasks = {}
|
|
|
|
|
2016-04-15 14:03:20 -07:00
|
|
|
|
|
|
|
FILE = "plugins/todo.data"
|
2014-11-21 21:25:27 -08:00
|
|
|
if os.path.isfile(FILE):
|
|
|
|
tasks = pickle.load(open(FILE, 'rb'))
|
|
|
|
|
2016-04-15 14:03:20 -07:00
|
|
|
|
2014-11-18 10:20:15 -08:00
|
|
|
def process_message(data):
|
|
|
|
global tasks
|
|
|
|
channel = data["channel"]
|
|
|
|
text = data["text"]
|
2016-04-15 14:03:20 -07:00
|
|
|
# only accept tasks on DM channels
|
2014-11-18 11:43:57 -08:00
|
|
|
if channel.startswith("D"):
|
2014-11-18 10:20:15 -08:00
|
|
|
if channel not in tasks.keys():
|
|
|
|
tasks[channel] = []
|
2016-04-15 14:03:20 -07:00
|
|
|
# do command stuff
|
2014-11-18 10:20:15 -08:00
|
|
|
if text.startswith("todo"):
|
|
|
|
tasks[channel].append(text[5:])
|
|
|
|
outputs.append([channel, "added"])
|
|
|
|
if text == "tasks":
|
|
|
|
output = ""
|
|
|
|
counter = 1
|
|
|
|
for task in tasks[channel]:
|
|
|
|
output += "%i) %s\n" % (counter, task)
|
|
|
|
counter += 1
|
|
|
|
outputs.append([channel, output])
|
|
|
|
if text == "fin":
|
|
|
|
tasks[channel] = []
|
|
|
|
if text.startswith("done"):
|
|
|
|
num = int(text.split()[1]) - 1
|
|
|
|
tasks[channel].pop(num)
|
|
|
|
if text == "show":
|
2016-04-15 14:49:38 -07:00
|
|
|
print(tasks)
|
2016-04-15 14:03:20 -07:00
|
|
|
pickle.dump(tasks, open(FILE, "wb"))
|