diff --git a/.gitea/workflows/build_container.yml b/.gitea/workflows/build_container.yml index 70ae4ac..beb128b 100644 --- a/.gitea/workflows/build_container.yml +++ b/.gitea/workflows/build_container.yml @@ -22,7 +22,7 @@ jobs: - name: Build container image env: IMAGE_NAME: papryk/dj-spangebob - TAG: ${{ gitea.ref_name }} + TAG: ${{ github.ref_name }} run: | docker build -t "$IMAGE_NAME:$TAG" . @@ -38,7 +38,7 @@ jobs: env: REGISTRY: https://gitea.papryk.com IMAGE_NAME: Papryk/dj-spangebob - TAG: ${{ gitea.ref_name }} + TAG: ${{ github.ref_name }} run: | docker push "$REGISTRY/$IMAGE_NAME:$TAG" diff --git a/src/global.d.ts b/src/global.d.ts index e5aaabe..b1f8c43 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -14,3 +14,8 @@ type Queue = { current: AudioFile | null, } +type HistoryObject = { + interaction: ChatInputCommandInteraction, + url: string, +} + diff --git a/src/main.ts b/src/main.ts index 23bb578..4f78e28 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,6 +9,7 @@ import { updatePlayer } from './playback'; import SpotifyWebApi from 'spotify-web-api-node'; export const DATA_DIR = "./data"; +export const HISTORY_DIR_PATH = process.env.HISTORY_DIR_PATH ?? "./history"; // AUDIO export const player = createAudioPlayer(); diff --git a/src/playback.ts b/src/playback.ts index 7630b53..b887033 100644 --- a/src/playback.ts +++ b/src/playback.ts @@ -3,6 +3,7 @@ import { player } from "./main"; import { CacheType, ChatInputCommandInteraction } from "discord.js"; import { getAudioFile } from "./util/downloader"; import { playSong } from "./util/helpers"; +import { add_to_history } from "./util/history"; const queue: Queue = { songList: [], @@ -11,12 +12,14 @@ const queue: Queue = { export async function requestSong( interaction: ChatInputCommandInteraction, - url: string) { + url: string, + user?: any +) { const path = await getAudioFile(url) queue.songList.push({ path, url }) + add_to_history({ interaction, url }) updatePlayer() - } export async function forceRequestSong( diff --git a/src/util/history.ts b/src/util/history.ts new file mode 100644 index 0000000..108d199 --- /dev/null +++ b/src/util/history.ts @@ -0,0 +1,31 @@ +import path from "node:path"; +import fs from "node:fs"; +import { HISTORY_DIR_PATH } from "../main"; + +export async function add_to_history(history: HistoryObject) { + 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 data = []; + + try { + const content = fs.readFileSync(file_path, 'utf8'); + data = JSON.parse(content); + } catch (err) { + data = []; + } + + data.push(history) + + fs.writeFileSync(file_path, JSON.stringify(data, null, 2)); +}