-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
69 lines (60 loc) · 2.25 KB
/
main.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
68
69
// The official Hugin API Twitter bot
// Written by TechyGuy17 based on the original python implementation by Mjovanc
// Version 0.0.2
// For license, view the license file
const { TwitterApi } = require('twitter-api-v2');
require('dotenv').config();
const cron = require("node-cron");
const client = new TwitterApi({
appKey: process.env.APPKEY,
appSecret: process.env.APPSECRET,
accessToken: process.env.ACCESSTOKEN,
accessSecret: process.env.ACCESSSECRET,
})
async function sendToTwitter(message) {
return await client.v2.tweet(message)
}
async function sendReplytoTwitter(message, id) {
return await client.v2.reply(message, id)
}
async function getPosts() {
await fetch('https://n1.vxo.nu/api/v1/posts')
.then((response) => {
return response.json()
}).then(async (json) => {
let postAmount = json.total_items
postMessage = 'Currently rocking ' + postAmount + ' messages stored in Official Hugin API 🔥 #kryptokrona'
let response = await sendToTwitter(postMessage)
id = response.data.id
await getEncryptedPosts()
await getPopularBoards()
})
}
async function getEncryptedPosts() {
await fetch('https://n1.vxo.nu/api/v1/posts-encrypted')
.then((response) => {
return response.json()
}).then(async (json) => {
let encryptedAmount = json.total_items
encryptedMessage = 'We also currently have ' + encryptedAmount + ' encrypted messages in the database'
let response = await sendReplytoTwitter(encryptedMessage, id)
})
}
async function getPopularBoards() {
await fetch('https://n1.vxo.nu/api/v1/statistics/boards/popular')
.then((response) => {
return response.json()
}).then(async (json) => {
let popularBoard = await json.statistics[0].board
let boardPosts = await json.statistics[0].posts
boardMessage = 'The most popular board at the moment is #' + popularBoard + ' with a total of ' + boardPosts + ' posts!'
sendReplytoTwitter(boardMessage, id)
})
}
async function getStats() {
getPosts()
}
cron.schedule("0 12 * * *", function () {
console.log("Running todays task")
getStats()
})