Update from Git Manager GUI
This commit is contained in:
105
commands/status.js
Normal file
105
commands/status.js
Normal file
@@ -0,0 +1,105 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||
import stats from "../util/stats.js";
|
||||
import queue from "../util/queue.js";
|
||||
import { requireOwner } from "../util/ownerOnly.js";
|
||||
import { t, getLang } from "../util/i18n.js";
|
||||
import fs from "fs";
|
||||
|
||||
export default {
|
||||
name: "status",
|
||||
description: "Zeigt den Bot-Status, API-Verfügbarkeit und den nächsten Update-Check",
|
||||
aliases: ["botstatus"],
|
||||
guild: ["all"],
|
||||
nsfw: false,
|
||||
user_permissions: [],
|
||||
bot_permissions: [],
|
||||
args_required: 0,
|
||||
args_usage: "",
|
||||
cooldown: 10,
|
||||
|
||||
data: new SlashCommandBuilder()
|
||||
.setName("status")
|
||||
.setDescription("Zeigt Bot-Status, API-Verfügbarkeit und Update-Check-Info"),
|
||||
|
||||
async execute(client, ctx) {
|
||||
const lang = loadLang(ctx.guild.id);
|
||||
if (!await requireOwner(client, ctx, lang)) return;
|
||||
// --- Spiget API Health-Check ---
|
||||
let spigetStatus = "✅ Erreichbar";
|
||||
let spigetPing = "–";
|
||||
try {
|
||||
const start = Date.now();
|
||||
const res = await fetch("https://api.spiget.org/v2/status", { signal: AbortSignal.timeout(5000) });
|
||||
spigetPing = `${Date.now() - start}ms`;
|
||||
if (!res.ok) spigetStatus = `⚠️ HTTP ${res.status}`;
|
||||
} catch {
|
||||
spigetStatus = "❌ Nicht erreichbar";
|
||||
}
|
||||
|
||||
// --- SpigotMC API Health-Check (Vault = 34315, existiert garantiert) ---
|
||||
let spigotStatus = "✅ Erreichbar";
|
||||
try {
|
||||
const res = await fetch("https://api.spigotmc.org/legacy/update.php?resource=34315", {
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
// 200 mit Versionstext = OK; alles andere = Problem
|
||||
if (!res.ok) spigotStatus = `⚠️ HTTP ${res.status}`;
|
||||
} catch {
|
||||
spigotStatus = "❌ Nicht erreichbar";
|
||||
}
|
||||
|
||||
// --- Queue-Status ---
|
||||
const queueStatus = queue.isRunning
|
||||
? `🔄 Aktiv (${queue.size} ausstehend)`
|
||||
: queue.size > 0
|
||||
? `⏳ Wartend (${queue.size} Jobs)`
|
||||
: "✅ Leerlauf";
|
||||
|
||||
// --- Nächster Check ---
|
||||
const nextRun = queue.nextRunAt
|
||||
? `<t:${Math.floor(queue.nextRunAt / 1000)}:R>`
|
||||
: "Unbekannt";
|
||||
|
||||
// --- Statistiken ---
|
||||
const s = stats.all();
|
||||
const startedAt = s.startedAt
|
||||
? `<t:${Math.floor(new Date(s.startedAt).getTime() / 1000)}:R>`
|
||||
: "Unbekannt";
|
||||
|
||||
// --- Discord Latenz ---
|
||||
const discordPing = `${client.bot.ws.ping}ms`;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(ctx.guild.members.me.displayHexColor)
|
||||
.setTitle(`📡 ${client.config.botName} – Status`)
|
||||
.addFields([
|
||||
// APIs
|
||||
{ name: "🌐 Spiget API", value: `${spigetStatus} (${spigetPing})`, inline: true },
|
||||
{ name: "🌐 SpigotMC API", value: spigotStatus, inline: true },
|
||||
{ name: "💬 Discord Ping", value: discordPing, inline: true },
|
||||
// Update-Check
|
||||
{ name: "⚙️ Queue", value: queueStatus, inline: true },
|
||||
{ name: "⏱️ Nächster Check", value: nextRun, inline: true },
|
||||
{ name: "🔄 Checks gesamt", value: `${s.checksRun}`, inline: true },
|
||||
// Statistiken
|
||||
{ name: "🔔 Updates gefunden", value: `${s.updatesFound}`, inline: true },
|
||||
{ name: "📤 Updates gepostet", value: `${s.updatesPosted}`, inline: true },
|
||||
{ name: "⚠️ API-Fehler", value: `${s.apiErrors}`, inline: true },
|
||||
// Bot-Info
|
||||
{ name: "🕐 Online seit", value: startedAt, inline: true },
|
||||
{ name: "🏓 Jobs verarbeitet", value: `${queue.processed}`, inline: true },
|
||||
{ name: "📩 Owner-DMs", value: `${s.dmsSent}`, inline: true },
|
||||
])
|
||||
.setFooter({ text: `${client.config.botName} • Version ${client.packageData.version}` })
|
||||
.setTimestamp();
|
||||
|
||||
return ctx.reply({ embeds: [embed] });
|
||||
},
|
||||
};
|
||||
|
||||
function loadLang(guildID) {
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync(`./serverdata/${guildID}.json`, "utf8"));
|
||||
return getLang(data);
|
||||
} catch { return "de"; }
|
||||
}
|
||||
Reference in New Issue
Block a user