Фикс loop
Выбор при поиске
Фикс queue
Фикс автовоспроизведения
This commit is contained in:
JonnyBro 2022-08-28 16:45:05 +05:00
parent 9136500baa
commit e8ab25d80c
12 changed files with 2001 additions and 1627 deletions

View file

@ -248,16 +248,14 @@ class JaBa extends Client {
* @param {Array} args * @param {Array} args
* @param {String} locale * @param {String} locale
*/ */
translate(key, args, locale) { translate(key, args, locale = this.defaultLanguage) {
if (!locale) locale = this.defaultLanguage;
const language = this.translations.get(locale); const language = this.translations.get(locale);
if (!language) throw "Invalid language set in data."; if (!language) throw "Invalid language set in data.";
return language(key, args); return language(key, args);
} }
printDate(date, format, locale) { printDate(date, format = false, locale = this.defaultLanguage) {
if (!locale) locale = this.defaultLanguage;
const languageData = this.languages.find((language) => language.name === locale || language.aliases.includes(locale)); const languageData = this.languages.find((language) => language.name === locale || language.aliases.includes(locale));
if (!format) format = languageData.defaultMomentFormat; if (!format) format = languageData.defaultMomentFormat;
@ -266,9 +264,7 @@ class JaBa extends Client {
.format(format); .format(format);
} }
convertTime(time, type, noPrefix, locale) { convertTime(time, type = false, noPrefix = false, locale = this.defaultLanguage) {
if (!type) type = false;
if (!locale) locale = this.defaultLanguage;
const languageData = this.languages.find((language) => language.name === locale || language.aliases.includes(locale)); const languageData = this.languages.find((language) => language.name === locale || language.aliases.includes(locale));
const m = moment(time).locale(languageData.moment); const m = moment(time).locale(languageData.moment);

View file

@ -1,4 +1,4 @@
const { SlashCommandBuilder, ActionRowBuilder, SelectMenuBuilder, InteractionCollector, ComponentType } = require("discord.js"), const { SlashCommandBuilder, ActionRowBuilder, SelectMenuBuilder } = require("discord.js"),
{ QueueRepeatMode } = require("discord-player"); { QueueRepeatMode } = require("discord-player");
const BaseCommand = require("../../base/BaseCommand"); const BaseCommand = require("../../base/BaseCommand");
@ -32,6 +32,8 @@ class Loop extends BaseCommand {
* @param {Object} data * @param {Object} data
*/ */
async execute(client, interaction) { async execute(client, interaction) {
await interaction.deferReply();
const voice = interaction.member.voice.channel; const voice = interaction.member.voice.channel;
if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL"); if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL");
const queue = client.player.getQueue(interaction.guildId); const queue = client.player.getQueue(interaction.guildId);
@ -62,42 +64,36 @@ class Loop extends BaseCommand {
]) ])
); );
const msg = await interaction.reply({ await interaction.editReply({
content: interaction.translate("common:AVAILABLE_OPTIONS"), content: interaction.translate("common:AVAILABLE_OPTIONS"),
components: [row], components: [row]
fetchReply: true
}); });
const collector = new InteractionCollector(client, { const filter = i => i.user.id === interaction.user.id;
componentType: ComponentType.SelectMenu, const collector = interaction.channel.createMessageComponentCollector({ filter, idle: (15 * 1000) });
message: msg,
idle: (2 * 1000)
});
collector.on("collect", async i => { collector.on("collect", async i => {
const type = i?.values[0]; if (i.isSelectMenu()) {
const mode = type === "3" ? QueueRepeatMode.AUTOPLAY : const type = i?.values[0];
type === "2" ? QueueRepeatMode.QUEUE : const mode = type === "3" ? QueueRepeatMode.AUTOPLAY :
type === "1" ? QueueRepeatMode.TRACK : QueueRepeatMode.OFF; type === "2" ? QueueRepeatMode.QUEUE :
type === "1" ? QueueRepeatMode.TRACK : QueueRepeatMode.OFF;
queue.setRepeatMode(mode); queue.setRepeatMode(mode);
return i.update({ return interaction.editReply({
content: interaction.translate(`music/loop:${ content: interaction.translate(`music/loop:${
type === "3" ? "AUTOPLAY_ENABLED" : type === "3" ? "AUTOPLAY_ENABLED" :
type === "2" ? "QUEUE_ENABLED" : type === "2" ? "QUEUE_ENABLED" :
type === "1" ? "TRACK_ENABLED" : "LOOP_DISABLED" type === "1" ? "TRACK_ENABLED" : "LOOP_DISABLED"
}`), }`),
components: []
});
});
collector.on("end", (_, reason) => {
if (reason === "idle") {
if (msg) msg.update({
components: [] components: []
}); });
} }
}); });
collector.on("end", (_, reason) => {
if (reason) interaction.deleteReply();
});
} }
} }

View file

@ -42,7 +42,7 @@ class Nowplaying extends BaseCommand {
.setAuthor({ .setAuthor({
name: interaction.translate("music/queue:TITLE") name: interaction.translate("music/queue:TITLE")
}) })
.setThumbnail(track.thumbnail || "https://cdn.discordapp.com/attachments/708642702602010684/1012418217660121089/noimage.png") .setThumbnail(track.thumbnail)
.addFields([ .addFields([
{ {
name: interaction.translate("music/nowplaying:T_TITLE"), name: interaction.translate("music/nowplaying:T_TITLE"),

View file

@ -1,4 +1,4 @@
const { SlashCommandBuilder, PermissionsBitField } = require("discord.js"); const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, PermissionsBitField } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand"); const BaseCommand = require("../../base/BaseCommand");
class Play extends BaseCommand { class Play extends BaseCommand {
@ -61,6 +61,154 @@ class Play extends BaseCommand {
spotifyBridge: false spotifyBridge: false
}); });
const searched = searchResult.tracks[0].description === "search";
if (searched) {
const row1 = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId("1")
.setStyle(ButtonStyle.Primary)
.setEmoji("1⃣"),
new ButtonBuilder()
.setCustomId("2")
.setStyle(ButtonStyle.Primary)
.setEmoji("2⃣"),
new ButtonBuilder()
.setCustomId("3")
.setStyle(ButtonStyle.Primary)
.setEmoji("3⃣"),
new ButtonBuilder()
.setCustomId("4")
.setStyle(ButtonStyle.Primary)
.setEmoji("4⃣"),
new ButtonBuilder()
.setCustomId("5")
.setStyle(ButtonStyle.Primary)
.setEmoji("5⃣"),
);
const row2 = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId("6")
.setStyle(ButtonStyle.Primary)
.setEmoji("6⃣"),
new ButtonBuilder()
.setCustomId("7")
.setStyle(ButtonStyle.Primary)
.setEmoji("7⃣"),
new ButtonBuilder()
.setCustomId("8")
.setStyle(ButtonStyle.Primary)
.setEmoji("8⃣"),
new ButtonBuilder()
.setCustomId("9")
.setStyle(ButtonStyle.Primary)
.setEmoji("9⃣"),
new ButtonBuilder()
.setCustomId("10")
.setStyle(ButtonStyle.Primary)
.setEmoji("🔟"),
);
const row3 = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId("search_cancel")
.setLabel(interaction.translate("common:CANCEL"))
.setStyle(ButtonStyle.Danger)
.setEmoji("❌"),
);
const rows = [row1, row2, row3];
const embed = new EmbedBuilder()
.setTitle(interaction.translate("music/play:RESULTS_TITLE", {
query
}))
.setThumbnail(interaction.client.user.avatarURL())
.setColor(client.config.embed.color)
.setDescription(searchResult.tracks.map(track => {
const views = new Intl.NumberFormat(interaction.client.languages.find(language => language.name === interaction.guild.data.language).moment, {
notation: "compact", compactDisplay: "short"
}).format(track.views);
return `${searchResult.tracks.indexOf(track) + 1}. [${track.title}](${track.url})\n> ${interaction.translate("common:VIEWS")}: **${views}**`;
}).join("\n"))
.setTimestamp();
await interaction.editReply({
content: interaction.translate("music/play:SEARCH_RESULTS"),
embeds: [embed],
components: [row1, row2, row3]
});
const filter = i => i.user.id === interaction.user.id;
const collector = interaction.channel.createMessageComponentCollector({ filter, idle: (15 * 1000) });
collector.on("collect", async i => {
if (i.isButton()) {
if (i.customId >= 1 && i.customId <= 10) {
i.deferUpdate();
var selected = searchResult.tracks[i.customId - 1];
queue.addTrack(selected);
try {
if (!queue.connection) await queue.connect(interaction.member.voice.channel);
if (!queue.playing) await queue.play();
rows.forEach(row => {
row.components.forEach(component => {
component.setDisabled(true);
});
});
return interaction.editReply({
content: interaction.translate("music/play:ADDED_QUEUE", {
songName: selected.title
}),
components: [row1, row2, row3]
});
} catch (e) {
client.player.deleteQueue(interaction.guildId);
console.error(e);
return interaction.editReply({
content: interaction.translate("music/play:ERR_OCCURRED", {
error: e
})
});
}
} else if (i.customId === "search_cancel") {
i.deferUpdate();
rows.forEach(row => {
row.components.forEach(component => {
component.setDisabled(true);
});
});
return interaction.editReply({
components: [row1, row2, row3]
});
}
}
});
collector.on("end", async (_, reason) => {
if (reason) {
rows.forEach(row => {
row.components.forEach(component => {
component.setDisabled(true);
});
});
return interaction.editReply({
components: [row1, row2, row3]
});
}
});
return;
}
searchResult.playlist ? queue.addTracks(searchResult.tracks) : queue.addTrack(searchResult.tracks[0]); searchResult.playlist ? queue.addTracks(searchResult.tracks) : queue.addTrack(searchResult.tracks[0]);
try { try {

View file

@ -1,4 +1,5 @@
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js"); const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js"),
{ QueueRepeatMode } = require("discord-player");
const BaseCommand = require("../../base/BaseCommand"); const BaseCommand = require("../../base/BaseCommand");
class Queue extends BaseCommand { class Queue extends BaseCommand {
@ -121,8 +122,8 @@ class Queue extends BaseCommand {
}; };
interaction.channel.awaitMessages({ filter, max: 1, time: (30 * 1000) }).then(collected => { interaction.channel.awaitMessages({ filter, max: 1, time: (30 * 1000) }).then(collected => {
if (embeds[Number(collected.first().content) - 1]) { if (embeds[collected.first().content - 1]) {
currentPage = Number(collected.first().content) - 1; currentPage = collected.first().content - 1;
interaction.editReply({ interaction.editReply({
content: interaction.translate("music/queue:PAGE", { content: interaction.translate("music/queue:PAGE", {
current: currentPage + 1, current: currentPage + 1,
@ -149,33 +150,10 @@ class Queue extends BaseCommand {
collector.on("end", async (_, reason) => { collector.on("end", async (_, reason) => {
if (reason) { if (reason) {
const row = new ActionRowBuilder() row.components.forEach(component => {
.addComponents( component.setDisabled(true);
new ButtonBuilder() });
.setCustomId("queue_prev_page")
.setLabel(interaction.translate("music/queue:PREV_PAGE"))
.setStyle(ButtonStyle.Primary)
.setEmoji("⬅️")
.setDisabled(true),
new ButtonBuilder()
.setCustomId("queue_next_page")
.setLabel(interaction.translate("music/queue:NEXT_PAGE"))
.setStyle(ButtonStyle.Primary)
.setEmoji("➡️")
.setDisabled(true),
new ButtonBuilder()
.setCustomId("queue_jump_page")
.setLabel(interaction.translate("music/queue:JUMP_PAGE"))
.setStyle(ButtonStyle.Secondary)
.setEmoji("↗️")
.setDisabled(true),
new ButtonBuilder()
.setCustomId("queue_stop")
.setLabel(interaction.translate("common:CANCEL"))
.setStyle(ButtonStyle.Danger)
.setEmoji("⏹️")
.setDisabled(true),
);
return interaction.editReply({ return interaction.editReply({
components: [row] components: [row]
}); });
@ -184,11 +162,33 @@ class Queue extends BaseCommand {
} }
} }
/**
*
* @param {import("discord.js").ChatInputCommandInteraction} interaction
* @param {import("discord-player").Queue} queue
* @returns
*/
function generateQueueEmbed(interaction, queue) { function generateQueueEmbed(interaction, queue) {
const embeds = []; const embeds = [];
const currentTrack = queue.current; const currentTrack = queue.current;
let k = 10; let k = 10;
if (!queue.tracks.length) {
const embed = new EmbedBuilder()
.setTitle(interaction.translate("music/nowplaying:CURRENTLY_PLAYING"))
.setThumbnail(currentTrack.thumbnail)
.setColor(interaction.client.config.embed.color)
.setDescription(`${interaction.translate("music/nowplaying:REPEAT")}: \`${
queue.repeatMode === QueueRepeatMode.AUTOPLAY ? interaction.translate("music/nowplaying:AUTOPLAY") :
queue.repeatMode === QueueRepeatMode.QUEUE ? interaction.translate("music/nowplaying:QUEUE") :
queue.repeatMode === QueueRepeatMode.TRACK ? interaction.translate("music/nowplaying:TRACK") : interaction.translate("common:DISABLED")
}\`\n${interaction.translate("music/queue:DURATION")}: \`${interaction.client.convertTime(Date.now() + queue.totalTime, false, true, interaction.guild.data.language)}\`\n[${currentTrack.title}](${currentTrack.url})\n> ${interaction.translate("music/queue:ADDED")} ${currentTrack.requestedBy}\n\n**${interaction.translate("music/queue:NEXT")}**\n${interaction.translate("music/queue:NO_QUEUE")}`)
.setTimestamp();
embeds.push(embed);
return embeds;
}
for (let i = 0; i < queue.tracks.length; i += 10) { for (let i = 0; i < queue.tracks.length; i += 10) {
const current = queue.tracks.slice(i, k); const current = queue.tracks.slice(i, k);
let j = i; let j = i;
@ -198,9 +198,13 @@ function generateQueueEmbed(interaction, queue) {
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle(interaction.translate("music/nowplaying:CURRENTLY_PLAYING")) .setTitle(interaction.translate("music/nowplaying:CURRENTLY_PLAYING"))
.setThumbnail(currentTrack.thumbnail || "https://cdn.discordapp.com/attachments/708642702602010684/1012418217660121089/noimage.png") .setThumbnail(currentTrack.thumbnail)
.setColor(interaction.client.config.embed.color) .setColor(interaction.client.config.embed.color)
.setDescription(`[${currentTrack.title}](${currentTrack.url})\n> ${interaction.translate("music/queue:ADDED")} ${currentTrack.requestedBy}\n\n**${interaction.translate("music/queue:NEXT")}**\n${info}`) .setDescription(`${interaction.translate("music/nowplaying:REPEAT")}: \`${
queue.repeatMode === QueueRepeatMode.AUTOPLAY ? interaction.translate("music/nowplaying:AUTOPLAY") :
queue.repeatMode === QueueRepeatMode.QUEUE ? interaction.translate("music/nowplaying:QUEUE") :
queue.repeatMode === QueueRepeatMode.TRACK ? interaction.translate("music/nowplaying:TRACK") : interaction.translate("common:DISABLED")
}\`\n${interaction.translate("music/queue:DURATION")}: \`${interaction.client.convertTime(Date.now() + queue.totalTime, false, true, interaction.guild.data.language)}\`\n[${currentTrack.title}](${currentTrack.url})\n> ${interaction.translate("music/queue:ADDED")} ${currentTrack.requestedBy}\n\n**${interaction.translate("music/queue:NEXT")}**\n${info}`)
.setTimestamp(); .setTimestamp();
embeds.push(embed); embeds.push(embed);
} }

View file

@ -1,3 +1,14 @@
### JaBa v4.1.2
* Добавлено
* Выбор при поиске текстом через команду *play*.
* Изменения
* Немного переделана команда *loop*.
* Исправления
* Исправлена ошибка команды *queue* если очередь пуста.
* Починено автовоспроизведение.
### JaBa v4.1.1 ### JaBa v4.1.1
* Добавлено * Добавлено
* Страницы в *queue*. * Страницы в *queue*.
@ -55,16 +66,16 @@
* Изменения * Изменения
* Все команды теперь являются слэш-командами! * Все команды теперь являются слэш-командами!
* Все команды доступны через **/**. * Все команды доступны через **/**!
* С помощью слэш-команд намного удобнее указывать аргументы для команд. * С помощью слэш-команд намного удобнее указывать аргументы для команд!
* Запрет на использование слэш-команд настраивается в **Настройки сервера** - **Интеграция** - **JaBa**. * Запрет на использование слэш-команд настраивается в **Настройки сервера** - **Интеграция** - **JaBa**!
* Команда *avatar* перенесена в категорию *General*. * Команда *avatar* перенесена в категорию *General*!
* Команда *jump* переименована в *skipto*. * Команда *jump* переименована в *skipto*!
* Команда *setafk* переименована в *afk*. * Команда *setafk* переименована в *afk*!
* Команда *lmg* переименована в *lmgtfy*. * Команда *lmg* переименована в *lmgtfy*!
* Команда *warn* доступна при нажатии на **пользователя** - **Приложения** - *warn*. В будущем там будет больше команд. * Команда *warn* доступна при нажатии **на пользователя** - **Приложения** - *warn*! В будущем там будет больше команд.
* Автопроигрывание музыки теперь находится в *loop*. * Автопроигрывание музыки теперь находится в *loop*!
* Все клипы доступны через команду *clips*. * Все клипы доступны через команду *clips*!
* Удалено * Удалено
* Категория *Images* * Категория *Images*

View file

@ -1,4 +1,5 @@
const playdl = require("play-dl"); const playdl = require("play-dl"),
fallbackImage = "https://cdn.discordapp.com/attachments/708642702602010684/1012418217660121089/noimage.png";
// const fetch = require("node-fetch"); // const fetch = require("node-fetch");
// const { getData, getPreview, getTracks } = require("spotify-url-info")(fetch); // const { getData, getPreview, getTracks } = require("spotify-url-info")(fetch);
@ -35,7 +36,7 @@ module.exports = {
const track = { const track = {
title: info.name, title: info.name,
duration: info.durationInMs, duration: info.durationInMs,
thumbnail: info.thumbnail, thumbnail: info.thumbnail || fallbackImage,
async engine() { async engine() {
return (await playdl.stream(info.url, { discordPlayerCompatibility: true })).stream; return (await playdl.stream(info.url, { discordPlayerCompatibility: true })).stream;
}, },
@ -52,7 +53,7 @@ module.exports = {
return { return {
title: track.name, title: track.name,
duration: track.durationInMs, duration: track.durationInMs,
thumbnail: track.thumbnail, thumbnail: track.thumbnail || fallbackImage,
async engine() { async engine() {
return (await playdl.stream(track.url, { discordPlayerCompatibility: true })).stream; return (await playdl.stream(track.url, { discordPlayerCompatibility: true })).stream;
}, },
@ -66,7 +67,7 @@ module.exports = {
const playlist = { const playlist = {
title: info.name, title: info.name,
description: "", description: "",
thumbnail: info.user.thumbnail, thumbnail: info.user.thumbnail || fallbackImage,
type: "playlist", type: "playlist",
source: "soundcloud-custom", source: "soundcloud-custom",
author: info.user.name, author: info.user.name,
@ -140,7 +141,7 @@ module.exports = {
const track = { const track = {
title: info.video_details.title, title: info.video_details.title,
duration: info.video_details.durationInSec * 1000, duration: info.video_details.durationInSec * 1000,
thumbnail: info.video_details.thumbnails[0].url, thumbnail: info.video_details.thumbnails[0].url || fallbackImage,
async engine() { async engine() {
return (await playdl.stream(`https://music.youtube.com/watch?v=${info.video_details.id}`, { discordPlayerCompatibility: true })).stream; return (await playdl.stream(`https://music.youtube.com/watch?v=${info.video_details.id}`, { discordPlayerCompatibility: true })).stream;
}, },
@ -148,9 +149,8 @@ module.exports = {
author: info.video_details.channel.name, author: info.video_details.channel.name,
description: "", description: "",
url: `https://music.youtube.com/watch?v=${info.video_details.id}`, url: `https://music.youtube.com/watch?v=${info.video_details.id}`,
related_videos: info.related_videos,
raw: info, raw: info,
source: "youtube-music-custom" source: "youtube"
}; };
return resolve({ playlist: null, info: [track] }); return resolve({ playlist: null, info: [track] });
@ -162,7 +162,7 @@ module.exports = {
const track = { const track = {
title: info.video_details.title, title: info.video_details.title,
duration: info.video_details.durationInSec * 1000, duration: info.video_details.durationInSec * 1000,
thumbnail: info.video_details.thumbnails[0].url, thumbnail: info.video_details.thumbnails[0].url || fallbackImage,
async engine() { async engine() {
return (await playdl.stream(info.video_details.url, { discordPlayerCompatibility: true })).stream; return (await playdl.stream(info.video_details.url, { discordPlayerCompatibility: true })).stream;
}, },
@ -170,9 +170,8 @@ module.exports = {
author: info.video_details.channel.name, author: info.video_details.channel.name,
description: "", description: "",
url: info.video_details.url, url: info.video_details.url,
related_videos: info.related_videos,
raw: info, raw: info,
source: "youtube-custom" source: "youtube"
}; };
return resolve({ playlist: null, info: [track] }); return resolve({ playlist: null, info: [track] });
} else if (playdl.yt_validate(query) === "playlist") { } else if (playdl.yt_validate(query) === "playlist") {
@ -183,7 +182,7 @@ module.exports = {
return { return {
title: track.title, title: track.title,
duration: track.durationInSec * 1000, duration: track.durationInSec * 1000,
thumbnail: track.thumbnails[0].url, thumbnail: track.thumbnails[0].url || fallbackImage,
async engine() { async engine() {
return (await playdl.stream(`https://music.youtube.com/watch?v=${track.id}`, { discordPlayerCompatibility: true })).stream; return (await playdl.stream(`https://music.youtube.com/watch?v=${track.id}`, { discordPlayerCompatibility: true })).stream;
}, },
@ -192,18 +191,18 @@ module.exports = {
description: "", description: "",
url: track.url, url: track.url,
raw: info, raw: info,
source: "youtube-music-playlist-custom" source: "youtube"
}; };
}); });
const playlist = { const playlist = {
title: info.title, title: info.title,
description: "", description: "",
thumbnail: info.thumbnail ? info.thumbnail.url : null, thumbnail: info.thumbnail ? info.thumbnail.url : fallbackImage,
type: "playlist", type: "playlist",
author: info.channel.name, author: info.channel.name,
id: info.id, id: info.id,
url: info.url, url: info.url,
source: "youtube-music-playlist-custom", source: "youtube",
rawPlaylist: info rawPlaylist: info
}; };
return resolve({ playlist: playlist, info: tracks }); return resolve({ playlist: playlist, info: tracks });
@ -215,7 +214,7 @@ module.exports = {
return { return {
title: track.title, title: track.title,
duration: track.durationInSec * 1000, duration: track.durationInSec * 1000,
thumbnail: track.thumbnails ? track.thumbnails[0] ? track.thumbnails[0].url : null : null, thumbnail: track.thumbnails[0].url || fallbackImage,
async engine() { async engine() {
return (await playdl.stream(track.url, { discordPlayerCompatibility: true })).stream; return (await playdl.stream(track.url, { discordPlayerCompatibility: true })).stream;
}, },
@ -224,7 +223,7 @@ module.exports = {
description: "", description: "",
url: track.url, url: track.url,
raw: info, raw: info,
source: "youtube-custom" source: "youtube"
}; };
}); });
const playlist = { const playlist = {
@ -232,7 +231,7 @@ module.exports = {
description: "", description: "",
thumbnail: info.thumbnail ? info.thumbnail.url : null, thumbnail: info.thumbnail ? info.thumbnail.url : null,
type: "playlist", type: "playlist",
source: "youtube-custom", source: "youtube",
author: info.channel.name, author: info.channel.name,
id: info.id, id: info.id,
url: info.url, url: info.url,
@ -242,27 +241,27 @@ module.exports = {
} }
// search on youtube // search on youtube
const search = await playdl.search(query, { limit: 1 }); const search = await playdl.search(query, { limit: 10 });
if (search) { if (search) {
const found = search[0]; const found = search.map(track => {
const track = { return {
title: found.title, title: track.title,
duration: found.durationInSec * 1000, duration: track.durationInSec * 1000,
thumbnail: found.thumbnails[0].url, thumbnail: track.thumbnails[0].url || fallbackImage,
async engine() { async engine() {
return (await playdl.stream(found.url, { discordPlayerCompatibility: true })).stream; return (await playdl.stream(track.url, { discordPlayerCompatibility: true })).stream;
}, },
views: found.views, views: track.views,
author: found.channel.name, author: track.channel.name,
description: "", description: "search",
url: found.url, url: track.url,
related_videos: found.related_videos, raw: track,
raw: found, source: "youtube"
source: "youtube-custom" };
}; });
return resolve({ playlist: null, info: [track] }); return resolve({ playlist: null, info: found });
} }
return resolve({ playlist: null, info: null }); return resolve({ playlist: null, info: null });

View file

@ -42,6 +42,7 @@
"REP": "Очки репутации", "REP": "Очки репутации",
"XP": "Опыт", "XP": "Опыт",
"VICTORY": "Победа", "VICTORY": "Победа",
"VIEWS": "Просмотры",
"DEFEAT": "Поражение", "DEFEAT": "Поражение",
"MODERATOR": "Модератор", "MODERATOR": "Модератор",
"DURATION": "Длительность", "DURATION": "Длительность",

View file

@ -5,14 +5,14 @@
"QUERY": "Название / Прямая ссылка / Ссылка на YouTube или SoundCloud", "QUERY": "Название / Прямая ссылка / Ссылка на YouTube или SoundCloud",
"NO_VOICE_CHANNEL": "Вы должны находиться в голосовом канале!", "NO_VOICE_CHANNEL": "Вы должны находиться в голосовом канале!",
"VOICE_CHANNEL_CONNECT": "Я не могу присоедениться к вашему голосовому каналу!", "VOICE_CHANNEL_CONNECT": "Я не могу присоедениться к вашему голосовому каналу!",
"RESULTS_FOOTER": "Укажите число от 1 до 10 (без префикса).", "SEARCH_RESULTS": "Я нашёл данные видео на просторах Youtube'а! Выберите что-то одно с помощью кнопок ниже.",
"NO_RESULT": "По запросу `{{query}}` ничего не найдено!", "RESULTS_TITLE": "Результаты поиска по \"{{query}}\"",
"NO_RESULT": "Произошла неизвестная ошибка при поиске `{{query}}`! Скорее всего это видео имеет ограничение по возрасту.",
"NOW_PLAYING": "Сейчас играет **{{songName}}**", "NOW_PLAYING": "Сейчас играет **{{songName}}**",
"NOT_PLAYING": "На сервере сейчас ничего не воспроизводится", "NOT_PLAYING": "На сервере сейчас ничего не воспроизводится",
"QUEUE_ENDED": "Очередь окончена", "QUEUE_ENDED": "Очередь окончена",
"ADDED_QUEUE": "**{{songName}}** добавлен в очередь!", "ADDED_QUEUE": "**{{songName}}** добавлен в очередь",
"STOP_DISCONNECTED": "Воспроизведение окончено, т.к. я вышел из голосового канала.", "STOP_DISCONNECTED": "Воспроизведение окончено, т.к. я вышел из голосового канала.",
"STOP_EMPTY": "Воспроизведение окончено, т.к. все вышли из голосового канала.", "STOP_EMPTY": "Воспроизведение окончено, т.к. все вышли из голосового канала.",
"RESULTS_CANCEL": "Поиск отменён!", "ERR_OCCURRED": "Произошла ошибка...\n`{{error}}`"
"ERR_OCCURRED": "Произошла ошибка, пропускаю...\n`{{error}}`"
} }

View file

@ -5,6 +5,7 @@
"QUEUE": "Очередь", "QUEUE": "Очередь",
"PAGE": "Страница **{{current}}**/**{{length}}**", "PAGE": "Страница **{{current}}**/**{{length}}**",
"NO_QUEUE": "Пусто", "NO_QUEUE": "Пусто",
"DURATION": "Длительность очереди",
"ADDED": "Добавил", "ADDED": "Добавил",
"NEXT_PAGE": "След. страница", "NEXT_PAGE": "След. страница",
"PREV_PAGE": "Пред. страница", "PREV_PAGE": "Пред. страница",

3229
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{ {
"name": "jaba", "name": "jaba",
"version": "4.1.1", "version": "4.1.2",
"description": "My Discord Bot", "description": "My Discord Bot",
"main": "index.js", "main": "index.js",
"private": true, "private": true,
@ -24,7 +24,7 @@
"cron": "^1.7.2", "cron": "^1.7.2",
"discord-api-types": "^0.37.5", "discord-api-types": "^0.37.5",
"discord-giveaways": "^6.0.1", "discord-giveaways": "^6.0.1",
"discord-player": "^5.3.1", "discord-player": "github:JonnyBro/discord-player",
"discord.js": "^14.3.0", "discord.js": "^14.3.0",
"ejs": "^3.1.3", "ejs": "^3.1.3",
"express": "^4.17.1", "express": "^4.17.1",
@ -40,8 +40,7 @@
"mongoose": "^5.13.14", "mongoose": "^5.13.14",
"ms": "^2.1.3", "ms": "^2.1.3",
"play-dl": "^1.9.5", "play-dl": "^1.9.5",
"prism-media": "^1.3.4", "prism-media": "^1.3.4"
"spotify-url-info": "^3.1.2"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^7.5.0" "eslint": "^7.5.0"