forked from sota1235/slack-hubot
/
linda-light.coffee
46 lines (40 loc) · 1.13 KB
/
linda-light.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Description:
# lindaで明かりをつける
#
# Commands:
# hubot [tuplespace] 電気(つけて|消して)
#
# Author:
# @napo, @nikezono
module.exports = (robot) ->
robot.on 'linda:ready', (linda) ->
robot.respond /([a-z_\-]+) 電気(つけて|消して)/i, (msg) ->
who = msg.message.user.name
where = msg.match[1]
cmd = switch msg.match[2]
when "つけて" then "on"
when "消して" then "off"
linda.read_with_timeout linda.config.space,
name: "light"
cmd: cmd
response: "success"
, 5000, (err, tuple) ->
if err
msg.send "@#{who} ダメっぽい(失敗)"
return
msg.send switch cmd
when "on" then "@#{who} つけたと思う"
when "off" then "@#{who} 消したと思う"
linda.tuplespace(linda.config.space).write
name: "light"
cmd: cmd
where: where
return
robot.respond /(電気|light)/i, (msg) ->
msg.send """
hubotで電気をつける・消す
(例)
hubot delta 電気つけて
hubot delta 電気消して
"""
return