mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 05:04:58 +05:00
Переписана servers
Не вижу смысла делать это как новую версию т.к. команда только для меня
This commit is contained in:
parent
4a9ea0a220
commit
01d036c3d1
4 changed files with 146 additions and 109 deletions
|
@ -36,7 +36,7 @@ class Queue extends BaseCommand {
|
||||||
if (!queue) return interaction.error("music/play:NOT_PLAYING");
|
if (!queue) return interaction.error("music/play:NOT_PLAYING");
|
||||||
|
|
||||||
let currentPage = 0;
|
let currentPage = 0;
|
||||||
let embeds = generateQueueEmbed(interaction, queue);
|
let embeds = generateQueueEmbeds(interaction, queue);
|
||||||
|
|
||||||
const row = new ActionRowBuilder()
|
const row = new ActionRowBuilder()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
|
@ -63,10 +63,7 @@ class Queue extends BaseCommand {
|
||||||
);
|
);
|
||||||
|
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
content: interaction.translate("music/queue:PAGE", {
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/${embeds.length}`,
|
||||||
current: currentPage + 1,
|
|
||||||
length: embeds.length
|
|
||||||
}),
|
|
||||||
embeds: [embeds[currentPage]],
|
embeds: [embeds[currentPage]],
|
||||||
components: [row]
|
components: [row]
|
||||||
});
|
});
|
||||||
|
@ -78,37 +75,31 @@ class Queue extends BaseCommand {
|
||||||
if (i.isButton()) {
|
if (i.isButton()) {
|
||||||
if (i.customId === "queue_prev_page") {
|
if (i.customId === "queue_prev_page") {
|
||||||
i.deferUpdate();
|
i.deferUpdate();
|
||||||
if (embeds != generateQueueEmbed(interaction, queue)) embeds = generateQueueEmbed(interaction, queue);
|
if (embeds != generateQueueEmbeds(interaction, queue)) embeds = generateQueueEmbeds(interaction, queue);
|
||||||
|
|
||||||
if (currentPage !== 0) {
|
if (currentPage !== 0) {
|
||||||
--currentPage;
|
--currentPage;
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: interaction.translate("music/queue:PAGE", {
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/${embeds.length}`,
|
||||||
current: currentPage + 1,
|
|
||||||
length: embeds.length
|
|
||||||
}),
|
|
||||||
embeds: [embeds[currentPage]],
|
embeds: [embeds[currentPage]],
|
||||||
components: [row]
|
components: [row]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (i.customId === "queue_next_page") {
|
} else if (i.customId === "queue_next_page") {
|
||||||
i.deferUpdate();
|
i.deferUpdate();
|
||||||
if (embeds != generateQueueEmbed(interaction, queue)) embeds = generateQueueEmbed(interaction, queue);
|
if (embeds != generateQueueEmbeds(interaction, queue)) embeds = generateQueueEmbeds(interaction, queue);
|
||||||
|
|
||||||
if (currentPage < embeds.length - 1) {
|
if (currentPage < embeds.length - 1) {
|
||||||
currentPage++;
|
currentPage++;
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: interaction.translate("music/queue:PAGE", {
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/${embeds.length}`,
|
||||||
current: currentPage + 1,
|
|
||||||
length: embeds.length
|
|
||||||
}),
|
|
||||||
embeds: [embeds[currentPage]],
|
embeds: [embeds[currentPage]],
|
||||||
components: [row]
|
components: [row]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (i.customId === "queue_jump_page") {
|
} else if (i.customId === "queue_jump_page") {
|
||||||
i.deferUpdate();
|
i.deferUpdate();
|
||||||
if (embeds != generateQueueEmbed(interaction, queue)) embeds = generateQueueEmbed(interaction, queue);
|
if (embeds != generateQueueEmbeds(interaction, queue)) embeds = generateQueueEmbeds(interaction, queue);
|
||||||
|
|
||||||
const msg = await interaction.followUp({
|
const msg = await interaction.followUp({
|
||||||
content: interaction.translate("music/queue:PAGE_TO_JUMP", {
|
content: interaction.translate("music/queue:PAGE_TO_JUMP", {
|
||||||
|
@ -121,14 +112,11 @@ class Queue extends BaseCommand {
|
||||||
return res.author.id === interaction.user.id && !isNaN(res.content);
|
return res.author.id === interaction.user.id && !isNaN(res.content);
|
||||||
};
|
};
|
||||||
|
|
||||||
interaction.channel.awaitMessages({ filter, max: 1, time: (30 * 1000) }).then(collected => {
|
interaction.channel.awaitMessages({ filter, max: 1, time: (10 * 1000) }).then(collected => {
|
||||||
if (embeds[collected.first().content - 1]) {
|
if (embeds[collected.first().content - 1]) {
|
||||||
currentPage = collected.first().content - 1;
|
currentPage = collected.first().content - 1;
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: interaction.translate("music/queue:PAGE", {
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/${embeds.length}`,
|
||||||
current: currentPage + 1,
|
|
||||||
length: embeds.length
|
|
||||||
}),
|
|
||||||
embeds: [embeds[currentPage]],
|
embeds: [embeds[currentPage]],
|
||||||
components: [row]
|
components: [row]
|
||||||
});
|
});
|
||||||
|
@ -166,7 +154,7 @@ class Queue extends BaseCommand {
|
||||||
* @param {import("discord-player").Queue} queue
|
* @param {import("discord-player").Queue} queue
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function generateQueueEmbed(interaction, queue) {
|
function generateQueueEmbeds(interaction, queue) {
|
||||||
const embeds = [];
|
const embeds = [];
|
||||||
const currentTrack = queue.current;
|
const currentTrack = queue.current;
|
||||||
let k = 10;
|
let k = 10;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js");
|
||||||
const BaseCommand = require("../../base/BaseCommand");
|
const BaseCommand = require("../../base/BaseCommand");
|
||||||
|
|
||||||
class Servers extends BaseCommand {
|
class Servers extends BaseCommand {
|
||||||
|
@ -31,102 +31,151 @@ class Servers extends BaseCommand {
|
||||||
* @param {Object} data
|
* @param {Object} data
|
||||||
*/
|
*/
|
||||||
async execute(client, interaction) {
|
async execute(client, interaction) {
|
||||||
let i0 = 0,
|
await interaction.deferReply({ ephemeral: true });
|
||||||
i1 = 10,
|
|
||||||
page = 1;
|
|
||||||
|
|
||||||
let description = `${interaction.translate("common:SERVERS")}: ${client.guilds.cache.size}\n\n` +
|
let currentPage = 0;
|
||||||
client.guilds.cache
|
const embeds = generateServersEmbeds(interaction, client.guilds.cache);
|
||||||
.sort((a, b) => b.memberCount - a.memberCount)
|
|
||||||
.map((r) => r)
|
|
||||||
.map((r, i) => `**${i + 1}** - ${r.name} | ${r.memberCount} ${client.getNoun(r.memberCount, interaction.translate("misc:NOUNS:MEMBERS:1"), interaction.translate("misc:NOUNS:MEMBERS:2"), interaction.translate("misc:NOUNS:MEMBERS:5"))}`)
|
|
||||||
.slice(0, 10)
|
|
||||||
.join("\n");
|
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const row = new ActionRowBuilder()
|
||||||
.setAuthor({
|
.addComponents(
|
||||||
name: interaction.user.tag,
|
new ButtonBuilder()
|
||||||
iconURL: interaction.member.displayAvatarURL({
|
.setCustomId("servers_prev_page")
|
||||||
extension: "png",
|
.setStyle(ButtonStyle.Primary)
|
||||||
size: 512
|
.setEmoji("⬅️"),
|
||||||
})
|
new ButtonBuilder()
|
||||||
})
|
.setCustomId("servers_next_page")
|
||||||
.setColor(client.config.embed.color)
|
.setStyle(ButtonStyle.Primary)
|
||||||
.setFooter({
|
.setEmoji("➡️"),
|
||||||
text: client.user.username
|
new ButtonBuilder()
|
||||||
})
|
.setCustomId("servers_jump_page")
|
||||||
.setTitle(`${interaction.translate("common:PAGE")}: ${page}/${client.guilds.cache.size}`)
|
.setStyle(ButtonStyle.Secondary)
|
||||||
.setDescription(description);
|
.setEmoji("↗️"),
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId("servers_stop")
|
||||||
|
.setStyle(ButtonStyle.Danger)
|
||||||
|
.setEmoji("⏹️"),
|
||||||
|
);
|
||||||
|
|
||||||
await interaction.reply({
|
await interaction.editReply({
|
||||||
embeds: [embed],
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
||||||
|
embeds: [embeds[currentPage]],
|
||||||
|
components: [row]
|
||||||
});
|
});
|
||||||
|
|
||||||
const msg = await interaction.fetchReply();
|
const filter = i => i.user.id === interaction.user.id;
|
||||||
|
const collector = interaction.channel.createMessageComponentCollector({ filter, idle: (20 * 1000) });
|
||||||
|
|
||||||
await msg.react("⬅");
|
collector.on("collect", async i => {
|
||||||
await msg.react("➡");
|
if (i.isButton()) {
|
||||||
await msg.react("❌");
|
if (i.customId === "servers_prev_page") {
|
||||||
|
i.deferUpdate();
|
||||||
|
|
||||||
const collector = msg.createReactionCollector({
|
if (currentPage !== 0) {
|
||||||
time: (2 * 1000)
|
--currentPage;
|
||||||
|
interaction.editReply({
|
||||||
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/${embeds.length}`,
|
||||||
|
embeds: [embeds[currentPage]],
|
||||||
|
components: [row]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (i.customId === "servers_next_page") {
|
||||||
|
i.deferUpdate();
|
||||||
|
|
||||||
|
if (currentPage < embeds.length - 1) {
|
||||||
|
currentPage++;
|
||||||
|
interaction.editReply({
|
||||||
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/${embeds.length}`,
|
||||||
|
embeds: [embeds[currentPage]],
|
||||||
|
components: [row]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (i.customId === "servers_jump_page") {
|
||||||
|
i.deferUpdate();
|
||||||
|
|
||||||
|
const msg = await interaction.followUp({
|
||||||
|
content: interaction.translate("music/queue:PAGE_TO_JUMP", {
|
||||||
|
length: embeds.length
|
||||||
|
}),
|
||||||
|
fetchReply: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const filter = res => {
|
||||||
|
return res.author.id === interaction.user.id && !isNaN(res.content);
|
||||||
|
};
|
||||||
|
|
||||||
|
interaction.channel.awaitMessages({ filter, max: 1, time: (10 * 1000) }).then(collected => {
|
||||||
|
if (embeds[collected.first().content - 1]) {
|
||||||
|
currentPage = collected.first().content - 1;
|
||||||
|
interaction.editReply({
|
||||||
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/${embeds.length}`,
|
||||||
|
embeds: [embeds[currentPage]],
|
||||||
|
components: [row]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (collected.first().deletable) collected.first().delete();
|
||||||
|
if (msg.deletable) msg.delete();
|
||||||
|
} else {
|
||||||
|
if (collected.first().deletable) collected.first().delete();
|
||||||
|
if (msg.deletable) msg.delete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (i.customId === "servers_stop") {
|
||||||
|
i.deferUpdate();
|
||||||
|
collector.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
collector.on("collect", async reaction => {
|
collector.on("end", () => {
|
||||||
if (reaction._emoji.name === "⬅") {
|
row.components.forEach(component => {
|
||||||
i0 = i0 - 10;
|
component.setDisabled(true);
|
||||||
i1 = i1 - 10;
|
});
|
||||||
page = page - 1;
|
|
||||||
|
|
||||||
if (i0 < 0) return msg.delete();
|
return interaction.editReply({
|
||||||
if (!i0 || !i1) return msg.delete();
|
components: [row]
|
||||||
|
});
|
||||||
description = `${interaction.translate("common:SERVERS")}: ${client.guilds.cache.size}\n\n` +
|
|
||||||
client.guilds.cache
|
|
||||||
.sort((a, b) => b.memberCount - a.memberCount)
|
|
||||||
.map(r => r)
|
|
||||||
.map((r, i) => `**${i + 1}** - ${r.name} | ${r.memberCount} ${client.getNoun(r.memberCount, interaction.translate("misc:NOUNS:MEMBERS:1"), interaction.translate("misc:NOUNS:MEMBERS:2"), interaction.translate("misc:NOUNS:MEMBERS:5"))}`)
|
|
||||||
.slice(i0, i1)
|
|
||||||
.join("\n");
|
|
||||||
|
|
||||||
embed
|
|
||||||
.setTitle(`${interaction.translate("common:PAGE")}: ${page}/${client.guilds.cache.size}`)
|
|
||||||
.setDescription(description);
|
|
||||||
|
|
||||||
msg.edit({
|
|
||||||
embeds: [embed]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reaction._emoji.name === "➡") {
|
|
||||||
i0 = i0 + 10;
|
|
||||||
i1 = i1 + 10;
|
|
||||||
page = page + 1;
|
|
||||||
|
|
||||||
if (i1 > client.guilds.cache.size + 10) return msg.delete();
|
|
||||||
if (!i0 || !i1) return msg.delete();
|
|
||||||
|
|
||||||
description = `${interaction.translate("common:SERVERS")}: ${client.guilds.cache.size}\n\n` +
|
|
||||||
client.guilds.cache
|
|
||||||
.sort((a, b) => b.memberCount - a.memberCount)
|
|
||||||
.map((r) => r)
|
|
||||||
.map((r, i) => `**${i + 1}** - ${r.name} | ${r.memberCount} ${client.getNoun(r.memberCount, interaction.translate("misc:NOUNS:MEMBERS:1"), interaction.translate("misc:NOUNS:MEMBERS:2"), interaction.translate("misc:NOUNS:MEMBERS:5"))}`)
|
|
||||||
.slice(i0, i1)
|
|
||||||
.join("\n");
|
|
||||||
|
|
||||||
embed.setTitle(`${interaction.translate("common:PAGE")}: ${page}/${Math.round(client.guilds.cache.size / 10)}`)
|
|
||||||
.setDescription(description);
|
|
||||||
|
|
||||||
msg.edit({
|
|
||||||
embeds: [embed]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reaction._emoji.name === "❌") return msg.delete();
|
|
||||||
|
|
||||||
await reaction.users.remove(interaction.member.id);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
||||||
|
* @param {*} servers
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function generateServersEmbeds(interaction, servers) {
|
||||||
|
const embeds = [];
|
||||||
|
let k = 10;
|
||||||
|
|
||||||
|
for (let i = 0; i < servers.size; i += 10) {
|
||||||
|
const current = servers.map(g => g).slice(i, k).sort((a, b) => b.memberCount - a.memberCount);
|
||||||
|
let j = i;
|
||||||
|
k += 10;
|
||||||
|
|
||||||
|
const info = current.map(server => `${++j}. ${server.name} | ${server.memberCount} ${interaction.client.getNoun(server.memberCount, interaction.translate("misc:NOUNS:MEMBERS:1"), interaction.translate("misc:NOUNS:MEMBERS:2"), interaction.translate("misc:NOUNS:MEMBERS:5"))}`).join("\n");
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(interaction.client.config.embed.color)
|
||||||
|
.setFooter({
|
||||||
|
text: interaction.client.config.embed.footer
|
||||||
|
})
|
||||||
|
.setTitle(interaction.translate("owner/servers:SERVERS_LIST"))
|
||||||
|
.setDescription(info)
|
||||||
|
.setTimestamp();
|
||||||
|
embeds.push(embed);
|
||||||
|
}
|
||||||
|
|
||||||
|
return embeds;
|
||||||
|
}
|
||||||
|
|
||||||
|
// `${interaction.translate("common:SERVERS")}: ${interaction.client.guilds.cache.size}\n\n` +
|
||||||
|
// interaction.client.guilds.cache
|
||||||
|
// .sort((a, b) => b.memberCount - a.memberCount)
|
||||||
|
// .map(g => g)
|
||||||
|
// .map((g, i) => `${i + 1}. ${g.name} | ${g.memberCount} ${interaction.client.getNoun(g.memberCount, interaction.translate("misc:NOUNS:MEMBERS:1"), interaction.translate("misc:NOUNS:MEMBERS:2"), interaction.translate("misc:NOUNS:MEMBERS:5"))}`)
|
||||||
|
// .slice(i, k)
|
||||||
|
// .join("\n")
|
||||||
|
|
||||||
module.exports = Servers;
|
module.exports = Servers;
|
|
@ -3,7 +3,6 @@
|
||||||
"USAGE": "",
|
"USAGE": "",
|
||||||
"EXAMPLES": "queue",
|
"EXAMPLES": "queue",
|
||||||
"QUEUE": "Очередь",
|
"QUEUE": "Очередь",
|
||||||
"PAGE": "Страница **{{current}}**/**{{length}}**",
|
|
||||||
"NO_QUEUE": "Пусто",
|
"NO_QUEUE": "Пусто",
|
||||||
"DURATION": "Длительность очереди",
|
"DURATION": "Длительность очереди",
|
||||||
"ADDED": "Добавил",
|
"ADDED": "Добавил",
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"DESCRIPTION": "Показать список серверов бота",
|
"DESCRIPTION": "Показать список серверов бота",
|
||||||
"USAGE": "",
|
"USAGE": "",
|
||||||
"EXAMPLES": "servers"
|
"EXAMPLES": "servers",
|
||||||
|
"SERVERS_LIST": "Список серверов"
|
||||||
}
|
}
|
Loading…
Reference in a new issue