-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathindex.js
65 lines (53 loc) · 1.12 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
const venom = require('venom-bot')
const venomOptions = require('./venom-options.js')
const TWENTY_MINUTES = 1200000
let client = null
dateLog('Started index.js')
initBot()
function initBot() {
dateLog('Initializing bot')
venom
// create bot with options
.create(venomOptions)
// start bot
.then((client) => startBot(client))
// catch errors
.catch((err) => {
dateLog(err)
})
}
function startBot(_client) {
dateLog('Starting bot')
client = _client
// restart bot every 20 minutos
// stops working otherwise
setTimeout(() => {
// close bot
client.close()
dateLog('Closing bot')
// init bot again
initBot()
}, TWENTY_MINUTES)
//
// add your code here
//
// example: reply every message with "Hi!""
client.onMessage(reply)
}
function reply(message) {
const sender = message.from
dateLog(`Message received from: ${sender}`)
const replyText = 'Hi!'
client.sendText(sender, replyText)
dateLog(`Message: "${replyText}" sent to: ${sender}`)
}
//
// Aux
//
// Catch ctrl+C
process.on('SIGINT', function () {
client.close()
})
function dateLog(text) {
console.log(new Date(), ' - ', text)
}