Skip to content

Commit d50af2f

Browse files
committed
fixes #75
1 parent 854e7d6 commit d50af2f

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

anon.coffee

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env coffee
22

33
ipv6 = require 'ipv6'
4+
async = require 'async'
45
Twit = require 'twit'
56
minimist = require 'minimist'
67
Mustache = require 'mustache'
@@ -50,6 +51,7 @@ getConfig = (path) ->
5051
for account in config.accounts
5152
if typeof account.ranges == 'string'
5253
account.ranges = loadJson account.ranges
54+
console.log "loaded config from", path
5355
config
5456

5557
loadJson = (path) ->
@@ -104,12 +106,36 @@ inspect = (account, edit) ->
104106
status = getStatus edit, name, account.template
105107
tweet account, status, edit
106108

109+
checkConfig = (config, error) ->
110+
if config.accounts
111+
async.each config.accounts, canTweet, error
112+
else
113+
error "missing accounts stanza in config"
114+
115+
canTweet = (account, error) ->
116+
try
117+
twitter = new Twit account
118+
a = account['access_token']
119+
twitter.get 'search/tweets', q: 'cats', (err, data, response) ->
120+
if err
121+
error err + " for access_token " + a
122+
else if not response.headers['x-access-level'] or response.headers['x-access-level'] != 'read-write'
123+
error "no read-write permission for access token " + a
124+
else
125+
error null
126+
catch err
127+
error "unable to create twitter client for account: " + account
128+
107129
main = ->
108130
config = getConfig argv.config
109-
wikipedia = new WikiChanges ircNickname: config.nick
110-
wikipedia.listen (edit) ->
111-
for account in config.accounts
112-
inspect account, edit
131+
checkConfig config, (err) ->
132+
if not err
133+
wikipedia = new WikiChanges ircNickname: config.nick
134+
wikipedia.listen (edit) ->
135+
for account in config.accounts
136+
inspect account, edit
137+
else
138+
console.log err
113139

114140
if require.main == module
115141
main()

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"license": "CC0-1.0",
66
"version": "0.0.3",
77
"dependencies": {
8+
"async": "latest",
89
"twit": "latest",
910
"wikichanges": ">=0.2.4",
1011
"coffee-script": "latest",

0 commit comments

Comments
 (0)