Last active
November 9, 2015 20:36
-
-
Save arkag/3498a65a7fb68a72621c to your computer and use it in GitHub Desktop.
Bot thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import pickle | |
| from collections import defaultdict | |
| outputs = [] | |
| crontabs = [] | |
| tasks = defaultdict(list) | |
| FILE = 'plugins/todo.data' | |
| if os.path.isfile(FILE): | |
| tasks = pickle.load(open(FILE, 'rb')) | |
| def process_message(data): | |
| global tasks | |
| channel = data['channel'] | |
| user = data['user'] | |
| action, text, num = delim(data['text']) | |
| if data['channel'].startswith("D"): | |
| # do command stuff | |
| if action == 'help': | |
| outputs.append([channel, 'Here is some help: ```NO```']) | |
| elif action == 'add': | |
| tasks[user].append(text) | |
| outputs.append([channel, 'added']) | |
| elif action == 'tasks': | |
| output = '' | |
| counter = 1 | |
| for task in tasks[user]: | |
| output += '%i: %s\n' % (counter, task) | |
| counter += 1 | |
| outputs.append([channel, output]) | |
| elif action == 'clear': | |
| tasks[user] = [] | |
| elif action == 'done': | |
| outputs.append([channel, 'Removing task: ' + tasks[user].pop(num)]) | |
| elif text == 'show': | |
| print tasks | |
| pickle.dump(tasks, open(FILE, 'wb')) | |
| def delim(msg): | |
| msg = msg.split() | |
| if msg[0] == u'<@U0E4887DF>': | |
| if(msg[1] == 'done'): | |
| return msg[1], ' '.join(msg[3:]), msg[2] | |
| return msg[1], ' '.join(msg[2:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment