added history
This commit is contained in:
@@ -22,7 +22,7 @@ jobs:
|
|||||||
- name: Build container image
|
- name: Build container image
|
||||||
env:
|
env:
|
||||||
IMAGE_NAME: papryk/dj-spangebob
|
IMAGE_NAME: papryk/dj-spangebob
|
||||||
TAG: ${{ gitea.ref_name }}
|
TAG: ${{ github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
docker build -t "$IMAGE_NAME:$TAG" .
|
docker build -t "$IMAGE_NAME:$TAG" .
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
REGISTRY: https://gitea.papryk.com
|
REGISTRY: https://gitea.papryk.com
|
||||||
IMAGE_NAME: Papryk/dj-spangebob
|
IMAGE_NAME: Papryk/dj-spangebob
|
||||||
TAG: ${{ gitea.ref_name }}
|
TAG: ${{ github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
docker push "$REGISTRY/$IMAGE_NAME:$TAG"
|
docker push "$REGISTRY/$IMAGE_NAME:$TAG"
|
||||||
|
|
||||||
|
|||||||
5
src/global.d.ts
vendored
5
src/global.d.ts
vendored
@@ -14,3 +14,8 @@ type Queue = {
|
|||||||
current: AudioFile | null,
|
current: AudioFile | null,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HistoryObject = {
|
||||||
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
|
url: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ 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();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ 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: [],
|
||||||
@@ -11,12 +12,14 @@ const queue: Queue = {
|
|||||||
|
|
||||||
export async function requestSong(
|
export async function requestSong(
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
url: string) {
|
url: string,
|
||||||
|
user?: any
|
||||||
|
) {
|
||||||
|
|
||||||
const path = await getAudioFile(url)
|
const path = await getAudioFile(url)
|
||||||
queue.songList.push({ path, url })
|
queue.songList.push({ path, url })
|
||||||
|
add_to_history({ interaction, url })
|
||||||
updatePlayer()
|
updatePlayer()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function forceRequestSong(
|
export async function forceRequestSong(
|
||||||
|
|||||||
31
src/util/history.ts
Normal file
31
src/util/history.ts
Normal file
@@ -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));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user