mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 13:14:58 +05:00
This commit is contained in:
parent
689e308aa0
commit
8c09d603bd
5 changed files with 178 additions and 66 deletions
|
@ -1,4 +1,4 @@
|
||||||
const { SlashCommandBuilder, ActionRowBuilder, SelectMenuBuilder, } = require("discord.js"),
|
const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, EmbedBuilder, ButtonStyle } = require("discord.js"),
|
||||||
{ joinVoiceChannel, createAudioResource, createAudioPlayer, getVoiceConnection, AudioPlayerStatus } = require("@discordjs/voice");
|
{ joinVoiceChannel, createAudioResource, createAudioPlayer, getVoiceConnection, AudioPlayerStatus } = require("@discordjs/voice");
|
||||||
const BaseCommand = require("../../base/BaseCommand"),
|
const BaseCommand = require("../../base/BaseCommand"),
|
||||||
fs = require("fs");
|
fs = require("fs");
|
||||||
|
@ -13,7 +13,10 @@ class Clips extends BaseCommand {
|
||||||
command: new SlashCommandBuilder()
|
command: new SlashCommandBuilder()
|
||||||
.setName("clips")
|
.setName("clips")
|
||||||
.setDescription(client.translate("music/clips:DESCRIPTION"))
|
.setDescription(client.translate("music/clips:DESCRIPTION"))
|
||||||
.setDMPermission(false),
|
.setDMPermission(false)
|
||||||
|
.addStringOption(option => option.setName("query")
|
||||||
|
.setDescription(client.translate("music/clips:QUERY"))
|
||||||
|
.setRequired(true)),
|
||||||
aliases: [],
|
aliases: [],
|
||||||
dirname: __dirname,
|
dirname: __dirname,
|
||||||
ownerOnly: false
|
ownerOnly: false
|
||||||
|
@ -36,6 +39,8 @@ class Clips extends BaseCommand {
|
||||||
fs.readdir("./clips", async function (err, files) {
|
fs.readdir("./clips", async function (err, files) {
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
|
|
||||||
|
const query = interaction.options.getString("query");
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
content: "```js\n" + err + "```"
|
content: "```js\n" + err + "```"
|
||||||
|
@ -43,39 +48,118 @@ class Clips extends BaseCommand {
|
||||||
return console.log("Unable to read directory: " + err);
|
return console.log("Unable to read directory: " + err);
|
||||||
}
|
}
|
||||||
|
|
||||||
const clips = files.map(file => {
|
if (query === "list") {
|
||||||
const fileName = file.substring(0, file.length - 4);
|
const clips = files.map(file => file.substring(0, file.length - 4));
|
||||||
return {
|
let currentPage = 0;
|
||||||
label: fileName,
|
const embeds = generateClipsEmbeds(interaction, clips);
|
||||||
value: fileName
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
const row = new ActionRowBuilder()
|
const row = new ActionRowBuilder()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
new SelectMenuBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId("clips_select")
|
.setCustomId("clips_prev_page")
|
||||||
.setPlaceholder(client.translate("common:NOTHING_SELECTED"))
|
.setStyle(ButtonStyle.Primary)
|
||||||
.addOptions(clips)
|
.setEmoji("⬅️"),
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId("clips_next_page")
|
||||||
|
.setStyle(ButtonStyle.Primary)
|
||||||
|
.setEmoji("➡️"),
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId("clips_jump_page")
|
||||||
|
.setStyle(ButtonStyle.Secondary)
|
||||||
|
.setEmoji("↗️"),
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId("clips_stop")
|
||||||
|
.setStyle(ButtonStyle.Danger)
|
||||||
|
.setEmoji("⏹️"),
|
||||||
);
|
);
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
content: interaction.translate("music/clips:AVAILABLE_CLIPS"),
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
||||||
|
embeds: [embeds[currentPage]],
|
||||||
components: [row]
|
components: [row]
|
||||||
});
|
});
|
||||||
|
|
||||||
const filter = i => i.user.id === interaction.user.id;
|
const filter = i => i.user.id === interaction.user.id;
|
||||||
const collector = interaction.channel.createMessageComponentCollector({ filter, idle: (15 * 1000) });
|
const collector = interaction.channel.createMessageComponentCollector({ filter, idle: (20 * 1000) });
|
||||||
|
|
||||||
collector.on("collect", async i => {
|
collector.on("collect", async i => {
|
||||||
if (i.isSelectMenu() && i.customId === "clips_select") {
|
if (i.isButton()) {
|
||||||
const clip = i?.values[0];
|
if (i.customId === "clips_prev_page") {
|
||||||
const voice = i.member.voice.channel;
|
i.deferUpdate();
|
||||||
if (!voice) return i.update({ content: interaction.translate("music/play:NO_VOICE_CHANNEL"), components: [] });
|
|
||||||
const queue = client.player.getQueue(i.guild.id);
|
if (currentPage !== 0) {
|
||||||
if (queue) return i.update({ content: interaction.translate("music/clips:ACTIVE_QUEUE"), components: [] });
|
--currentPage;
|
||||||
if (getVoiceConnection(i.guild.id)) return i.update({ content: interaction.translate("music/clips:ACTIVE_CLIP"), components: [] });
|
interaction.editReply({
|
||||||
if (!fs.existsSync(`./clips/${clip}.mp3`)) return i.update({ content: interaction.translate("music/clips:NO_FILE", { file: clip }), components: [] });
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
||||||
|
embeds: [embeds[currentPage]],
|
||||||
|
components: [row]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (i.customId === "clips_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 === "clips_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 === "clips_stop") {
|
||||||
|
i.deferUpdate();
|
||||||
|
collector.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
collector.on("end", () => {
|
||||||
|
row.components.forEach(component => {
|
||||||
|
component.setDisabled(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
return interaction.editReply({
|
||||||
|
components: [row]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const voice = interaction.member.voice.channel;
|
||||||
|
if (!voice) return interaction.editReply({ content: interaction.translate("music/play:NO_VOICE_CHANNEL") });
|
||||||
|
const queue = client.player.getQueue(interaction.guild.id);
|
||||||
|
if (queue) return interaction.editReply({ content: interaction.translate("music/clips:ACTIVE_QUEUE") });
|
||||||
|
if (getVoiceConnection(interaction.guild.id)) return interaction.editReply({ content: interaction.translate("music/clips:ACTIVE_CLIP") });
|
||||||
|
if (!fs.existsSync(`./clips/${query}.mp3`)) return interaction.editReply({ content: interaction.translate("music/clips:NO_FILE", { file: query }) });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const connection = joinVoiceChannel({
|
const connection = joinVoiceChannel({
|
||||||
|
@ -84,7 +168,7 @@ class Clips extends BaseCommand {
|
||||||
adapterCreator: interaction.guild.voiceAdapterCreator
|
adapterCreator: interaction.guild.voiceAdapterCreator
|
||||||
});
|
});
|
||||||
|
|
||||||
const resource = createAudioResource(fs.createReadStream(`./clips/${clip}.mp3`));
|
const resource = createAudioResource(fs.createReadStream(`./clips/${query}.mp3`));
|
||||||
const player = createAudioPlayer()
|
const player = createAudioPlayer()
|
||||||
.on("error", err => {
|
.on("error", err => {
|
||||||
connection.destroy();
|
connection.destroy();
|
||||||
|
@ -103,20 +187,43 @@ class Clips extends BaseCommand {
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
content: interaction.translate("music/clips:PLAYING", {
|
content: interaction.translate("music/clips:PLAYING", {
|
||||||
clip
|
clip: query
|
||||||
}),
|
}),
|
||||||
components: []
|
components: []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
collector.on("end", () => {
|
|
||||||
return interaction.editReply({
|
|
||||||
components: []
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
||||||
|
* @param {Array} clips
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function generateClipsEmbeds(interaction, clips) {
|
||||||
|
const embeds = [];
|
||||||
|
let k = 10;
|
||||||
|
|
||||||
|
for (let i = 0; i < clips.length; i += 10) {
|
||||||
|
const current = clips.slice(i, k);
|
||||||
|
k += 10;
|
||||||
|
|
||||||
|
const page = current.join("\n");
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setColor(interaction.client.config.embed.color)
|
||||||
|
.setFooter({
|
||||||
|
text: interaction.client.config.embed.footer
|
||||||
|
})
|
||||||
|
.setTitle(interaction.translate("music/clips:CLIPS_LIST"))
|
||||||
|
.setDescription(page)
|
||||||
|
.setTimestamp();
|
||||||
|
embeds.push(embed);
|
||||||
|
}
|
||||||
|
|
||||||
|
return embeds;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Clips;
|
module.exports = Clips;
|
|
@ -56,15 +56,14 @@ class Servers extends BaseCommand {
|
||||||
.setEmoji("⏹️"),
|
.setEmoji("⏹️"),
|
||||||
);
|
);
|
||||||
|
|
||||||
const msg = await interaction.editReply({
|
await interaction.editReply({
|
||||||
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
content: `${interaction.translate("common:PAGE")}: **${currentPage + 1}**/**${embeds.length}**`,
|
||||||
fetchReply: true,
|
|
||||||
embeds: [embeds[currentPage]],
|
embeds: [embeds[currentPage]],
|
||||||
components: [row]
|
components: [row]
|
||||||
});
|
});
|
||||||
|
|
||||||
const filter = i => i.user.id === interaction.user.id;
|
const filter = i => i.user.id === interaction.user.id;
|
||||||
const collector = msg.createMessageComponentCollector({ filter, idle: (20 * 1000) });
|
const collector = interaction.channel.createMessageComponentCollector({ filter, idle: (20 * 1000) });
|
||||||
|
|
||||||
collector.on("collect", async i => {
|
collector.on("collect", async i => {
|
||||||
if (i.isButton()) {
|
if (i.isButton()) {
|
||||||
|
@ -143,7 +142,7 @@ class Servers extends BaseCommand {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
||||||
* @param {*} servers
|
* @param {Array} servers
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function generateServersEmbeds(interaction, servers) {
|
function generateServersEmbeds(interaction, servers) {
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
### JaBa v4.1.13
|
||||||
|
* Изменения
|
||||||
|
* Переписана команда *clips*.
|
||||||
|
|
||||||
### JaBa v4.1.12
|
### JaBa v4.1.12
|
||||||
* Исправления
|
* Исправления
|
||||||
* Фикс поиска по ссылкам.
|
* Фикс поиска по ссылкам.
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
"DESCRIPTION": "Показать список доступных звуков и воспроизвести выбранный",
|
"DESCRIPTION": "Показать список доступных звуков и воспроизвести выбранный",
|
||||||
"USAGE": "",
|
"USAGE": "",
|
||||||
"EXAMPLES": "clips",
|
"EXAMPLES": "clips",
|
||||||
"AVAILABLE_CLIPS": "Список доступных клипов:",
|
"QUERY": "Название клипа / list",
|
||||||
|
"CLIPS_LIST": "Список доступных клипов",
|
||||||
|
"NO_CLIP": "Данный файл не существует",
|
||||||
"ACTIVE_QUEUE": "Не могу воспроизвести клип, т.к. на сервере есть активная очередь",
|
"ACTIVE_QUEUE": "Не могу воспроизвести клип, т.к. на сервере есть активная очередь",
|
||||||
"ACTIVE_CLIP": "Уже воспроизводится какой-то файл",
|
"ACTIVE_CLIP": "Уже воспроизводится какой-то файл",
|
||||||
"PLAYING": "Начато проигрывание клипа `{{clip}}`"
|
"PLAYING": "Начато проигрывание клипа **{{clip}}**"
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "jaba",
|
"name": "jaba",
|
||||||
"version": "4.1.12",
|
"version": "4.1.13",
|
||||||
"description": "My Discord Bot",
|
"description": "My Discord Bot",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|
Loading…
Reference in a new issue