diff --git a/src/commands/forceplay.ts b/src/commands/forceplay.ts index fe1aaaf..041db1b 100644 --- a/src/commands/forceplay.ts +++ b/src/commands/forceplay.ts @@ -1,7 +1,7 @@ import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import { connectToChannelByInteraction } from '../util/helpers'; import { forceRequestSong } from '../playback'; -import { getPlayMsg } from '../messages'; +import { getPlayMsg, msg_downloading, msg_play, msg_searching } from '../messages'; import { search } from '../util/downloader'; const name = "forceplay" @@ -26,16 +26,16 @@ async function execute(interaction: ChatInputCommandInteraction) { if (input.startsWith("http")) { url = input } else { - await interaction.editReply(`searching for: ${input}`); + await interaction.editReply(msg_searching(input)); url = await search(input) console.log(input, url) } - await interaction.editReply(`downloading: ${url}`); + await interaction.editReply(msg_downloading(url)); await forceRequestSong(interaction, url) const msg = getPlayMsg(url) - await interaction.editReply(msg); + await interaction.editReply(msg_play()); } catch (error) { console.error(error); await interaction.editReply('Coś poszło nie tak :/'); diff --git a/src/commands/help.ts b/src/commands/help.ts index 473e2af..17c33d0 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -1,4 +1,5 @@ import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; +import { msg_help } from '../messages'; const name = "help" @@ -9,7 +10,7 @@ function register() { } async function execute(interaction: ChatInputCommandInteraction) { - await interaction.reply('Jak ci się kurwa nie podoba to tutaj proszę o pull requesty https://gitea.papryk.com/Papryk/dj-spangebob'); + await interaction.reply(msg_help()); } export default { diff --git a/src/commands/play.ts b/src/commands/play.ts index d47257f..fab1c33 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -1,7 +1,7 @@ import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import { connectToChannelByInteraction } from '../util/helpers'; import { requestSong } from '../playback'; -import { getPlayMsg } from '../messages'; +import { getPlayMsg, msg_downloading, msg_play, msg_searching } from '../messages'; import { search } from '../util/downloader'; const name = "play" @@ -26,16 +26,16 @@ async function execute(interaction: ChatInputCommandInteraction) { if (input.startsWith("http")) { url = input } else { - await interaction.editReply(`searching for: ${input}`); + await interaction.editReply(msg_searching(input)); url = await search(input) console.log(input, url) } - await interaction.editReply(`downloading: ${url}`); + await interaction.editReply(msg_downloading(url)); await requestSong(interaction, url) const msg = getPlayMsg(url) - await interaction.editReply(msg); + await interaction.editReply(msg_play()); } catch (error) { console.error(error); await interaction.editReply('Coś poszło nie tak :/'); diff --git a/src/commands/queue.ts b/src/commands/queue.ts index fe206d6..02b229c 100644 --- a/src/commands/queue.ts +++ b/src/commands/queue.ts @@ -1,5 +1,5 @@ import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; -import { getQueue } from '../playback'; +import { msg_play } from '../messages'; const name = "queue" @@ -10,11 +10,8 @@ function register() { } async function execute(interaction: ChatInputCommandInteraction) { - console.log(interaction.member) - const queue = getQueue() - await interaction.reply(`Current: ${queue.current} -Queue: - ${queue.songList.join('\n ')}`); + await interaction.deferReply() + await interaction.editReply(msg_play()); } export default { diff --git a/src/commands/skip.ts b/src/commands/skip.ts index a7db12b..352b55c 100644 --- a/src/commands/skip.ts +++ b/src/commands/skip.ts @@ -1,5 +1,6 @@ import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import { skip_song } from '../playback'; +import { msg_skipped } from '../messages'; const name = "skip" @@ -12,8 +13,8 @@ function register() { async function execute(interaction: ChatInputCommandInteraction) { try { await interaction.deferReply() - skip_song() - await interaction.editReply('skipped'); + const skipped = skip_song() + await interaction.editReply(msg_skipped(skipped)); } catch (error) { console.error(error); await interaction.reply('Coś poszło nie tak :/'); diff --git a/src/global.d.ts b/src/global.d.ts index e4ee251..e5aaabe 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -4,7 +4,13 @@ type Command = { execute: (interaction: ChatInputCommandInteraction) => Promise, } -type Queue = { - songList: string[], - current: string | null, +type AudioFile = { + url: string + path: string } + +type Queue = { + songList: AudioFile[], + current: AudioFile | null, +} + diff --git a/src/messages.ts b/src/messages.ts index c0766e7..522f78f 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -1,17 +1,83 @@ +import { EmbedBuilder, InteractionEditReplyOptions, InteractionReplyOptions } from "discord.js"; import { getQueue } from "./playback"; +import { PRIMARY_COLOR } from "./theme"; +import { formatFilePath } from "./util/downloader"; + +const REPO_URL = "https://gitea.papryk.com/Papryk/dj-spangebob" export function getPlayMsg(url: string): string { - return ` - Request: ${url} - https://gitea.papryk.com/Papryk/dj-spangebob pull requesty milewidziane XD\n` + getQueueMsg() + return `TODO-3` } export function getCurrentSongMsg(): string { return 'TODO-1' } export function getQueueMsg(): string { - const queue = getQueue() - return `Current: ${queue.current?.replace("/app/data/", "").replace(/\[.*\].opus/,"").trim()} -Queue: - ${queue.songList.join('\n ').replace(/\/app\/data\//g, "").replace(/\[.*\].opus/g,"").trim()}` + return `TODO-2` + +} + +export function msg_searching(input: string): InteractionEditReplyOptions { + return { + embeds: [ + new EmbedBuilder() + .setDescription(`🔎 Searching for: **${input}**`) + .setColor(PRIMARY_COLOR) + ] + } +} + +export function msg_downloading(url: string): InteractionEditReplyOptions { + return { + embeds: [ + new EmbedBuilder() + .setDescription(`⬇️ Downloading: ${url}`) + .setColor(PRIMARY_COLOR) + ] + } +} + + +export function msg_play(): InteractionEditReplyOptions { + const queue = getQueue(); + const current = queue.current ? `[${formatFilePath(queue.current.path)}](${queue.current.url})` : "Nic nie gra"; + const queueSongs = queue.songList + .map(audio => `[${formatFilePath(audio.path)}(${audio.url})`) + .slice(0, 10) + .map((queueItem, index) => `${index + 1}. ${queueItem}`) + + return { + embeds: [ + new EmbedBuilder() + .setTitle("🎵 DJ-SPANDŹBOB 🎵") + .setColor(PRIMARY_COLOR) + .addFields( + { name: "Na Placku", value: current }, + { name: "Kolejka", value: queueSongs.length ? queueSongs.join("\n") : "Pusta Kolejka" } + ) + .setTimestamp() + ] + } +} + +export function msg_help() { + return { + embeds: [ + new EmbedBuilder() + .setDescription("") + .setTitle("🎵 DJ-SPANDŹBOB 🎵") + .setColor(PRIMARY_COLOR) + .addFields( + { name: "Repo", value: REPO_URL }, + ) + .setTimestamp() + ] + } +} + +export function msg_skipped(song: AudioFile | null) { + if (song) { + return `Skipnięte ${formatFilePath(song.path)}` + } + return "Nic nie gra mordo" } diff --git a/src/playback.ts b/src/playback.ts index 7df85f0..7630b53 100644 --- a/src/playback.ts +++ b/src/playback.ts @@ -14,7 +14,7 @@ export async function requestSong( url: string) { const path = await getAudioFile(url) - queue.songList.push(path) + queue.songList.push({ path, url }) updatePlayer() } @@ -24,8 +24,9 @@ export async function forceRequestSong( url: string) { const path = await getAudioFile(url) - queue.songList.push(path) - queue.current = path + const audio = { path, url } + queue.songList.push(audio) + queue.current = audio playSong(player, path); } @@ -38,21 +39,24 @@ export async function updatePlayer() { return }; queue.current = nextSong; - playSong(player, nextSong); + playSong(player, nextSong.path); } } -export function skip_song() { +export function skip_song(): AudioFile | null { if (player.state.status === AudioPlayerStatus.Playing) { + const skipped = queue.current const nextSong = queue.songList.shift() if (!nextSong) { queue.current = null player.stop() - return + return null }; queue.current = nextSong; - playSong(player, nextSong); + playSong(player, nextSong.path); + return skipped } + return null } export function pause_playback(player: AudioPlayer) { diff --git a/src/theme.ts b/src/theme.ts new file mode 100644 index 0000000..67c522c --- /dev/null +++ b/src/theme.ts @@ -0,0 +1,3 @@ +export const PRIMARY_COLOR = 0x57F287; + + diff --git a/src/util/downloader.ts b/src/util/downloader.ts index b27f432..021363e 100644 --- a/src/util/downloader.ts +++ b/src/util/downloader.ts @@ -87,3 +87,9 @@ export async function search(input: string) { }); }); } + +export function formatFilePath(path: string): string { + return path.replace("/app/data/", "") + .replace(/\[.*\].opus/, "") + .trim(); +}