-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathff7.coffee
47 lines (34 loc) · 1.29 KB
/
ff7.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
_ = require "lodash"
fs = require "fs"
Twitter = require "twitter"
client = new Twitter
consumer_key: process.env.FF7_CONSUMER_KEY
consumer_secret: process.env.FF7_CONSUMER_SECRET
access_token_key: process.env.FF7_ACCESS_TOKEN_KEY
access_token_secret: process.env.FF7_ACCESS_TOKEN_SECRET
module.exports = ->
# No real need for async operations...
# This file is running once an hour, let's make things more readable instead
script = fs.readFileSync("#{__dirname}/quotes.txt", { encoding: "utf8" })
hold = ""
skip = false
# Create full sentences from a slightly malformed FF7 script
script = _.reduceRight script.split("\n"), (result, line) ->
skip = false
line = line.trim()
if (_.uniq line).length < 2 then return result
# Wait until we hit the beginning of a sentence to push these fragments
if line.charAt(0).match(/[a-z]/)
hold += line
skip = true
return result
# Finally we have a real sentence, let's make it a choice
if line + hold >= 139 then return result
result.push "#{line} #{hold}".trim()
hold = ""
return result
, []
tweet = { status: (_.sample script) }
client.post "/statuses/update", tweet, (err, tweet, response) ->
console.log err, tweet, response
process.exit 0