format wiadomości

This commit is contained in:
Patryk Koreń
2026-01-03 20:58:23 +01:00
parent 765157f754
commit 28b6546c25
10 changed files with 118 additions and 34 deletions

View File

@@ -1,7 +1,7 @@
import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
import { connectToChannelByInteraction } from '../util/helpers'; import { connectToChannelByInteraction } from '../util/helpers';
import { forceRequestSong } from '../playback'; import { forceRequestSong } from '../playback';
import { getPlayMsg } from '../messages'; import { getPlayMsg, msg_downloading, msg_play, msg_searching } from '../messages';
import { search } from '../util/downloader'; import { search } from '../util/downloader';
const name = "forceplay" const name = "forceplay"
@@ -26,16 +26,16 @@ async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
if (input.startsWith("http")) { if (input.startsWith("http")) {
url = input url = input
} else { } else {
await interaction.editReply(`searching for: ${input}`); await interaction.editReply(msg_searching(input));
url = await search(input) url = await search(input)
console.log(input, url) console.log(input, url)
} }
await interaction.editReply(`downloading: ${url}`); await interaction.editReply(msg_downloading(url));
await forceRequestSong(interaction, url) await forceRequestSong(interaction, url)
const msg = getPlayMsg(url) const msg = getPlayMsg(url)
await interaction.editReply(msg); await interaction.editReply(msg_play());
} catch (error) { } catch (error) {
console.error(error); console.error(error);
await interaction.editReply('Coś poszło nie tak :/'); await interaction.editReply('Coś poszło nie tak :/');

View File

@@ -1,4 +1,5 @@
import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
import { msg_help } from '../messages';
const name = "help" const name = "help"
@@ -9,7 +10,7 @@ function register() {
} }
async function execute(interaction: ChatInputCommandInteraction<CacheType>) { async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
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 { export default {

View File

@@ -1,7 +1,7 @@
import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
import { connectToChannelByInteraction } from '../util/helpers'; import { connectToChannelByInteraction } from '../util/helpers';
import { requestSong } from '../playback'; import { requestSong } from '../playback';
import { getPlayMsg } from '../messages'; import { getPlayMsg, msg_downloading, msg_play, msg_searching } from '../messages';
import { search } from '../util/downloader'; import { search } from '../util/downloader';
const name = "play" const name = "play"
@@ -26,16 +26,16 @@ async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
if (input.startsWith("http")) { if (input.startsWith("http")) {
url = input url = input
} else { } else {
await interaction.editReply(`searching for: ${input}`); await interaction.editReply(msg_searching(input));
url = await search(input) url = await search(input)
console.log(input, url) console.log(input, url)
} }
await interaction.editReply(`downloading: ${url}`); await interaction.editReply(msg_downloading(url));
await requestSong(interaction, url) await requestSong(interaction, url)
const msg = getPlayMsg(url) const msg = getPlayMsg(url)
await interaction.editReply(msg); await interaction.editReply(msg_play());
} catch (error) { } catch (error) {
console.error(error); console.error(error);
await interaction.editReply('Coś poszło nie tak :/'); await interaction.editReply('Coś poszło nie tak :/');

View File

@@ -1,5 +1,5 @@
import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
import { getQueue } from '../playback'; import { msg_play } from '../messages';
const name = "queue" const name = "queue"
@@ -10,11 +10,8 @@ function register() {
} }
async function execute(interaction: ChatInputCommandInteraction<CacheType>) { async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
console.log(interaction.member) await interaction.deferReply()
const queue = getQueue() await interaction.editReply(msg_play());
await interaction.reply(`Current: ${queue.current}
Queue:
${queue.songList.join('\n ')}`);
} }
export default { export default {

View File

@@ -1,5 +1,6 @@
import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js'; import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
import { skip_song } from '../playback'; import { skip_song } from '../playback';
import { msg_skipped } from '../messages';
const name = "skip" const name = "skip"
@@ -12,8 +13,8 @@ function register() {
async function execute(interaction: ChatInputCommandInteraction<CacheType>) { async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
try { try {
await interaction.deferReply() await interaction.deferReply()
skip_song() const skipped = skip_song()
await interaction.editReply('skipped'); await interaction.editReply(msg_skipped(skipped));
} catch (error) { } catch (error) {
console.error(error); console.error(error);
await interaction.reply('Coś poszło nie tak :/'); await interaction.reply('Coś poszło nie tak :/');

12
src/global.d.ts vendored
View File

@@ -4,7 +4,13 @@ type Command = {
execute: (interaction: ChatInputCommandInteraction<CacheType>) => Promise<void>, execute: (interaction: ChatInputCommandInteraction<CacheType>) => Promise<void>,
} }
type Queue = { type AudioFile = {
songList: string[], url: string
current: string | null, path: string
} }
type Queue = {
songList: AudioFile[],
current: AudioFile | null,
}

View File

@@ -1,17 +1,83 @@
import { EmbedBuilder, InteractionEditReplyOptions, InteractionReplyOptions } from "discord.js";
import { getQueue } from "./playback"; 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 { export function getPlayMsg(url: string): string {
return ` return `TODO-3`
Request: ${url}
https://gitea.papryk.com/Papryk/dj-spangebob pull requesty milewidziane XD\n` + getQueueMsg()
} }
export function getCurrentSongMsg(): string { export function getCurrentSongMsg(): string {
return 'TODO-1' return 'TODO-1'
} }
export function getQueueMsg(): string { export function getQueueMsg(): string {
const queue = getQueue() return `TODO-2`
return `Current: ${queue.current?.replace("/app/data/", "").replace(/\[.*\].opus/,"").trim()}
Queue: }
${queue.songList.join('\n ').replace(/\/app\/data\//g, "").replace(/\[.*\].opus/g,"").trim()}`
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"
} }

View File

@@ -14,7 +14,7 @@ export async function requestSong(
url: string) { url: string) {
const path = await getAudioFile(url) const path = await getAudioFile(url)
queue.songList.push(path) queue.songList.push({ path, url })
updatePlayer() updatePlayer()
} }
@@ -24,8 +24,9 @@ export async function forceRequestSong(
url: string) { url: string) {
const path = await getAudioFile(url) const path = await getAudioFile(url)
queue.songList.push(path) const audio = { path, url }
queue.current = path queue.songList.push(audio)
queue.current = audio
playSong(player, path); playSong(player, path);
} }
@@ -38,21 +39,24 @@ export async function updatePlayer() {
return return
}; };
queue.current = nextSong; 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) { if (player.state.status === AudioPlayerStatus.Playing) {
const skipped = queue.current
const nextSong = queue.songList.shift() const nextSong = queue.songList.shift()
if (!nextSong) { if (!nextSong) {
queue.current = null queue.current = null
player.stop() player.stop()
return return null
}; };
queue.current = nextSong; queue.current = nextSong;
playSong(player, nextSong); playSong(player, nextSong.path);
return skipped
} }
return null
} }
export function pause_playback(player: AudioPlayer) { export function pause_playback(player: AudioPlayer) {

3
src/theme.ts Normal file
View File

@@ -0,0 +1,3 @@
export const PRIMARY_COLOR = 0x57F287;

View File

@@ -87,3 +87,9 @@ export async function search(input: string) {
}); });
}); });
} }
export function formatFilePath(path: string): string {
return path.replace("/app/data/", "")
.replace(/\[.*\].opus/, "")
.trim();
}