Add stop command to countdown plugin
This commit is contained in:
parent
1a71dd8a1e
commit
600cba1631
1 changed files with 17 additions and 8 deletions
|
@ -6,7 +6,7 @@ import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
LOGGER = logging.getLogger('countdown')
|
LOGGER = logging.getLogger('countdown')
|
||||||
MESSAGE_RE = re.compile(r'(!countdown)\s+(\d+)')
|
COUNTDOWN_RE = re.compile(r'(!countdown)\s+(\d+|stop)\s*')
|
||||||
|
|
||||||
# rtmbot interface
|
# rtmbot interface
|
||||||
crontable = []
|
crontable = []
|
||||||
|
@ -25,23 +25,32 @@ def process_message(data):
|
||||||
LOGGER.error('Missing "text" key in data.')
|
LOGGER.error('Missing "text" key in data.')
|
||||||
return
|
return
|
||||||
|
|
||||||
match = MESSAGE_RE.match(text)
|
match = COUNTDOWN_RE.match(text)
|
||||||
if not match:
|
if not match:
|
||||||
return
|
return
|
||||||
|
|
||||||
cmd = match.group(1)
|
cmd = match.group(1)
|
||||||
if not cmd:
|
if not cmd:
|
||||||
return
|
return
|
||||||
try:
|
|
||||||
n = int(match.group(2))
|
|
||||||
except ValueError:
|
|
||||||
LOGGER.error('Expected number but got {}'.format(match.group(2)))
|
|
||||||
return
|
|
||||||
|
|
||||||
_setup_timer(data['channel'], n)
|
arg = match.group(2)
|
||||||
|
if arg == 'stop':
|
||||||
|
_kill_countdowns()
|
||||||
|
outputs.append([data['channel'], 'Stopped all countdowns.'])
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
n = int(match.group(2))
|
||||||
|
except ValueError:
|
||||||
|
LOGGER.error('Expected number but got {}'.format(match.group(2)))
|
||||||
|
return
|
||||||
|
_setup_timer(data['channel'], n)
|
||||||
|
|
||||||
def _setup_timer(channel, time):
|
def _setup_timer(channel, time):
|
||||||
COUNTDOWNS.append([channel, time])
|
COUNTDOWNS.append([channel, time])
|
||||||
|
|
||||||
|
def _kill_countdowns():
|
||||||
|
del COUNTDOWNS[:]
|
||||||
|
|
||||||
def _do_countdown():
|
def _do_countdown():
|
||||||
global COUNTDOWNS
|
global COUNTDOWNS
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue