26 Commits

Author SHA1 Message Date
Patryk Koreń
8be88fd4c7 ci11
Some checks failed
Build and Push Docker Image / build-image (push) Has been cancelled
2026-01-07 22:12:45 +01:00
Patryk Koreń
ab021d1512 ci11
Some checks failed
Build and Push Docker Image / build-image (push) Has been cancelled
2026-01-07 22:09:48 +01:00
Patryk Koreń
4e944da7e1 ci11
Some checks failed
Build and Push Docker Image / build-image (push) Has been cancelled
2026-01-07 21:59:40 +01:00
Patryk Koreń
41d040167b ci11
Some checks failed
Build and Push Docker Image / build-image (push) Has been cancelled
2026-01-07 21:58:35 +01:00
Patryk Koreń
cbe9ca8691 ci11
Some checks failed
Build and Push Docker Image / build-image (push) Has been cancelled
2026-01-07 21:56:55 +01:00
Patryk Koreń
79841b30c9 ci11
Some checks failed
Build and Push Docker Image / build-image (push) Failing after 32s
2026-01-07 21:50:19 +01:00
Patryk Koreń
3d7f6eeddf ci11
Some checks failed
Build and Push Docker Image / build-image (push) Has been cancelled
2026-01-07 21:48:10 +01:00
Patryk Koreń
ff433ebd58 ci11
Some checks failed
Build and Push Docker Image / build-image (push) Has been cancelled
2026-01-07 21:46:48 +01:00
Patryk Koreń
a116302a10 ci11
Some checks failed
Build and Push Docker Image / build-image (push) Has been cancelled
2026-01-07 21:44:40 +01:00
Patryk Koreń
459174e3c3 ci11
Some checks failed
Build and Push Docker Image / build-image (push) Has been cancelled
2026-01-07 21:41:38 +01:00
Patryk Koreń
78421b9a93 ci11
Some checks failed
Build and Push Docker Image / docker (push) Has been cancelled
2026-01-07 21:33:31 +01:00
Patryk Koreń
b206c734b0 ci11
Some checks failed
Build and Push Docker Image / docker (push) Has been cancelled
2026-01-07 21:31:11 +01:00
Patryk Koreń
9102a9b15a ci11
Some checks failed
Build and Push Docker Image / docker (push) Has been cancelled
2026-01-07 21:29:57 +01:00
Patryk Koreń
3ff9759e1e ci11
Some checks failed
Build and Push Docker Image / docker (push) Has been cancelled
2026-01-07 21:26:36 +01:00
Patryk Koreń
dd2571c09d ci11
Some checks failed
Build and Push Docker Image / docker (push) Has been cancelled
2026-01-07 20:39:37 +01:00
Patryk Koreń
30d0485da3 ci11
Some checks failed
Build and Push Docker Image / docker (push) Has been cancelled
2026-01-07 20:32:10 +01:00
Patryk Koreń
3232abab68 ci10
Some checks failed
Build and Push Docker Image / docker (push) Failing after 39s
2026-01-07 20:29:21 +01:00
Patryk Koreń
6add9f7cad ci9
Some checks failed
Build and Push Docker Image / docker (push) Failing after 57s
2026-01-07 20:25:20 +01:00
Patryk Koreń
e8ca15df06 ci8
Some checks failed
Build and Push Docker Image / docker (push) Failing after 51s
2026-01-07 20:20:55 +01:00
Patryk Koreń
1061864cae ci7
Some checks failed
Build and Push Docker Image / docker (push) Failing after 41s
2026-01-07 20:15:47 +01:00
Patryk Koreń
26449dd5c9 ci6
Some checks failed
Build and Push Docker Image / docker (push) Failing after 37s
2026-01-07 20:14:04 +01:00
Patryk Koreń
72e822950b ci5
Some checks failed
Build and Push Docker Image / docker (push) Failing after 40s
2026-01-07 20:12:32 +01:00
Patryk Koreń
d3396a4c9b ci4
Some checks failed
Build and Push Docker Image / docker (push) Failing after 38s
2026-01-07 20:05:36 +01:00
Patryk Koreń
1269b35dbd ci3
Some checks failed
Build and Push Docker Image / docker (push) Failing after 41s
2026-01-07 20:04:05 +01:00
Patryk Koreń
0163625507 ci2 2026-01-07 20:03:12 +01:00
Patryk Koreń
b28c1e6795 ci
Some checks failed
Build and Push Docker Image / docker (push) Failing after 1m50s
2026-01-07 19:44:39 +01:00
15 changed files with 86 additions and 217 deletions

View File

@@ -9,7 +9,7 @@ jobs:
build-image: build-image:
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: container:
image: docker:rc-dind image: docker:latest
steps: steps:
- name: Install dedps - name: Install dedps
@@ -21,8 +21,9 @@ jobs:
- name: Build container image - name: Build container image
env: env:
REGISTRY: https://gitea.papryk.com
IMAGE_NAME: papryk/dj-spangebob IMAGE_NAME: papryk/dj-spangebob
TAG: ${{ github.ref_name }} TAG: ${{ gitea.ref_name }}
run: | run: |
docker build -t "$IMAGE_NAME:$TAG" . docker build -t "$IMAGE_NAME:$TAG" .
@@ -32,13 +33,13 @@ jobs:
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
run: | run: |
echo "$REGISTRY_PASSWORD" | docker "$REGISTRY" -u "$REGISTRY_USERNAME" --password-stdin echo "$REGISTRY_PASSWORD" | podman login "$REGISTRY" -u "$REGISTRY_USERNAME" --password-stdin
- name: Build and push Docker image - name: Build and push Docker image
env: env:
REGISTRY: https://gitea.papryk.com REGISTRY: https://gitea.papryk.com
IMAGE_NAME: Papryk/dj-spangebob IMAGE_NAME: Papryk/dj-spangebob
TAG: ${{ github.ref_name }} TAG: ${{ gitea.ref_name }}
run: | run: |
docker push "$REGISTRY/$IMAGE_NAME:$TAG" podman push "$REGISTRY/$IMAGE_NAME:$TAG"

View File

@@ -1,9 +1,6 @@
FROM node:22-alpine FROM node:20-alpine
RUN apk add --no-cache wget ffmpeg #yt-dlp RUN apk add --no-cache ffmpeg yt-dlp
RUN wget -P /tmp https://github.com/yt-dlp/yt-dlp/releases/download/2026.03.17/yt-dlp_musllinux
RUN mv /tmp/yt-dlp_musllinux /usr/bin/yt-dlp
RUN chmod 777 /usr/bin/yt-dlp
WORKDIR /app WORKDIR /app

View File

@@ -1 +0,0 @@
{"timestamp":1775508648856,"url":"https://www.youtube.com/watch?v=xTemcPZw8Eo","user":"kapitan.papryk"}

View File

@@ -1 +0,0 @@
{"timestamp":1772133865649,"url":"https://www.youtube.com/watch?v=TWiOB4lUZrQ","user":"kapitan.papryk"}

View File

@@ -1,36 +0,0 @@
[
{
"interaction": {
"type": 2,
"id": "1466473802148872486",
"applicationId": "887789346277691402",
"channelId": "470712099753164811",
"guildId": "343827205878710273",
"user": "264739894641950720",
"member": "264739894641950720",
"version": 1,
"appPermissions": "2230881414020816",
"memberPermissions": "2230883322429171",
"locale": "pl",
"guildLocale": "en-US",
"entitlements": [],
"authorizingIntegrationOwners": {
"0": "343827205878710273"
},
"context": 0,
"attachmentSizeLimit": 10485760,
"commandId": "1452614990078021710",
"commandName": "play",
"commandType": 1,
"commandGuildId": null,
"deferred": true,
"replied": true,
"ephemeral": false,
"webhook": {
"id": "887789346277691402"
},
"options": {}
},
"url": "https://soundcloud.com/musicbymoonlght/4th-of-july-rock-x-house-mix-by-moonlght-vol-2?si=93777764ee5c404db6f3fb3c6dc347d8&utm_source=clipboard&utm_medium=text&utm_campaign=social_sharing"
}
]

View File

@@ -32,10 +32,10 @@ async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
} }
await interaction.editReply(msg_downloading(url)); await interaction.editReply(msg_downloading(url));
forceRequestSong(url, { user: interaction.user.username }).then(() => { await forceRequestSong(interaction, url)
// const msg = getPlayMsg(url)
interaction.editReply(msg_play()); const msg = getPlayMsg(url)
}) 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

@@ -7,7 +7,6 @@ import queue from "./queue"
import resume from "./resume" import resume from "./resume"
import skip from "./skip" import skip from "./skip"
import stop from "./stop" import stop from "./stop"
import loop from "./loop"
export const commands: { [key: string]: Command } = { export const commands: { [key: string]: Command } = {
ping, ping,
@@ -19,6 +18,5 @@ export const commands: { [key: string]: Command } = {
stop, stop,
pause, pause,
skip, skip,
loop,
} }

View File

@@ -1,34 +0,0 @@
import { CacheType, ChatInputCommandInteraction, SlashCommandBuilder } from 'discord.js';
import { toggleLoop } from '../playback';
import { formatFilePath } from '../util/downloader'
const name = "loop"
function register() {
return new SlashCommandBuilder()
.setName(name)
.setDescription('loop current song')
}
async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
try {
await interaction.deferReply()
const audio = toggleLoop()
if (audio) {
await interaction.editReply(`looped ${formatFilePath(audio.url)}`);
}
else {
await interaction.editReply(`Loop turned off`);
}
} catch (error) {
console.error(error);
await interaction.reply('Coś poszło nie tak :/');
}
}
export default {
name,
register,
execute
}

View File

@@ -36,9 +36,10 @@ async function execute(interaction: ChatInputCommandInteraction<CacheType>) {
} }
await interaction.editReply(msg_downloading(url)); await interaction.editReply(msg_downloading(url));
requestSong(url, { user: interaction.user.username }).then(() => { await requestSong(interaction, url)
interaction.editReply(msg_play());
}) const msg = getPlayMsg(url)
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 :/');

10
src/global.d.ts vendored
View File

@@ -10,13 +10,7 @@ type AudioFile = {
} }
type Queue = { type Queue = {
songList: AudioFile[] songList: AudioFile[],
current: AudioFile | null current: AudioFile | null,
loop: AudioFile | null
}
type HistoryObject = {
user?: number | string,
url?: string,
} }

View File

@@ -9,7 +9,6 @@ import { updatePlayer } from './playback';
import SpotifyWebApi from 'spotify-web-api-node'; import SpotifyWebApi from 'spotify-web-api-node';
export const DATA_DIR = "./data"; export const DATA_DIR = "./data";
export const HISTORY_DIR_PATH = process.env.HISTORY_DIR_PATH ?? "./history";
// AUDIO // AUDIO
export const player = createAudioPlayer(); export const player = createAudioPlayer();

View File

@@ -3,39 +3,29 @@ import { player } from "./main";
import { CacheType, ChatInputCommandInteraction } from "discord.js"; import { CacheType, ChatInputCommandInteraction } from "discord.js";
import { getAudioFile } from "./util/downloader"; import { getAudioFile } from "./util/downloader";
import { playSong } from "./util/helpers"; import { playSong } from "./util/helpers";
import { add_to_history } from "./util/history";
const queue: Queue = { const queue: Queue = {
songList: [], songList: [],
current: null, current: null
loop: null,
}
export function toggleLoop(): AudioFile | null {
if (queue.loop) queue.loop = null
else queue.loop = queue.current
return queue.loop
} }
export async function requestSong( export async function requestSong(
url: string, interaction: ChatInputCommandInteraction<CacheType>,
data: Partial<HistoryObject> url: string) {
) {
const path = await getAudioFile(url) const path = await getAudioFile(url)
queue.songList.push({ path, url }) queue.songList.push({ path, url })
add_to_history({ url, user: data.user }) updatePlayer()
await updatePlayer()
} }
export async function forceRequestSong( export async function forceRequestSong(
url: string, interaction: ChatInputCommandInteraction<CacheType>,
data: Partial<HistoryObject> url: string) {
) {
const path = await getAudioFile(url) const path = await getAudioFile(url)
const audio = { path, url } const audio = { path, url }
queue.songList.push(audio) queue.songList.push(audio)
add_to_history({ url, user: data.user })
queue.current = audio queue.current = audio
playSong(player, path); playSong(player, path);
} }
@@ -43,7 +33,7 @@ export async function forceRequestSong(
export async function updatePlayer() { export async function updatePlayer() {
if (player.state.status === AudioPlayerStatus.Idle) { if (player.state.status === AudioPlayerStatus.Idle) {
const nextSong = queue.loop ?? queue.songList.shift() const nextSong = queue.songList.shift()
if (!nextSong) { if (!nextSong) {
queue.current = null queue.current = null
return return

View File

@@ -18,13 +18,8 @@ export async function getAudioFile(url: string): Promise<string> {
return path return path
} }
function isYTLink(url: string) {
return url.startsWith("https://youtube") ||
url.startsWith("https://youtu.be");
}
export async function extractId(url: string): Promise<string> { export async function extractId(url: string): Promise<string> {
// if (!isYTLink(url)) { if (url.startsWith("https://soundcloud")) { // soundcloud
const ytDlpBin = process.env.YT_DLP_BIN_PATH! ?? "yt-dlp"; const ytDlpBin = process.env.YT_DLP_BIN_PATH! ?? "yt-dlp";
return await new Promise<string>((resolve, reject) => { return await new Promise<string>((resolve, reject) => {
const p = spawn(ytDlpBin, [ const p = spawn(ytDlpBin, [
@@ -38,12 +33,12 @@ export async function extractId(url: string): Promise<string> {
p.on("close", code => code === 0 ? resolve(out.trim()) : reject(new Error("yt-dlp extract id failed"))); p.on("close", code => code === 0 ? resolve(out.trim()) : reject(new Error("yt-dlp extract id failed")));
}); });
// } else { } else {
// const idMatch = /[?&]v=([a-zA-Z0-9_-]{11})/.exec(url); const idMatch = /[?&]v=([a-zA-Z0-9_-]{11})/.exec(url);
// if (!idMatch) throw new Error("Cannot extract video ID"); if (!idMatch) throw new Error("Cannot extract video ID");
// const id = idMatch[1]; const id = idMatch[1];
// return id return id
// } }
} }
export async function downloadAudio(url: string): Promise<void> { export async function downloadAudio(url: string): Promise<void> {

View File

@@ -61,7 +61,6 @@ export async function connectToChannel(channel: VoiceBasedChannel) {
} }
export async function playSong(player: AudioPlayer, songUrl: string) { export async function playSong(player: AudioPlayer, songUrl: string) {
try {
/** /**
* Here we are creating an audio resource using a sample song freely available online * Here we are creating an audio resource using a sample song freely available online
* (see https://www.soundhelix.com/audio-examples) * (see https://www.soundhelix.com/audio-examples)
@@ -85,7 +84,4 @@ export async function playSong(player: AudioPlayer, songUrl: string) {
* state within 5 seconds, otherwise it will reject with an error. * state within 5 seconds, otherwise it will reject with an error.
*/ */
return entersState(player, AudioPlayerStatus.Playing, 5_000); return entersState(player, AudioPlayerStatus.Playing, 5_000);
} catch (e) {
console.error(e)
}
} }

View File

@@ -1,30 +0,0 @@
import path from "node:path";
import fs from "node:fs";
import { HISTORY_DIR_PATH } from "../main";
export async function add_to_history(data: HistoryObject) {
try {
const today = new Date();
const day = String(today.getDate()).padStart(2, '0');
const month = String(today.getMonth() + 1).padStart(2, '0');
const year = today.getFullYear();
const file_name = `${day}-${month}-${year}.json`;
const file_path = path.join(HISTORY_DIR_PATH, file_name)
if (!fs.existsSync(HISTORY_DIR_PATH)) {
fs.mkdirSync(HISTORY_DIR_PATH);
}
let history = {
timestamp: today.getTime(),
url: data.url,
user: data.user,
};
fs.writeFileSync(file_path, JSON.stringify(history));
} catch (error) {
console.log(error)
}
}