Last active
September 6, 2017 10:19
-
-
Save attakei/6d43b8733d891b98a9b6a3bcf9b902a3 to your computer and use it in GitHub Desktop.
Timer demo for errbot
This file contains 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
[Core] | |
Name = Timer | |
Module = timer | |
[Documentation] | |
Description = Timer | |
This file contains 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
from errbot import BotPlugin, botcmd, arg_botcmd | |
class Timer(BotPlugin): | |
@arg_botcmd('min', type=int) | |
def noodle_timer(self, msg, min): | |
self.start_poller(min * 60, self.finished, (msg.frm, min,)) | |
return 'Start {} mins'.format(min) | |
@botcmd | |
def talk_timer(self, msg, args): | |
mins = [int(m) for m in args.split()] | |
sum_ = sum(mins) | |
self.start_poller(0, self._timer, (msg.frm, mins,)) | |
def _timer(self, frm, mins): | |
self.stop_poller(self._timer, (frm, mins,)) | |
if len(mins) < 1: | |
self.send(frm, 'Time is overed') | |
return | |
sum_ = sum(mins) | |
self.send(frm, 'Rest {} mins'.format(sum_)) | |
min = mins[0] | |
mins = mins[1:] | |
self.start_poller(min * 60, self._timer, (frm, mins,)) | |
def finished(self, frm, min): | |
self.send(frm, 'Finished') | |
self.stop_poller(self.finished, (frm, min,)) | |
@botcmd | |
def hello(self, msg, args): | |
return 'Hello {}!, ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment