-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitBot.js
44 lines (36 loc) · 1.07 KB
/
twitBot.js
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
const Twit = require('twit')
const quotes = require('./backup/quotes.json')
const {shuffle} = require('./utils/helpers')
const twitLength = 280
const srQuotes = quotes.filter(q => q.sr)
shuffle(srQuotes)
let i = 0
function post(status) {
const bot = new Twit({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token: process.env.TWITTER_ACCESS_TOKEN,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
})
bot.post('statuses/update', {status}, (err, data) => {
if (err) return console.error(err)
console.log(data.text)
})
}
function postQuote() {
const quote = srQuotes[++i % srQuotes.length]
const text = `${quote.sr}
— ${quote.author}`
if (text.length > twitLength) return
const tags = '\n#programiranje #citati'
const fullText = (text + tags).length < twitLength ? text + tags : text
post(fullText)
}
function initBot() {
console.log('initBot')
// postQuote()
// setInterval(postQuote, 2 * 60 * 60 * 1000) // hours * min * sec * ms
}
module.exports = {
initBot,
}