-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
121 lines (109 loc) · 3.56 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* @module Discord-Services
* @copyright un boxing man 2021
* @license MIT
*/
const wump = require('wumpfetch');
module.exports = class dsClient {
/**
* Create Boats class
* @constructor
* @param {string} token - Your Discord Services token
*/
constructor(token) {
this.token = token;
}
/**
* Post bot commands to the API.
*
* @param {string} botid - The bot's ID.
* @param {string} command - The name of the command.
* @param {string} desc - The description or what the command does.
* @param {string} category - The type of command.
*/
postCommands(botid, comma, desc, category) {
if (!this.token) throw new TypeError('API token not provided');
if (typeof comma !== 'string') throw new TypeError(' the command must be a string');
if (typeof desc !== 'string') throw new TypeError('The description must be a string');
if (typeof category !== 'string') throw new TypeError('the category must be a string');
if (typeof botid !== 'string') throw new TypeError('Bot ID must be a string');
return new Promise(async (resolve, reject) => {
try {
const res = await wump(`https://api.discordservices.net/bot/${botid}/commands`, {
method: 'POST',
headers: {
'Authorization': this.token
},
data: {
"command": comma,
"desc": desc,
"category": category
}
}).send();
resolve(res.json());
} catch (err) {
reject(new Error(err));
}
});
}
/**
* Post bot commands to the API.
*
* @param {string} botid - The bot's ID.
* @param {string} title - The title of the news.
* @param {string} content - The content of the news.
* @param {boolean} error - The type of command.
*/
postNews(botid, title, content, error) {
if (!this.token) throw new TypeError('API token not provided');
if (typeof title !== 'string') throw new TypeError(' the title must be a string');
if (typeof content !== 'string') throw new TypeError('The content must be a string');
if (typeof error !== `boolean`) throw new TypeError('the category must be a boolean');
if (typeof botid !== 'string') throw new TypeError('Bot ID must be a string');
return new Promise(async (resolve, reject) => {
try {
const res = await wump(`https://api.discordservices.net/bot/${botid}/news`, {
method: 'POST',
headers: {
'Authorization': this.token
},
data: {
"title": title,
"content": content,
"error": error
}
}).send();
resolve(res.json());
} catch (err) {
reject(new Error(err));
}
});
}
/**
* Post bot server count to API.
*
* @param {number} servercount - The bot's server count.
* @param {string} botid - The bot's ID.
*/
postStats(servercount, botid) {
if (!this.token) throw new TypeError('API token not provided');
if (typeof servercount !== 'number') throw new TypeError('Server count must be a number');
if (typeof botid !== 'string') throw new TypeError('Bot ID must be a string');
return new Promise(async (resolve, reject) => {
try {
const res = await wump(`https://api.discordservices.net/bot/${botid}/stats`, {
method: 'POST',
headers: {
'Authorization': this.token
},
data: {
'servers': servercount
}
}).send();
resolve(res.json());
} catch (err) {
reject(new Error(err));
}
});
}
};