Sync Status

This commit is contained in:
2026-08-14 12:57:49 -07:00
commit d9a2c07aec
3 changed files with 133 additions and 0 deletions

2
.env.example Normal file
View File

@@ -0,0 +1,2 @@
CHANNEL_ID=
DISCORD_TOKEN=

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.env
node_modules

129
server.js Normal file
View 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
);