|
1 | 1 | #!/usr/bin/env coffee |
2 | 2 |
|
3 | 3 | ipv6 = require 'ipv6' |
| 4 | +async = require 'async' |
4 | 5 | Twit = require 'twit' |
5 | 6 | minimist = require 'minimist' |
6 | 7 | Mustache = require 'mustache' |
@@ -50,6 +51,7 @@ getConfig = (path) -> |
50 | 51 | for account in config.accounts |
51 | 52 | if typeof account.ranges == 'string' |
52 | 53 | account.ranges = loadJson account.ranges |
| 54 | + console.log "loaded config from", path |
53 | 55 | config |
54 | 56 |
|
55 | 57 | loadJson = (path) -> |
@@ -104,12 +106,36 @@ inspect = (account, edit) -> |
104 | 106 | status = getStatus edit, name, account.template |
105 | 107 | tweet account, status, edit |
106 | 108 |
|
| 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 | + |
107 | 129 | main = -> |
108 | 130 | 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 |
113 | 139 |
|
114 | 140 | if require.main == module |
115 | 141 | main() |
|
0 commit comments