Update from Git Manager GUI

This commit is contained in:
2026-02-25 18:51:08 +01:00
parent de4341a0a9
commit 1567151fce
21 changed files with 2023 additions and 0 deletions

117
commands/search.js Normal file
View File

@@ -0,0 +1,117 @@
import { EmbedBuilder, SlashCommandBuilder } from "discord.js";
import { Spiget } from "spiget";
const spiget = new Spiget("Viper-Network");
export default {
name: "search",
description: "Durchsucht die Spiget-API nach einer Ressource und gibt die Top-Ergebnisse zurück",
aliases: [],
guild: ["all"],
nsfw: false,
user_permissions: [],
bot_permissions: [],
args_required: 1,
args_usage: `[ressourcenname] Beispiel: vn!search Vault\nTipp: -n [anzahl] für Suchmenge (Standard: 100), -r für Sortierung nach Bewertung\nBeispiel: vn!search a -n 5000 -r`,
cooldown: 3,
data: new SlashCommandBuilder()
.setName("search")
.setDescription("Sucht nach einem Plugin auf SpigotMC")
.addStringOption((opt) =>
opt.setName("name").setDescription("Name des Plugins").setRequired(true)
)
.addIntegerOption((opt) =>
opt.setName("anzahl").setDescription("Suchmenge (Standard: 100)").setRequired(false)
)
.addStringOption((opt) =>
opt
.setName("sortierung")
.setDescription("Sortierung der Ergebnisse")
.setRequired(false)
.addChoices(
{ name: "Downloads", value: "downloads" },
{ name: "Bewertung", value: "rating" }
)
),
async execute(client, ctx, args) {
let search, size, sortBy;
if (ctx.isSlash) {
search = ctx.interaction.options.getString("name");
size = ctx.interaction.options.getInteger("anzahl") ?? 100;
sortBy = ctx.interaction.options.getString("sortierung") ?? "downloads";
} else {
size = 100;
sortBy = "downloads";
// Parse -n flag
const nIdx = args.indexOf("-n");
if (nIdx !== -1 && args[nIdx + 1]) {
const parsed = parseInt(args[nIdx + 1], 10);
if (!isNaN(parsed) && parsed > 0) size = parsed;
args.splice(nIdx, 2);
}
// Parse -r flag (sort by rating)
const rIdx = args.indexOf("-r");
if (rIdx !== -1) {
sortBy = "rating";
args.splice(rIdx, 1);
}
if (args.length === 0) {
return ctx.reply("Bitte gib einen Suchbegriff an!");
}
search = args.join(" ");
}
const apiURL = `https://api.spiget.org/v2/search/resources/${encodeURIComponent(search)}?size=${size}`;
let results;
try {
const res = await fetch(apiURL);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
results = await res.json();
} catch (e) {
client.logger.error(e);
return ctx.reply("Die Spiget-API konnte nicht erreicht werden. Bitte versuche es später erneut.");
}
if (!Array.isArray(results) || results.length === 0) {
return ctx.reply(`Keine Ergebnisse für \`${search}\` gefunden.`);
}
// Sort by downloads or rating
const topResults = results
.sort((a, b) => {
if (sortBy === "rating") {
const ratingA = a.rating?.average ?? 0;
const ratingB = b.rating?.average ?? 0;
return ratingB - ratingA;
}
return b.downloads - a.downloads;
})
.slice(0, 5);
const list = topResults
.map(({ id, name, downloads, rating }) => {
const stars = rating?.average ? `${rating.average.toFixed(1)}` : "⭐ k.A.";
return `**${name}**\n⬇️ *${downloads.toLocaleString("de-DE")}* ${stars} 🆔 ${id}`;
})
.join("\n\n");
const sortLabel = sortBy === "rating" ? "Bewertung" : "Downloads";
const resultEmbed = new EmbedBuilder()
.setColor(ctx.guild.members.me.displayHexColor)
.setTitle(`:mag: Top-Ergebnisse für '${search}'`)
.setDescription(`${list}\n\n⬇️ = Downloads ⭐ = Bewertung 🆔 = Plugin-ID`)
.setFooter({
text: `Sortiert nach: ${sortLabel} | ${client.config.prefix}plugin [id] für mehr Details`,
});
return ctx.reply({ embeds: [resultEmbed] });
},
};