-
Notifications
You must be signed in to change notification settings - Fork 2
/
derpo.coffee
139 lines (125 loc) · 4.74 KB
/
derpo.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
Responder = require './responderbot'
google = require './google'
request = require 'request'
# split this twilio junk out, dawg
twilio = require('twilio')( require('./twilio_config').args... )
last_message = "ham"
port = 4000
done = no
class Derpo extends Responder
constructor: ( config )->
config.name = "derpo"
super config
@client?.addListener 'nick', (oldn, newn, chans, msg)=>
@say "#{oldn} changed to #{newn}"
@patterns = [
recognize: @re /^lololol (.+)*/i
respond: (m,o,say) =>
return if done
done = yes
[to,body...] = m[1].split(" ")
body = body.join(" ")
last_message = body
url = "http://callinline.com/in"
from = "use the number from twilio config dawg"
say JSON.stringify msg = {to, from, body}
call = {to,from,url}
twilio.makeCall call, (err, resp)=>
console.log err, resp
if err
say "error"
else
say "#{resp.status}, to:#{resp.to}'"
,
recognize: @re /^homies\?/i
respond: (m,o,say) =>
@get_nicks => say @nicks.join " "
,
recognize: @re /^hnsearch (.+)*/i
respond: (m,o,say) =>
term = @match_to_term m
google "#{ term } site:news.ycombinator.com", (err, next, links)=>
say @pick1 links
,
recognize: @re /^what about (.+)*\?*/i
respond: (m, o, say) =>
term = @match_to_term m
google term, (err,next,links)=> say @pick1 links
,
recognize: @re /^what\'s a (.+)*\?*/i
respond: (m, o, say) =>
term = @match_to_term m
google "wiki #{ term }", (e,n,links)=> say @pick1 links
,
recognize: @re /^where is (.+)*\?*/i
respond: (m, o, say) =>
place = encodeURIComponent @match_to_term m
say "http://maps.googleapis.com/maps/api/staticmap?center=#{ place }&size=500x400&sensor=false&.jpg"
# say "It's here: #{gmaps.staticMap( place, 11, '500x400', no, no)}&.jpg"
,
recognize: @re /^who is (.+)*\?*/i
respond: (m, o, say) =>
term = @match_to_term m
google "wiki #{ term }", (e,n,links)=> say @pick1 links
,
recognize: @re /^define (.+)*\?*/i
respond: (m, o, say) =>
term = @match_to_term m
google "define #{ term }", (e,n,links)=> say @pick1 links
,
recognize: @re /^how do i (.+)*\?*/i
respond: (m, o, say) =>
term = @match_to_term m
google "how to #{ term }", (e,n,links)=> say @pick1 links, yes
,
recognize: @re /who wins between\s(.*)\s(?:and|or)\s([^\?]*)/i
respond: ([x..., message, me, you], o, say)=>
winners = ['coffeescript','white_stripes','blues','ruby','torpedo','lisp',
'macros','mrluc', 'ddg','derpo','tweeto','duckduckgo','zepplin','beer',
'kelly', 'John_Harasyn','emacs','Emacs'
]
losers = ['php','java','ms','microsoft','accounting','C#','.net','dotnet',
'sql','pema','darkcypher_bit','tenrox','VisualStudio',
'vs', 'vs2012','eclipse', "the vikings"
]
return say me if you in losers or me in winners
return say you if me in losers or you in winners
say if Math.random() > 0.5 then me else you
,
recognize: @re /^trygif (.+)*/i
respond: (m,o,say)=>
term = @match_to_term m
try @image_search "#{term} gif", (err,imgs) =>
return say( img.unescapedUrl ) for img in imgs when img.width > 200 and img.unescapedUrl.indexOf(".gif") isnt -1
say "hard luck"
catch err
say "dude. #{err}"
]
image_search: (query, callback) =>
request "http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=#{ query.replace(/\s/g, '+') }&start=#{ page=0 }", (err, res, body) ->
try callback no, JSON.parse(body).responseData.results
catch err
callback err, []
match_to_term: (m)-> m[1..].join(" ").toLowerCase()
picky_pick: (links, is_good, perform) =>
return perform(link) for link in links when is_good link
pick1: (links, show = yes)->
for {description, title, href} in links when description.length > 2
desc_length = 275 - title.length - (href?.length or 0)
return @cleanup "[#{title}] #{ description?[0..desc_length] } #{ if show then href else '' }"
cleanup: (s)-> s=s.replace " ", " "
bot = new Derpo require( './irc_config' )
express = require 'express'
app = express()
app.get "/in", (req,res)->
response = """<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="woman">#{last_message}</Say>
<Hangup/>
</Response>"""
res.send response
app.listen(port)
console.log "Listening on #{port}"
unless bot.connect
bot.match "where is san lorenzo, ecuador?"
bot.match "who wins between athaeryn's new bad-ass regex and the-old-regex"