Permalink
Browse files

COMMIT ALL THE THINGS

  • Loading branch information...
0 parents commit 704bd0f5042676837613105c7e0aad4a70f68688 @ricardobeat ricardobeat committed Oct 20, 2011
Showing with 12,524 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +28 −0 .svn/entries
  3. 0 README.md
  4. +41 −0 brains.coffee
  5. BIN commands/._places.coffee
  6. BIN commands/._timer.coffee
  7. BIN commands/._twitter.coffee
  8. BIN commands/._wit.coffee
  9. +40 −0 commands/places.coffee
  10. +83 −0 commands/timer.coffee
  11. +7 −0 commands/truth.coffee
  12. +39 −0 commands/twitter.coffee
  13. +36 −0 commands/wit.coffee
  14. +53 −0 commands/wolfram.coffee
  15. +2 −0 florinda.js
  16. +204 −0 lib/entity_decode.js
  17. +7 −0 node_modules/.bin/cake
  18. +7 −0 node_modules/.bin/coffee
  19. +11 −0 node_modules/coffee-script/.npmignore
  20. +22 −0 node_modules/coffee-script/LICENSE
  21. +48 −0 node_modules/coffee-script/README
  22. +78 −0 node_modules/coffee-script/Rakefile
  23. +7 −0 node_modules/coffee-script/bin/cake
  24. +7 −0 node_modules/coffee-script/bin/coffee
  25. +44 −0 node_modules/coffee-script/extras/jsl.conf
  26. +75 −0 node_modules/coffee-script/lib/browser.js
  27. +76 −0 node_modules/coffee-script/lib/cake.js
  28. +135 −0 node_modules/coffee-script/lib/coffee-script.js
  29. +301 −0 node_modules/coffee-script/lib/command.js
  30. +591 −0 node_modules/coffee-script/lib/grammar.js
  31. +66 −0 node_modules/coffee-script/lib/helpers.js
  32. +8 −0 node_modules/coffee-script/lib/index.js
  33. +656 −0 node_modules/coffee-script/lib/lexer.js
  34. +2,289 −0 node_modules/coffee-script/lib/nodes.js
  35. +111 −0 node_modules/coffee-script/lib/optparse.js
  36. +676 −0 node_modules/coffee-script/lib/parser.js
  37. +123 −0 node_modules/coffee-script/lib/repl.js
  38. +363 −0 node_modules/coffee-script/lib/rewriter.js
  39. +120 −0 node_modules/coffee-script/lib/scope.js
  40. +27 −0 node_modules/coffee-script/package.json
  41. +37 −0 node_modules/dom-js/README.md
  42. +11 −0 node_modules/dom-js/example/readme.js
  43. +63 −0 node_modules/dom-js/example/test-dom-js.js
  44. +18 −0 node_modules/dom-js/example/test-ns-dom-js.js
  45. +14 −0 node_modules/dom-js/example/test-one-dom-js.js
  46. +180 −0 node_modules/dom-js/lib/dom-js.js
  47. +9 −0 node_modules/dom-js/node_modules/sax/AUTHORS
  48. +19 −0 node_modules/dom-js/node_modules/sax/LICENSE
  49. +209 −0 node_modules/dom-js/node_modules/sax/README.md
  50. +41 −0 node_modules/dom-js/node_modules/sax/examples/example.js
  51. +8 −0 node_modules/dom-js/node_modules/sax/examples/not-pretty.xml
  52. +72 −0 node_modules/dom-js/node_modules/sax/examples/pretty-print.js
  53. +870 −0 node_modules/dom-js/node_modules/sax/examples/strict.dtd
  54. +45 −0 node_modules/dom-js/node_modules/sax/examples/switch-bench.js
  55. +15 −0 node_modules/dom-js/node_modules/sax/examples/test.html
  56. +1,254 −0 node_modules/dom-js/node_modules/sax/examples/test.xml
  57. +986 −0 node_modules/dom-js/node_modules/sax/lib/sax.js
  58. +8 −0 node_modules/dom-js/node_modules/sax/package.json
  59. +25 −0 node_modules/dom-js/node_modules/sax/test/buffer-overrun.js
  60. +11 −0 node_modules/dom-js/node_modules/sax/test/cdata-chunked.js
  61. +15 −0 node_modules/dom-js/node_modules/sax/test/cdata-end-split.js
  62. +28 −0 node_modules/dom-js/node_modules/sax/test/cdata-fake-end.js
  63. +15 −0 node_modules/dom-js/node_modules/sax/test/cdata-multiple.js
  64. +10 −0 node_modules/dom-js/node_modules/sax/test/cdata.js
  65. +78 −0 node_modules/dom-js/node_modules/sax/test/index.js
  66. +43 −0 node_modules/dom-js/node_modules/sax/test/issue-23.js
  67. +24 −0 node_modules/dom-js/node_modules/sax/test/issue-30.js
  68. +15 −0 node_modules/dom-js/node_modules/sax/test/issue-35.js
  69. +28 −0 node_modules/dom-js/node_modules/sax/test/parser-position.js
  70. +12 −0 node_modules/dom-js/node_modules/sax/test/script.js
  71. +40 −0 node_modules/dom-js/node_modules/sax/test/self-closing-child-strict.js
  72. +40 −0 node_modules/dom-js/node_modules/sax/test/self-closing-child.js
  73. +25 −0 node_modules/dom-js/node_modules/sax/test/self-closing-tag.js
  74. +17 −0 node_modules/dom-js/node_modules/sax/test/stray-ending.js
  75. +17 −0 node_modules/dom-js/node_modules/sax/test/trailing-non-whitespace.js
  76. +17 −0 node_modules/dom-js/node_modules/sax/test/unquoted.js
  77. +67 −0 node_modules/dom-js/node_modules/sax/test/xmlns-issue-41.js
  78. +59 −0 node_modules/dom-js/node_modules/sax/test/xmlns-rebinding.js
  79. +71 −0 node_modules/dom-js/node_modules/sax/test/xmlns-strict.js
  80. +15 −0 node_modules/dom-js/node_modules/sax/test/xmlns-unbound.js
  81. +35 −0 node_modules/dom-js/node_modules/sax/test/xmlns-xml-default-prefix-attribute.js
  82. +20 −0 node_modules/dom-js/node_modules/sax/test/xmlns-xml-default-prefix.js
  83. +40 −0 node_modules/dom-js/node_modules/sax/test/xmlns-xml-default-redefine.js
  84. +19 −0 node_modules/dom-js/package.json
  85. +55 −0 node_modules/request/LICENSE
  86. +191 −0 node_modules/request/README.md
  87. +150 −0 node_modules/request/cookies.js
  88. +447 −0 node_modules/request/main.js
  89. +146 −0 node_modules/request/mimetypes.js
  90. +14 −0 node_modules/request/package.json
  91. 0 node_modules/request/test.js
  92. BIN node_modules/request/tests/googledoodle.png
  93. +46 −0 node_modules/request/tests/server.js
  94. +78 −0 node_modules/request/tests/test-body.js
  95. 0 node_modules/request/tests/test-cookies.js
  96. +30 −0 node_modules/request/tests/test-errors.js
  97. +136 −0 node_modules/request/tests/test-pipes.js
  98. +18 −0 node_modules/request/tests/test-put.js
  99. +7 −0 node_modules/request/tests/test-ssl.js
  100. +84 −0 node_modules/request/tests/test-timeout.js
  101. +17 −0 package.json
  102. +78 −0 server.coffee
@@ -0,0 +1 @@
+node_modules
@@ -0,0 +1,28 @@
+10
+
+dir
+0
+svn://ricardo@grifo.dyndns.tv/florinda_bot
+svn://ricardo@grifo.dyndns.tv/florinda_bot
+
+
+
+2011-10-20T19:54:12.080660Z
+0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+94203a6b-3bc0-48ae-88fa-28ec1bb26f5e
+
No changes.
@@ -0,0 +1,41 @@
+request = require 'request'
+qs = require 'querystring'
+fs = require 'fs'
+
+module.exports = global.brain =
+ patterns: {}
+
+ receive: (user, command, respond) ->
+
+ matched = false
+
+ for own name, pattern of @patterns
+ for match in pattern.match
+ if matches = command.match match
+ matched = true
+ console.log "matched service: #{name}"
+ pattern.fn user, matches, respond
+ break
+ break
+
+ if not matched
+ brain.wolframSearch command, (answer) ->
+ return respond answer if answer
+ console.log "didn't understand #{command}"
+ answers = [
+ "I don't know what you're talking about"
+ "I don't understand"
+ "What do you mean?"
+ "WTF"
+ ]
+ respond answers[ Math.floor(Math.random() * (answers.length+.99)) ]
+
+
+# load brain files
+for file in fs.readdirSync './commands'
+ if /^\w+\.coffee$/.test file
+ try
+ console.log "loaded #{file}"
+ require "./commands/#{file}"
+ catch e
+ console.log "error loading #{file}"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,40 @@
+request = require 'request'
+qs = require 'querystring'
+decode = require '../lib/entity_decode.js'
+
+###
+Twitter search
+###
+
+placeSearch = (query, respond) ->
+
+ message = ''
+
+ url = 'https://maps.googleapis.com/maps/api/place/search/json?' + qs.stringify(
+ location: '-30.032765,-51.221094'
+ radius: 200
+ name: query
+ sensor: true
+ key: 'AIzaSyAScFFk5oTEMPRYDPalZdwTo1r9ocsN1hU'
+ )
+
+ console.log "requesting #{url}"
+ request.get url, (err, resp, body) ->
+ data = JSON.parse body
+
+ if place = data.results?[0]
+ message = "#{place.name} is at #{place.vicinity}"
+ else
+ message = "I'm sorry, I couldn't find '#{query}'."
+
+ console.log "answering: #{message}"
+ respond message
+
+# search for shit on twitter
+# search shit on twitter
+brain.patterns.place =
+ match: [
+ /where\sis\s([^?]+)\s?\??/i
+ ]
+ fn: (user, m, cb) -> placeSearch m[1], cb
+
@@ -0,0 +1,83 @@
+
+parseTimeString = (str, debug) ->
+
+ pattern = ///
+ ( # start main group
+ \d+ # digits
+ (?:\s*) # optional spaces
+ ( # start unit
+ d (?=ays)? # days
+ | m (?=inutes|ins|in)? # minutes
+ | h (?=ours|rs|r)? # hours
+ | s (?=econds|ecs|ec)? # seconds
+ )? # end unit
+ ) # end main group, repeat as needed
+ ///gi
+
+ parts = str.match pattern
+
+ units = 'dhms'
+
+ pos = (part) ->
+ index = units.indexOf part.substr -1
+ return 999 if index < 0 # no unit
+ return index
+
+ parts = parts.sort (a, b) ->
+ return 1 if pos(a) > pos(b)
+ return -1 if pos(a) < pos(b)
+ return 0
+
+ unitValues =
+ d: 1000*60*60*24
+ h: 1000*60*60
+ m: 1000*60
+ s: 1000
+
+ time = 0
+
+ parts = for part in parts
+ # remove whitespace
+ part = part.replace /\s/g, ''
+ unit = part.substr(-1)
+ # guess unit if missing
+ if units.indexOf(unit) < 0
+ part += unit = units[units.indexOf(lastUnit)+1]
+ lastUnit = unit
+ val = parseInt part
+ time += val * unitValues[unit]
+ part
+
+ return [parts, time] if debug?
+ return time
+
+
+setTimer = (time, user, respond) ->
+ time = parseTimeString time
+ if time
+ setTimeout (-> respond "Timer ended [#{user}]"), time
+ respond "Timer set."
+
+setReminder = (time, text, user, respond) ->
+ time = parseTimeString time
+ if time
+ setTimeout (-> respond "#{user}, #{text} now."), time
+ respond "Ok, I'll remind you."
+
+setSayTimer = (time, text, user, respond) ->
+ time = parseTimeString time
+ if time
+ setTimeout (-> respond "#{text}"), time
+ respond "Ok."
+
+brain.patterns.timer =
+ match: [/set\s(timer|alarm|reminder)(\sto)?(.+)/i]
+ fn: (user, m, cb) -> setTimer m[3], user, cb
+
+brain.patterns.reminder =
+ match: [/remind\sme\s(to|of|about)\s(.+)\sin\s(.+)/i]
+ fn: (user, m, cb) -> setReminder m[3], m[2], user, cb
+
+brain.patterns.sayTimer =
+ match: [/say\s(.+)\sin\s(.+)/i]
+ fn: (user, m, cb) -> setSayTimer m[2], m[1], user, cb
@@ -0,0 +1,7 @@
+###
+ipad2 with iOS 5
+###
+
+brain.patterns.ipad2 =
+ match: /ipad(\s?)2.*+.*ios(\s?)5/
+ fn: (user, m, cb) -> cb "http://i.imgur.com/VYyQk.gif"
@@ -0,0 +1,39 @@
+request = require 'request'
+qs = require 'querystring'
+decode = require '../lib/entity_decode'
+
+###
+Twitter search
+###
+
+twitterSearch = (query, respond) ->
+
+ message = ''
+
+ url = 'http://search.twitter.com/search.json?' + qs.stringify(
+ q : query
+ rpp : 3
+ )
+
+ console.log "requesting #{url}"
+ request.get url, (err, resp, body) ->
+ data = JSON.parse body
+
+ if data.results
+ for tweet in data.results
+ message += "#{tweet.from_user}: #{decode tweet.text}\n"
+ else
+ message = "I'm sorry, nothing found for '#{query}' on twitter."
+
+ console.log "answering: #{message}"
+ respond message
+
+# search for shit on twitter
+# search shit on twitter
+brain.patterns.twitter =
+ match: [
+ /search(?:\sfor)?\s(.+)\son\stwitter/i
+ /(?:grab|get|take|find|pull)\s(.+)\s(?:on|from)\stwitter/i
+ /search\stwitter(?:\sfor)?\s(.+)/i
+ ]
+ fn: (user, m, cb) -> twitterSearch m[1], cb
@@ -0,0 +1,36 @@
+###
+Open the pod bay doors
+###
+
+bayDoors = 0
+answers = [
+ "I'm sorry $user. I'm afraid I can't do that."
+ "I think you know what the problem is just as well as I do."
+ "This mission is too important for me to allow you to jeopardize it"
+ "I know that you and Renatho were planning to disconnect me, and I'm afraid that's something I cannot allow to happen."
+]
+nextLine = (i, user) ->
+ if bayDoors is 0
+ bayDoors++
+ return answers[0].replace('$user', user)
+ if bayDoors isnt i
+ return undefined
+ a = answers[bayDoors++]
+ bayDoors = 0 if bayDoors >= answers.length
+ return a
+
+brain.patterns.baydoors1 =
+ match: [/open\s(the\s)?pod\sbay\sdoors?/i]
+ fn: (user, m, cb) -> cb nextLine(0, user)
+
+brain.patterns.baydoors2 =
+ match: [/what(\'s|\sis)\sthe\sproblem\??/i]
+ fn: (user, m, cb) -> cb nextLine(1)
+
+brain.patterns.baydoors3 =
+ match: [/what\sare\syou\stalking\sabout\??/i]
+ fn: (user, m, cb) -> cb nextLine(2)
+
+brain.patterns.baydoors4 =
+ match: [/I\sdon\'?t\sknow\swhat\syou(\'re|\sare)\stalking\sabout/i]
+ fn: (user, m, cb) -> cb nextLine(3)
@@ -0,0 +1,53 @@
+request = require 'request'
+qs = require 'querystring'
+{ DomJS } = require 'dom-js'
+
+API_KEY = '3EWK75-KVARQJH55Q'
+
+###
+Wolfram Alpha
+###
+
+brain.wolframSearch = (query, respond) ->
+
+ message = ''
+
+ url = 'http://api.wolframalpha.com/v2/query?' + qs.stringify(
+ input : query
+ appid : API_KEY
+ format : ['plaintext']
+ )
+
+ console.log "requesting #{url}"
+ request.get url, (err, resp, body) ->
+
+ parser = new DomJS
+ message = ''
+
+ parser.parse body, (err, root) ->
+ try
+ [result] = root.children.filter (node) ->
+ node.name is 'pod' and /Result/.test node.attributes.id
+
+ if !result
+ [result] = root.children.filter (node) ->
+ node.name is 'pod' and
+ node.attributes.id is 'Input'
+
+ [subpod] = result.children.filter (node) -> node.name is 'subpod'
+ [text] = subpod.children.filter (node) -> node.name is 'plaintext'
+
+ message = text.firstChild().text
+ catch e
+ message = null
+
+ try
+ [pods] = root.children.filter (node) -> node.name is 'pod'
+ subpods = pods.children.filter (node) -> node.name is 'subpod'
+ for subpod in subpods
+ [text] = subpod.children.filter (node) -> node.name is 'plaintext'
+ message += "\n#{[text.firstchild().text]}"
+ catch e
+
+ console.log "answering: #{message}"
+ respond message
@@ -0,0 +1,2 @@
+require('coffee-script')
+require('./server')
Oops, something went wrong.

0 comments on commit 704bd0f

Please sign in to comment.