-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (51 loc) · 1.64 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
const express = require('express');
const CronJob = require('cron').CronJob;
const app = express();
require('dotenv').config();
const { AsthaFess } = require('./AsthaFess');
const PORT = 3000;
const bot = new AsthaFess({
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
access_token: process.env.ACCESS_TOKEN,
access_token_secret: process.env.ACCESS_TOKEN_SECRET,
triggerword: ['medioker!', 'itb!', 'bucin!', 'help!', 'trade!'],
blacklist: ['STEI-K','K','Komputasi', 'stei-k', 'stei-komputasi','steik','STEIK']
})
const job = new CronJob(
'0 */3 * * * *',
doJob,
null,
true,
);
async function doJob () {
let tempMessage;
try {
const authenticatedUserId = await bot.getadminuserinfo();
const message = await bot.getDirectMessage(authenticatedUserId);
if (message.id) {
//console.log(JSON.stringify(message, null, 2), 'Dapet nichhh <<<<<<<')
tempMessage = message;
await bot.tweetMessage(message);
const response = await bot.deleteMessage(message);
} else {
console.log('no tweet to post!')
}
} catch (error) {
console.log(error);
console.log('======================ERROR=====================')
if(tempMessage.id) {
await bot.deleteMessage(tempMessage);
}
}
}
app.get('/', (req, res) => {
res.send('AsthaFess still Online!')
})
app.get('/trigger',async (req, res, next) => {
job.fireOnTick();
res.send('job triggered!');
})
app.listen(PORT, () => {
console.log(`AsthaFess app listening on port ${PORT}`)
})