-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
*_config.coffee | ||
node_modules/ | ||
lib-cov | ||
*.seed | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |