-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (52 loc) · 1.34 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const {blackCards, whiteCards} = require("./decks")
var Twit = require("twit")
var conf = require("./config")
var T = new Twit({
consumer_key: conf.consumerKey,
consumer_secret: conf.consumerSecret,
access_token: conf.accessToken,
access_token_secret: conf.accessSecret
})
const blackLength = blackCards.length
const whiteLength = whiteCards.length
const regex = new RegExp("_")
function getText(){
var blackCardPos = Math.floor(Math.random() * (blackLength))
var selectedBlack = blackCards[blackCardPos]
var selectedWhite = []
for (var i = 0; i < selectedBlack.pick; i++) {
whiteCardPos = Math.floor(Math.random() * (whiteLength))
selectedWhite.push(whiteCards[whiteCardPos].slice(0,-1))
}
let finish = selectedBlack.text
if (regex.exec(finish)) {
selectedWhite.map(item => {
finish = finish.replace("_", item)
})
}
else {
selectedWhite.map(item => {
finish += `\n${item}`
})
}
// finish = finish.replace("®", "")
["®", "<i>", "</i>"].map(item => {
finish = finish.replace(item, "")
})
finish = finish.split("<br/>").join("\n")
return finish
}
function post(text){
T.post("statuses/update", {status: text}, (err, data, res) => {
if (err) {
throw err
}
})
}
post(getText())
let tweetnum = 0
setInterval(function(){
post(getText())
tweetnum++
console.log(tweetnum)
}, conf.timeInMinutes*60*1000)