forked from hubotio/hubot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse.coffee
92 lines (82 loc) · 2.62 KB
/
response.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
class Response
# Public: Responses are sent to matching listeners. Messages know about the
# content and user that made the original message, and how to reply back to
# them.
#
# robot - A Robot instance.
# message - A Message instance.
# match - A Match object from the successful Regex match.
constructor: (@robot, @message, @match) ->
@envelope =
room: @message.room
user: @message.user
message: @message
# Public: Posts a message back to the chat source
#
# strings - One or more strings to be posted. The order of these strings
# should be kept intact.
#
# Returns nothing.
send: (strings...) ->
@robot.adapter.send @envelope, strings...
# Public: Posts an emote back to the chat source
#
# strings - One or more strings to be posted. The order of these strings
# should be kept intact.
#
# Returns nothing.
emote: (strings...) ->
@robot.adapter.emote @envelope, strings...
# Public: Posts a message mentioning the current user.
#
# strings - One or more strings to be posted. The order of these strings
# should be kept intact.
#
# Returns nothing.
reply: (strings...) ->
@robot.adapter.reply @envelope, strings...
# Public: Posts a topic changing message
#
# strings - One or more strings to set as the topic of the
# room the bot is in.
#
# Returns nothing.
topic: (strings...) ->
@robot.adapter.topic @envelope, strings...
# Public: Play a sound in the chat source
#
# strings - One or more strings to be posted as sounds to play. The order of
# these strings should be kept intact.
#
# Returns nothing
play: (strings...) ->
@robot.adapter.play @envelope, strings...
# Public: Posts a message in an unlogged room
#
# strings - One or more strings to be posted. The order of these strings
# should be kept intact.
#
# Returns nothing
locked: (strings...) ->
@robot.adapter.locked @envelope, strings...
# Public: Picks a random item from the given items.
#
# items - An Array of items.
#
# Returns a random item.
random: (items) ->
items[ Math.floor(Math.random() * items.length) ]
# Public: Tell the message to stop dispatching to listeners
#
# Returns nothing.
finish: ->
@message.finish()
# Public: Creates a scoped http client with chainable methods for
# modifying the request. This doesn't actually make a request though.
# Once your request is assembled, you can call `get()`/`post()`/etc to
# send the request.
#
# Returns a ScopedClient instance.
http: (url) ->
@robot.http(url)
module.exports = Response