-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
95 lines (89 loc) · 2.82 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const fetch = require("node-fetch")
const Bot = require("./structures/bot")
const config = require("./utils/config.json")
module.exports = class Dbleu {
/**
* @type {string}
* @private
*/
token
/**
* @param {string} token - The API-Token for discord-botlist.eu
*/
constructor(token) {
this.token = token
}
/**
* Get all dates of the upvotes for the Bot
* @returns {Promise<Array<Date>>}
*/
getVotes() {
return new Promise((resolve, reject) => {
fetch(`${config.endpoints}/${config.version}/votes`, {
method: "GET",
headers: {
"Authorization": `Bearer ${this.token}`
}
}).then(async res => {
if (res.status !== 200) return reject(`${res.status}: ${(await res.json()).message}`)
resolve(await res.json())
})
})
}
/**
* Get all dates of the upvotes for the Bot
* @returns {Promise<Bot>}
*/
ping() {
return new Promise((resolve, reject) => {
fetch(`${config.endpoints}/${config.version}/ping`, {
method: "GET",
headers: {
"Authorization": `Bearer ${this.token}`
}
}).then(async res => {
if (res.status !== 200) return reject(`${res.status}: ${(await res.json()).message}`)
resolve(await res.json())
})
})
}
/**
* Get the vote/server analytics of your bot
* @returns {Promise<Bot>}
*/
analytics() {
return new Promise((resolve, reject) => {
fetch(`${config.endpoints}/${config.version}/analytics`, {
method: "GET",
headers: {
"Authorization": `Bearer ${this.token}`
}
}).then(async res => {
if (res.status !== 200) return reject(`${res.status}: ${(await res.json()).message}`)
resolve(await res.json())
})
})
}
/**
* Update the stats for your Bot
* @param {Number|string} serverCount
* @returns {Promise<Bot>}
*/
updateStats(serverCount) {
return new Promise((resolve, reject) => {
fetch(`${config.endpoints}/${config.version}/update`, {
method: "PATCH",
headers: {
"Authorization": `Bearer ${this.token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
serverCount: serverCount
})
}).then(async res => {
if (res.status !== 200) return reject(`${res.status}: ${(await res.json()).message}`)
resolve(await res.json())
})
})
}
}