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 { 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<CacheType>) {
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 :/');

View File

@@ -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<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 {

View File

@@ -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<CacheType>) {
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 :/');

View File

@@ -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<CacheType>) {
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 {

View File

@@ -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<CacheType>) {
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 :/');

12
src/global.d.ts vendored
View File

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

View File

@@ -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) {

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();
}