This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmisc.js
80 lines (72 loc) · 2.2 KB
/
misc.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
const Axios = require("axios");
function validateEmail(email) {
const re =
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
}
async function getDiscordUser(access_token) {
return await Axios({
url: `https://discord.com/api/users/@me`,
method: 'GET',
headers: {
Authorization: `Bearer ${access_token}`
}
}).then((res_dis) => {
return res_dis.data;
}).catch((err) => {
return err;
});
}
async function refreshDiscordToken(refresh_token) {
return await Axios({
url: `https://discord.com/api/oauth2/token`,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: `client_id=${process.env.DISCORD_CLIENT_ID}&client_secret=${process.env.DISCORD_CLIENT_SECRET}&grant_type=refresh_token&refresh_token=${refresh_token}`
}).then((res_dis) => {
return res_dis.data;
}).catch((err) => {
return err;
});
}
async function ReportWebVital(content) {
Axios({
url: process.env.DISCORD_WEBHOOKS_WEB_VITALS,
method: 'POST',
data: { content }
})
}
async function ReportCrash(content) {
Axios({
url: process.env.DISCORD_WEBHOOKS_CRASH_REPORT,
method: 'POST',
data: { content }
}).then((res) => { }).catch((err) => {
console.log(err);
});
}
async function ReportCodeExec(content) {
Axios({
url: process.env.DISCORD_WEBHOOKS_CODE_EXEC_VITALS,
method: 'POST',
data: { content }
}).then((res) => { }).catch((err) => {
console.log(err);
});
}
async function CheckServerHealth(url) {
console.log(url)
return await Axios({
url: url,
method: 'GET',
timeout: 5000
}).then((res) => {
return res;
}).catch((err) => {
console.log(err)
return { err: err, sucess: false, msg: 'Server is down' };
});
}
module.exports = { CheckServerHealth, ReportCodeExec, ReportWebVital, ReportCrash, validateEmail, getDiscordUser, refreshDiscordToken }