Skip to content
Newer
Older
100644 454 lines (391 sloc) 13.4 KB
f0cf411 @atmos OCD ordering/spacing
atmos authored Dec 24, 2011
1 Fs = require 'fs'
2 Url = require 'url'
3 Log = require 'log'
4 Path = require 'path'
5 Connect = require 'connect'
ce8bb29 Extract User and Brain into their own files
Tom Bell authored Nov 20, 2011
6
f0cf411 @atmos OCD ordering/spacing
atmos authored Dec 24, 2011
7 User = require './user'
8 Brain = require './brain'
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
9
bc7403e Update logging in Campfire adapter
Tom Bell authored Nov 22, 2011
10 HUBOT_DEFAULT_ADAPTERS = [ "campfire", "shell" ]
11
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
12 class Robot
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
13 # Robots receive messages from a chat source (Campfire, irc, etc), and
14 # dispatch them to matching listeners.
15 #
16 # path - String directory full of Hubot scripts to load.
5fd81c3 @tombell Add switch for disabling the http server
tombell authored Dec 24, 2011
17 constructor: (adapterPath, adapter, httpd, name = "Hubot") ->
be6b76b @atmos enable '/' instead of hubot as a cli opt
atmos authored Oct 10, 2011
18 @name = name
ce8bb29 Extract User and Brain into their own files
Tom Bell authored Nov 20, 2011
19 @brain = new Brain
d8c60d4 @atmos Merge branch 'master' into core-cleanup
atmos authored Nov 16, 2011
20 @alias = false
21 @adapter = null
be6b76b @atmos enable '/' instead of hubot as a cli opt
atmos authored Oct 11, 2011
22 @commands = []
23 @Response = Robot.Response
24 @listeners = []
25 @loadPaths = []
26 @enableSlash = false
ad04da1 squish log level into new Log
Tom Bell authored Nov 22, 2011
27 @logger = new Log process.env.HUBOT_LOG_LEVEL or "info"
30644f5 Add initial logger calls replacing console.log
Tom Bell authored Nov 22, 2011
28
fb48ead @atmos working http interface
atmos authored Dec 24, 2011
29 @parseVersion()
5fd81c3 @tombell Add switch for disabling the http server
tombell authored Dec 24, 2011
30 @setupConnect() if httpd
d9497ad update danger adapter
Tom Bell authored Nov 19, 2011
31 @loadAdapter adapterPath, adapter if adapter?
792567b Update Campfire, IRC and Shell adapters
Tom Bell authored Nov 4, 2011
32
315b721 @tombell Add `route` function on Robot
tombell authored Dec 24, 2011
33 # Public: Specify a router and callback to register as Connect middleware.
34 #
35 # route - A String of the route to match.
36 # callback - A Function that is called when the route is requested
37 #
38 # Returns nothing.
39 route: (route, callback) ->
14f92b7 @atmos have a default port and use the router for route
atmos authored Dec 24, 2011
40 @router.get route, callback
315b721 @tombell Add `route` function on Robot
tombell authored Dec 24, 2011
41
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
42 # Public: Adds a Listener that attempts to match incoming messages based on
43 # a Regex.
44 #
45 # regex - A Regex that determines if the callback should be called.
46 # callback - A Function that is called with a Response object.
47 #
48 # Returns nothing.
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
49 hear: (regex, callback) ->
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored Oct 26, 2011
50 @listeners.push new TextListener(@, regex, callback)
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
51
bbf0c75 Update formatting
Tom Bell authored Oct 26, 2011
52 # Public: Adds a Listener that attempts to match incoming messages directed
53 # at the robot based on a Regex. All regexes treat patterns like they begin
54 # with a '^'
be5fce6 @atmos hubot listen or be addressed in chat. fixes #4
atmos authored Sep 9, 2011
55 #
56 # regex - A Regex that determines if the callback should be called.
57 # callback - A Function that is called with a Response object.
58 #
59 # Returns nothing.
60 respond: (regex, callback) ->
61 re = regex.toString().split("/")
18beda1 @atmos handle slashes in regexes properly
atmos authored Oct 16, 2011
62 re.shift() # remove empty first item
63 modifiers = re.pop() # pop off modifiers
64
6780d7a Update equality checks to use 'is'
Tom Bell authored Oct 26, 2011
65 if re[0] and re[0][0] is "^"
30644f5 Add initial logger calls replacing console.log
Tom Bell authored Nov 22, 2011
66 @logger.warning "Anchors don't work well with respond, perhaps you want to use 'hear'"
67 @logger.warning "The regex in question was #{regex.toString()}"
ce149d9 @atmos warn about anchors not working with respond, fixes #10
atmos authored Oct 10, 2011
68
18beda1 @atmos handle slashes in regexes properly
atmos authored Oct 16, 2011
69 pattern = re.join("/") # combine the pattern back again
bc7403e Update logging in Campfire adapter
Tom Bell authored Nov 22, 2011
70
a39b823 @Vrtak-CZ Add --alias (--enable-slash is deprecated)
Vrtak-CZ authored Nov 6, 2011
71 if @alias
72 alias = @alias.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") # escape alias for regexp
8d925d4 @igorgue Added punctuation to the alias too.
igorgue authored Nov 20, 2011
73 newRegex = new RegExp("^(?:#{alias}[:,]?|#{@name}[:,]?)\\s*(?:#{pattern})", modifiers)
be6b76b @atmos enable '/' instead of hubot as a cli opt
atmos authored Oct 11, 2011
74 else
fc33244 @lautis Allow comma when addressing Hubot
lautis authored Nov 3, 2011
75 newRegex = new RegExp("^#{@name}[:,]?\\s*(?:#{pattern})", modifiers)
18beda1 @atmos handle slashes in regexes properly
atmos authored Oct 16, 2011
76
30644f5 Add initial logger calls replacing console.log
Tom Bell authored Nov 22, 2011
77 @logger.debug newRegex.toString()
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored Oct 26, 2011
78 @listeners.push new TextListener(@, newRegex, callback)
79
80 # Public: Adds a Listener that triggers when anyone enters the room.
81 #
82 # callback - A Function that is called with a Response object.
83 #
84 # Returns nothing.
85 enter: (callback) ->
86 @listeners.push new Listener(@, ((msg) -> msg instanceof Robot.EnterMessage), callback)
87
88 # Public: Adds a Listener that triggers when anyone leaves the room.
89 #
90 # callback - A Function that is called with a Response object.
91 #
92 # Returns nothing.
93 leave: (callback) ->
94 @listeners.push new Listener(@, ((msg) -> msg instanceof Robot.LeaveMessage), callback)
be5fce6 @atmos hubot listen or be addressed in chat. fixes #4
atmos authored Sep 9, 2011
95
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
96 # Public: Passes the given message to any interested Listeners.
97 #
1737347 @atmos add Response.finish() to indicate a message is "handled"
atmos authored Dec 23, 2011
98 # message - A Robot.Message instance. Listeners can flag this message as
99 # 'done' to prevent further execution
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
100 #
101 # Returns nothing.
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
102 receive: (message) ->
1737347 @atmos add Response.finish() to indicate a message is "handled"
atmos authored Dec 24, 2011
103 for listener in @listeners
0e69b33 @atmos shift around the done handling
atmos authored Dec 23, 2011
104 try
105 listener.call message
74eb585 @tombell Update behaviour of finishing further execution
tombell authored Dec 24, 2011
106 break if message.done
0e69b33 @atmos shift around the done handling
atmos authored Dec 24, 2011
107 catch ex
108 @logger.error "Unable to call the listener: #{ex}"
1737347 @atmos add Response.finish() to indicate a message is "handled"
atmos authored Dec 24, 2011
109
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
110
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
111 # Public: Loads every script in the given path.
112 #
113 # path - A String path on the filesystem.
114 #
115 # Returns nothing.
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
116 load: (path) ->
30644f5 Add initial logger calls replacing console.log
Tom Bell authored Nov 22, 2011
117 @logger.info "Loading scripts from #{path}"
bc7403e Update logging in Campfire adapter
Tom Bell authored Nov 22, 2011
118
a5b8d5d @atmos make hubot-scripts development easier
atmos authored Aug 30, 2011
119 Path.exists path, (exists) =>
120 if exists
121 @loadPaths.push path
df4912b Update to use for x in y instead of forEach
Tom Bell authored Oct 26, 2011
122 for file in Fs.readdirSync(path)
a5b8d5d @atmos make hubot-scripts development easier
atmos authored Aug 30, 2011
123 @loadFile path, file
124
125 # Public: Loads a file in path
126 #
127 # path - A String path on the filesystem.
128 # file - A String filename in path on the filesystem.
129 #
130 # Returns nothing.
131 loadFile: (path, file) ->
132 ext = Path.extname file
133 full = Path.join path, Path.basename(file, ext)
6780d7a Update equality checks to use 'is'
Tom Bell authored Oct 26, 2011
134 if ext is '.coffee' or ext is '.js'
b7128e9 Update hubot-scripts loading
Tom Bell authored Nov 23, 2011
135 try
136 require(full) @
137 @parseHelp "#{path}/#{file}"
138 catch err
139 @logger.error "#{err}"
140
141 loadHubotScripts: (path, scripts) ->
142 @logger.info "Loading hubot-scripts from #{path}"
143 for script in scripts
144 @loadFile path, script
845e37e @atmos parse help on a per-script basis
atmos authored Sep 8, 2011
145
959b26d @atmos use basic auth if available
atmos authored Dec 24, 2011
146 # Setup the Connect server's defaults
147 #
148 # Sets up basic authentication if parameters are provided
149 #
150 # Returns: nothing.
5fd81c3 @tombell Add switch for disabling the http server
tombell authored Dec 24, 2011
151 setupConnect: ->
959b26d @atmos use basic auth if available
atmos authored Dec 24, 2011
152 user = process.env.CONNECT_USER
153 pass = process.env.CONNECT_PASSWORD
154
155 @connect = Connect()
156 if user and pass
157 @connect.use Connect.basicAuth(user, path)
8b4cd8b @atmos expose the router so we can use http verbs
atmos authored Dec 24, 2011
158 @connect.use Connect.router (app) =>
159 @router = app
959b26d @atmos use basic auth if available
atmos authored Dec 24, 2011
160
14f92b7 @atmos have a default port and use the router for route
atmos authored Dec 24, 2011
161 @connect.listen process.env.PORT || 8080
5fd81c3 @tombell Add switch for disabling the http server
tombell authored Dec 24, 2011
162
17c81a4 Update adapter loading code
Tom Bell authored Nov 12, 2011
163 # Load the adapter Hubot is going to use.
164 #
165 # path - A String of the path to adapter if local.
166 # adapter - A String of the adapter name to use.
167 #
168 # Returns nothing.
91d45e3 Begin updating the core moving adapters out
Tom Bell authored Nov 10, 2011
169 loadAdapter: (path, adapter) ->
30644f5 Add initial logger calls replacing console.log
Tom Bell authored Nov 22, 2011
170 @logger.info "Loading adapter #{adapter}"
171
17c81a4 Update adapter loading code
Tom Bell authored Nov 12, 2011
172 try
bc7403e Update logging in Campfire adapter
Tom Bell authored Nov 22, 2011
173 path = if adapter in HUBOT_DEFAULT_ADAPTERS
17c81a4 Update adapter loading code
Tom Bell authored Nov 12, 2011
174 "#{path}/#{adapter}"
175 else
176 "hubot-#{adapter}"
177
178 @adapter = require("#{path}").use(@)
179 catch err
392cd7f Show error when failing to load adapter, closes #196
Tom Bell authored Nov 27, 2011
180 @logger.error "Cannot load adapter #{adapter} - #{err}"
91d45e3 Begin updating the core moving adapters out
Tom Bell authored Nov 10, 2011
181
845e37e @atmos parse help on a per-script basis
atmos authored Sep 8, 2011
182 # Public: Help Commands for Running Scripts
183 #
184 # Returns an array of help commands for running scripts
bc7403e Update logging in Campfire adapter
Tom Bell authored Nov 22, 2011
185 helpCommands: ->
845e37e @atmos parse help on a per-script basis
atmos authored Sep 8, 2011
186 @commands.sort()
187
188 # Private: load help info from a loaded script
189 #
190 # path - The path to the file on disk
191 #
192 # Returns nothing
193 parseHelp: (path) ->
194 Fs.readFile path, "utf-8", (err, body) =>
bc7403e Update logging in Campfire adapter
Tom Bell authored Nov 22, 2011
195 throw err if err?
845e37e @atmos parse help on a per-script basis
atmos authored Sep 8, 2011
196 for i, line of body.split("\n")
1d1b69d @jasford Updated the help generator to allow for .js scripts to include help l…
jasford authored Oct 30, 2011
197 break if !(line[0] == '#' or line.substr(0, 2) == '//')
845e37e @atmos parse help on a per-script basis
atmos authored Sep 8, 2011
198 continue if !line.match('-')
199 @commands.push line[2..line.length]
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
200
28963b1 Add send/reply functions to Robot
Tom Bell authored Nov 24, 2011
201 # Public: A helper send function which delegates to the adapter's send
202 # function.
203 #
204 # user - A User instance.
205 # strings - One or more Strings for each message to send.
206 send: (user, strings...) ->
207 @adapter.send user, strings...
208
af68186 @ejfinneran messageRoom function for the Robot class
ejfinneran authored Dec 14, 2011
209 # Public: A helper send function to message a room that the robot is in
210 #
211 # room - String designating the room to message
212 # strings - One or more Strings for each message to send.
213 messageRoom: (room, strings...) ->
214 user = @userForId @id, { room: room }
215 @adapter.send user, strings...
216
217
28963b1 Add send/reply functions to Robot
Tom Bell authored Nov 24, 2011
218 # Public: A helper reply function which delegates to the adapter's reply
219 # function.
220 #
221 # user - A User instance.
222 # strings - One or more Strings for each message to send.
223 reply: (user, strings...) ->
224 @adapter.reply user, strings...
225
3a9d1b5 Add missing tomdoc comments to functions
Tom Bell authored Nov 5, 2011
226 # Public: Get an Array of User objects stored in the brain.
792567b Update Campfire, IRC and Shell adapters
Tom Bell authored Nov 4, 2011
227 users: ->
228 @brain.data.users
229
432e818 Update to fix the robot name not getting passed through
Tom Bell authored Nov 8, 2011
230 # Public: Get a User object given a unique identifier.
792567b Update Campfire, IRC and Shell adapters
Tom Bell authored Nov 4, 2011
231 userForId: (id, options) ->
232 user = @brain.data.users[id]
233 unless user
ce8bb29 Extract User and Brain into their own files
Tom Bell authored Nov 20, 2011
234 user = new User id, options
792567b Update Campfire, IRC and Shell adapters
Tom Bell authored Nov 4, 2011
235 @brain.data.users[id] = user
236 user
237
432e818 Update to fix the robot name not getting passed through
Tom Bell authored Nov 8, 2011
238 # Public: Get a User object given a name.
792567b Update Campfire, IRC and Shell adapters
Tom Bell authored Nov 4, 2011
239 userForName: (name) ->
240 result = null
241 lowerName = name.toLowerCase()
242 for k of (@brain.data.users or { })
f34166f @atmos don't bomb out if a name isn't set, just skip it
atmos authored Dec 6, 2011
243 userName = @brain.data.users[k]['name']
244 if userName? and userName.toLowerCase() is lowerName
792567b Update Campfire, IRC and Shell adapters
Tom Bell authored Nov 4, 2011
245 result = @brain.data.users[k]
246 result
247
52bcdd3 @russelldavis Move fuzzy matching to its own function.
russelldavis authored Nov 6, 2011
248 # Public: Get all users whose names match fuzzyName. Currently, match
249 # means 'starts with', but this could be extended to match initials,
250 # nicknames, etc.
251 #
252 usersForRawFuzzyName: (fuzzyName) ->
253 lowerFuzzyName = fuzzyName.toLowerCase()
254 user for key, user of (@brain.data.users or {}) when (
bc7403e Update logging in Campfire adapter
Tom Bell authored Nov 22, 2011
255 user.name.toLowerCase().lastIndexOf(lowerFuzzyName, 0) == 0)
311e6a2 @atmos whitespace cleanup
atmos authored Nov 25, 2011
256
52bcdd3 @russelldavis Move fuzzy matching to its own function.
russelldavis authored Nov 7, 2011
257 # Public: If fuzzyName is an exact match for a user, returns an array with
258 # just that user. Otherwise, returns an array of all users for which
259 # fuzzyName is a raw fuzzy match (see usersForRawFuzzyName).
260 #
261 usersForFuzzyName: (fuzzyName) ->
f3d86be Merge branch 'matchPartialNames' of https://github.com/russelldavis/h…
Tom Bell authored Nov 13, 2011
262 matchedUsers = @usersForRawFuzzyName(fuzzyName)
52bcdd3 @russelldavis Move fuzzy matching to its own function.
russelldavis authored Nov 7, 2011
263 lowerFuzzyName = fuzzyName.toLowerCase()
264 # We can scan matchedUsers rather than all users since usersForRawFuzzyName
265 # will include exact matches
266 for user in matchedUsers
267 return [user] if user.name.toLowerCase() is lowerFuzzyName
311e6a2 @atmos whitespace cleanup
atmos authored Nov 25, 2011
268
52bcdd3 @russelldavis Move fuzzy matching to its own function.
russelldavis authored Nov 7, 2011
269 matchedUsers
270
fb48ead @atmos working http interface
atmos authored Dec 24, 2011
271 # Kick off the event loop for the adapter
272 #
273 # Returns: Nothing.
792567b Update Campfire, IRC and Shell adapters
Tom Bell authored Nov 4, 2011
274 run: ->
275 @adapter.run()
276
fb48ead @atmos working http interface
atmos authored Dec 24, 2011
277 # Public: Gracefully shutdown the robot process
278 #
279 # Returns: Nothing.
44dd87e @alexwhitman Add bot shutdown function
alexwhitman authored Nov 27, 2011
280 shutdown: ->
281 @adapter.close()
282 @brain.close()
283
fb48ead @atmos working http interface
atmos authored Dec 24, 2011
284 # Public: The version of Hubot from npm
285 #
286 # Returns: SemVer compliant version number
287 parseVersion: ->
288 package_path = __dirname + "/../package.json"
289
290 console.log package_path
291 data = Fs.readFileSync package_path, 'utf8', (err,data) =>
292
293 content = JSON.parse(data)
294 @version = content['version']
295
53d76c3 @technoweenie add real user/message objects
technoweenie authored Aug 27, 2011
296 class Robot.Message
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
297 # Represents an incoming message from the chat.
298 #
ce8bb29 Extract User and Brain into their own files
Tom Bell authored Nov 20, 2011
299 # user - A User instance that sent the message.
1737347 @atmos add Response.finish() to indicate a message is "handled"
atmos authored Dec 24, 2011
300 constructor: (@user, @done = false) ->
301
302 # Indicates that no other Listener should be called on this object
5fd81c3 @tombell Add switch for disabling the http server
tombell authored Dec 24, 2011
303 finish: ->
1737347 @atmos add Response.finish() to indicate a message is "handled"
atmos authored Dec 24, 2011
304 @done = true
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored Oct 26, 2011
305
306 class Robot.TextMessage extends Robot.Message
307 # Represents an incoming message from the chat.
308 #
ce8bb29 Extract User and Brain into their own files
Tom Bell authored Nov 20, 2011
309 # user - A User instance that sent the message.
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
310 # text - The String message contents.
311 constructor: (@user, @text) ->
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored Oct 26, 2011
312 super @user
53d76c3 @technoweenie add real user/message objects
technoweenie authored Aug 27, 2011
313
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
314 # Determines if the message matches the given regex.
315 #
316 # regex - The Regex to check.
317 #
318 # Returns a Match object or null.
53d76c3 @technoweenie add real user/message objects
technoweenie authored Aug 27, 2011
319 match: (regex) ->
320 @text.match regex
321
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored Oct 26, 2011
322 # Represents an incoming user entrance notification.
323 #
ce8bb29 Extract User and Brain into their own files
Tom Bell authored Nov 20, 2011
324 # user - A User instance for the user who entered.
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored Oct 26, 2011
325 class Robot.EnterMessage extends Robot.Message
326
327 # Represents an incoming user exit notification.
328 #
ce8bb29 Extract User and Brain into their own files
Tom Bell authored Nov 20, 2011
329 # user - A User instance for the user who left.
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored Oct 26, 2011
330 class Robot.LeaveMessage extends Robot.Message
331
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
332 class Listener
bbf0c75 Update formatting
Tom Bell authored Oct 26, 2011
333 # Listeners receive every message from the chat source and decide if they
334 # want to act on it.
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
335 #
336 # robot - The current Robot instance.
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored Oct 26, 2011
337 # matcher - The Function that determines if this listener should trigger the
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
338 # callback.
339 # callback - The Function that is triggered if the incoming message matches.
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored Oct 26, 2011
340 constructor: (@robot, @matcher, @callback) ->
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
341
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
342 # Public: Determines if the listener likes the content of the message. If
343 # so, a Response built from the given Message is passed to the Listener
344 # callback.
345 #
346 # message - a Robot.Message instance.
347 #
348 # Returns nothing.
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
349 call: (message) ->
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored Oct 26, 2011
350 if match = @matcher message
74eb585 @tombell Update behaviour of finishing further execution
tombell authored Dec 24, 2011
351 @callback new @robot.Response(@robot, message, match)
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
352
9968309 @eventualbuddha Allow handling Campfire enter/leave messages.
eventualbuddha authored Oct 26, 2011
353 class TextListener extends Listener
354 # TextListeners receive every message from the chat source and decide if they want
355 # to act on it.
356 #
357 # robot - The current Robot instance.
358 # regex - The Regex that determines if this listener should trigger the
359 # callback.
360 # callback - The Function that is triggered if the incoming message matches.
361 constructor: (@robot, @regex, @callback) ->
362 @matcher = (message) =>
363 if message instanceof Robot.TextMessage
364 message.match @regex
365
1e4ae57 @technoweenie google images tests
technoweenie authored Aug 28, 2011
366 class Robot.Response
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
367 # Public: Responses are sent to matching listeners. Messages know about the
368 # content and user that made the original message, and how to reply back to
369 # them.
370 #
371 # robot - The current Robot instance.
372 # message - The current Robot.Message instance.
373 # match - The Match object from the successful Regex match.
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
374 constructor: (@robot, @message, @match) ->
375
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
376 # Public: Posts a message back to the chat source
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
377 #
378 # strings - One or more strings to be posted. The order of these strings
379 # should be kept intact.
380 #
381 # Returns nothing.
382 send: (strings...) ->
792567b Update Campfire, IRC and Shell adapters
Tom Bell authored Nov 4, 2011
383 @robot.adapter.send @message.user, strings...
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
384
7c9e8a8 @markstory Adding topic support.
markstory authored Oct 27, 2011
385 # Public: Posts a topic changing message
386 #
2b99aa2 @atmos whitespace
atmos authored Oct 31, 2011
387 # strings - One or more strings to set as the topic of the
7c9e8a8 @markstory Adding topic support.
markstory authored Oct 27, 2011
388 # room the bot is in.
389 #
390 # Returns nothing.
391 topic: (strings...) ->
792567b Update Campfire, IRC and Shell adapters
Tom Bell authored Nov 4, 2011
392 @robot.adapter.topic @message.user, strings...
7c9e8a8 @markstory Adding topic support.
markstory authored Oct 27, 2011
393
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
394 # Public: Posts a message mentioning the current user.
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
395 #
396 # strings - One or more strings to be posted. The order of these strings
397 # should be kept intact.
398 #
399 # Returns nothing.
400 reply: (strings...) ->
792567b Update Campfire, IRC and Shell adapters
Tom Bell authored Nov 4, 2011
401 @robot.adapter.reply @message.user, strings...
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
402
3726dbe @technoweenie document the core robot methods better
technoweenie authored Aug 27, 2011
403 # Public: Picks a random item from the given items.
404 #
405 # items - An Array of items (usually Strings).
406 #
1737347 @atmos add Response.finish() to indicate a message is "handled"
atmos authored Dec 24, 2011
407 # Returns an random item.
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
408 random: (items) ->
409 items[ Math.floor(Math.random() * items.length) ]
410
1737347 @atmos add Response.finish() to indicate a message is "handled"
atmos authored Dec 24, 2011
411 # Public: Tell the message to stop dispatching to listeners
412 #
413 # Returns nothing.
5fd81c3 @tombell Add switch for disabling the http server
tombell authored Dec 24, 2011
414 finish: ->
1737347 @atmos add Response.finish() to indicate a message is "handled"
atmos authored Dec 24, 2011
415 @message.finish()
416
158e963 @technoweenie use scoped-http-client
technoweenie authored Aug 28, 2011
417 # Public: Creates a scoped http client with chainable methods for
418 # modifying the request. This doesn't actually make a request though.
419 # Once your request is assembled, you can call `get()`/`post()`/etc to
420 # send the request.
421 #
422 # url - String URL to access.
423 #
424 # Examples:
f796552 @atmos cleanup shitty variable usage
atmos authored Oct 10, 2011
425 #
158e963 @technoweenie use scoped-http-client
technoweenie authored Aug 28, 2011
426 # res.http("http://example.com")
427 # # set a single header
428 # .header('Authorization', 'bearer abcdef')
429 #
430 # # set multiple headers
431 # .headers(Authorization: 'bearer abcdef', Accept: 'application/json')
432 #
433 # # add URI query parameters
434 # .query(a: 1, b: 'foo & bar')
435 #
436 # # make the actual request
437 # .get() (err, res, body) ->
438 # console.log body
439 #
440 # # or, you can POST data
441 # .post(data) (err, res, body) ->
442 # console.log body
443 #
444 # Returns a ScopedClient instance.
445 http: (url) ->
446 @httpClient.create(url)
447
23e72da Small refactor of twilio adapter
Tom Bell authored Oct 31, 2011
448 HttpClient = require 'scoped-http-client'
449
450 Robot.Response::httpClient = HttpClient
b253e94 @atmos fuck a color history
atmos authored Aug 27, 2011
451
452 module.exports = Robot
1455b62 Consistent whitespace
Tom Bell authored Nov 20, 2011
453
Something went wrong with that request. Please try again.