Skip to content

Commit

Permalink
Initial version of BankFan
Browse files Browse the repository at this point in the history
  • Loading branch information
mrluc committed Jul 8, 2013
1 parent 0196f7c commit 02878da
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*_config.coffee
node_modules/
lib-cov
*.seed
*.log
Expand Down
48 changes: 48 additions & 0 deletions bankfan.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Twit = require 'twit'
sentiment = require 'sentiment'
{Module} = require './extensions'

class BankFan extends Module

scores:
sue:-4, overdraft:-4, fees:-4, fee:-4, overdrawn:-4, bot:-4,
foreclose:-8, foreclosure:-8, foreclosing:-8, lie: -4, thieves:-4,
account: -4, sucked:-4, sucks:-4, cares: 0, god: -1, routing: -4,
help: -3, checking: -3
constructor: (credentials, opts)->
@[k] = v for k, v of opts
@twit = new Twit credentials
@annoy()

check_limits: => @twit.get 'application/rate_limit_status', (err, {@resources}, res)=> @log @resources
valid_tweet: (t)-> t?.user?.id?

annoy: =>
@check_limits()
counter = 0
stream = @twit.stream 'statuses/filter', {@track, @lang}
stream.on 'tweet', (tweet)=>
if @valid_tweet tweet
@if_we_should_respond tweet , =>
@respond_to tweet, -> process.exit() if (counter++) > 10

if_we_should_respond: ({text, user:{screen_name}}, respond)=>
sentiment text, @scores, (err, result)=>
@log "SENTIMENT ANALYSIS: ", text, screen_name, JSON.stringify result
respond() if -(@intensity) > result.score or result.score > @intensity

respond_to: ({id, user: {screen_name}}, after) =>
status =
in_reply_to_status_id: id
status: "Hey @#{ screen_name }, maybe @BofA_Help has some input here? http://goo.gl/OGbaP"
@say status, after

say: (status, after)=>
log_then = (args...)=> @log args; after()
return @twit.post( 'statuses/update', status, log_then ) if @live
log_then status

log: (args...)-> console.log s for s in args

opts = live: yes, lang:'en', intensity: 3, track: 'BofA,BofA_Help,Bank of America,BankOfAmerica'
bot = new BankFan require('./twitter_config'), opts
35 changes: 35 additions & 0 deletions extensions.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

moduleKeywords = ['extended', 'included']

class Module
@extend: (obj) ->
for key, value of obj when key not in moduleKeywords
@[key] = value

obj.extended?.apply(@)
this

@include: (obj) ->
for key, value of obj when key not in moduleKeywords
# Assign properties to the prototype
@::[key] = value

obj.included?.apply(@)
this
exports.Module = Module

exports.ModuleTests = ->

Ham =
describe: ->
"#{ @attributes.join ', ' } ham."
Tasty =
attributes: ["tasty"]

class TastyHam extends Module
@include Tasty
@include Ham

th = new TastyHam

console.log th.describe()

0 comments on commit 02878da

Please sign in to comment.