mirror of
https://gitlab.com/vyla-entertainment/status.git
synced 2026-11-09 19:57:25 -05:00
Sync Status
This commit is contained in:
2
.env.example
Normal file
2
.env.example
Normal file
@@ -0,0 +1,2 @@
|
||||
CHANNEL_ID=
|
||||
DISCORD_TOKEN=
|
||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.env
|
||||
node_modules
|
||||
129
server.js
Normal file
129
server.js
Normal file
@@ -0,0 +1,129 @@
|
||||
require("dotenv").config();
|
||||
|
||||
const {
|
||||
Client,
|
||||
GatewayIntentBits,
|
||||
EmbedBuilder
|
||||
} = require("discord.js");
|
||||
|
||||
const axios = require("axios");
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds
|
||||
]
|
||||
});
|
||||
|
||||
const services = [
|
||||
{
|
||||
name: "Website",
|
||||
url: "https://vyla.cc"
|
||||
},
|
||||
{
|
||||
name: "Player",
|
||||
url: "https://player.vyla.cc"
|
||||
},
|
||||
{
|
||||
name: "API",
|
||||
url: "https://api.vyla.cc"
|
||||
}
|
||||
];
|
||||
|
||||
let statusMessage;
|
||||
|
||||
async function checkService(service) {
|
||||
|
||||
const start = Date.now();
|
||||
|
||||
try {
|
||||
const response = await axios.get(service.url, {
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
return {
|
||||
online: true,
|
||||
latency: Date.now() - start,
|
||||
status: response.status
|
||||
};
|
||||
|
||||
} catch {
|
||||
return {
|
||||
online: false,
|
||||
latency: null,
|
||||
status: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async function updateStatus() {
|
||||
|
||||
const channel = await client.channels.fetch(
|
||||
process.env.CHANNEL_ID
|
||||
);
|
||||
|
||||
let description = "";
|
||||
let allOnline = true;
|
||||
|
||||
for (const service of services) {
|
||||
|
||||
const result = await checkService(service);
|
||||
|
||||
if (!result.online)
|
||||
allOnline = false;
|
||||
|
||||
description +=
|
||||
`
|
||||
**[${service.name}](${service.url})**
|
||||
Status: ${result.online ? "🟢 Online" : "🔴 Offline"}
|
||||
Response Time: ${result.latency ?? "N/A"} ms
|
||||
|
||||
`;
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(
|
||||
allOnline
|
||||
? "All Systems Operational"
|
||||
: "System Issues Detected"
|
||||
)
|
||||
.setDescription(description)
|
||||
.setColor(
|
||||
allOnline
|
||||
? 15987699
|
||||
: 16711680
|
||||
)
|
||||
.setFooter({
|
||||
text: `Last updated: ${new Date().toLocaleString()}`
|
||||
});
|
||||
|
||||
if (!statusMessage) {
|
||||
|
||||
statusMessage = await channel.send({
|
||||
embeds: [embed]
|
||||
});
|
||||
|
||||
} else {
|
||||
await statusMessage.edit({
|
||||
embeds: [embed]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
client.once("ready", async () => {
|
||||
console.log(
|
||||
`${client.user.tag} is online`
|
||||
);
|
||||
|
||||
await updateStatus();
|
||||
|
||||
setInterval(
|
||||
updateStatus,
|
||||
60000
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
client.login(
|
||||
process.env.DISCORD_TOKEN
|
||||
);
|
||||
Reference in New Issue
Block a user