From ab3d1e4cc55b82dbfe38ee3aa1376801153e625d Mon Sep 17 00:00:00 2001 From: Ryan Huber Date: Tue, 18 Nov 2014 10:20:15 -0800 Subject: [PATCH] added another example plugin --- doc/example-plugins/counter.py | 4 ++-- doc/example-plugins/repeat2.py | 8 -------- doc/example-plugins/todo.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) delete mode 100644 doc/example-plugins/repeat2.py create mode 100644 doc/example-plugins/todo.py diff --git a/doc/example-plugins/counter.py b/doc/example-plugins/counter.py index 5846c94..84e9012 100644 --- a/doc/example-plugins/counter.py +++ b/doc/example-plugins/counter.py @@ -2,8 +2,8 @@ import time crontable = [] outputs = [] -#crontable.append([.5,"add_number"]) crontable.append([5,"say_time"]) def say_time(): - outputs.append(["D030GJLM2", time.time()]) + #NOTE: you must add a real channel ID for this to work + outputs.append(["D12345678", time.time()]) diff --git a/doc/example-plugins/repeat2.py b/doc/example-plugins/repeat2.py deleted file mode 100644 index 95738fc..0000000 --- a/doc/example-plugins/repeat2.py +++ /dev/null @@ -1,8 +0,0 @@ -import time -crontable = [] -outputs = [] - -def process_message(data): - if data['channel'].startswith("D"): - outputs.append([data['channel'], "from repeat2: " + data['text']]) - diff --git a/doc/example-plugins/todo.py b/doc/example-plugins/todo.py new file mode 100644 index 0000000..cdfc92b --- /dev/null +++ b/doc/example-plugins/todo.py @@ -0,0 +1,31 @@ +outputs = [] +crontabs = [] + +tasks = {} + +def process_message(data): + global tasks + channel = data["channel"] + text = data["text"] + #only accept tasks on DM channels + if channel.startswith("D") or channel.startswith("C"): + if channel not in tasks.keys(): + tasks[channel] = [] + #do command stuff + 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": + print tasks