대부분 모든기능 제작

하단 player연결, 일시정지, 스킵, 볼륨, 특정시간재생, queue 디자인 변경, queue 변경기능 제작
This commit is contained in:
tkrmagid-desktop
2026-04-10 00:40:40 +09:00
parent 88a5a88c51
commit 374fbdb1ce
18 changed files with 1265 additions and 83 deletions

View File

@@ -1,6 +1,6 @@
import { Guild, Message, TextChannel } from "discord.js";
import { LoadType, Player, Track, TrackEndEvent } from "shoukaku";
import { client, lavalinkManager } from "../index";
import { LoadType, Player, Track, TrackEndEvent, TrackStartEvent } from "shoukaku";
import { client, lavalinkManager, Redis } from "../index";
import { timeFormat } from "../utils/music/Utils";
import { default_content, default_embed, default_image, getButtons } from "../utils/music/Config";
import { GuildType } from "../../db/db";
@@ -30,6 +30,11 @@ export class GuildPlayer {
public msg: Message,
) {
this.player.setGlobalVolume(50);
this.player.on("start", (_data: TrackStartEvent) => {
Redis.publishState("player_update", {
guildId: this.guild.id,
});
});
this.player.on("end", async (data: TrackEndEvent) => {
if (this.isDead) return;
if (data.reason === "replaced") return;
@@ -65,6 +70,13 @@ export class GuildPlayer {
public get isRecommend(): boolean {
return this.GDB?.options.recommend ?? false;
}
public get position(): number {
if (!this.isPlaying) return 0;
return this.player.position;
}
public get volume(): number {
return this.player.volume;
}
public async addTrack(track: Track, userId: string) {
this.queue.push({ ...track, userId });
@@ -73,7 +85,7 @@ export class GuildPlayer {
await this.playNext();
} else {
// 재생목록 추가되었을때
this.setMsg();
this.setMsg({ player: false, queue: true });
}
}
@@ -85,7 +97,7 @@ export class GuildPlayer {
await this.playNext();
} else {
// 재생목록 추가되었을때
this.setMsg();
this.setMsg({ player: false, queue: true });
}
}
@@ -100,10 +112,10 @@ export class GuildPlayer {
public async setPause() {
if (this.isPaused) {
await this.player.setPaused(false);
this.setMsg();
this.setMsg({ player: true, queue: false });
} else if (this.isPlaying) {
await this.player.setPaused(true);
this.setMsg();
this.setMsg({ player: true, queue: false });
}
}
@@ -122,20 +134,28 @@ export class GuildPlayer {
let nowQueue = this.queue.slice(1);
nowQueue = shuffle(nowQueue);
this.queue = [this.queue[0], ...nowQueue];
this.setMsg();
this.setMsg({ player: false, queue: true });
}
public setRecommend() {
if (!this.GDB) return;
this.GDB.options.recommend = !this.GDB.options.recommend;
DB.guild.update(this.GDB);
this.setMsg();
this.setMsg({ player: false, queue: false });
}
public setVolume(volume: number) {
if (!this.isPlaying) return;
if (!this.nowTrack) return;
this.player.setGlobalVolume(volume);
this.setMsg({ player: true, queue: false });
}
public seek(num: number) {
if (!this.isPlaying) return;
if (!this.nowTrack) return;
this.player.seekTo(num);
Redis.publishState("player_update", { guildId: this.guild.id });
}
private async autoPlay() {
@@ -189,7 +209,9 @@ export class GuildPlayer {
lavalinkManager.shoukaku.leaveVoiceChannel(this.guild.id);
}
private async setMsg() {
public async setMsg(update: { player: boolean; queue: boolean; } = { player: true, queue: true }) {
if (update.player) Redis.publishState("player_update", { guildId: this.guild.id });
if (update.queue) Redis.publishState("queue_update", { guildId: this.guild.id });
const { channel, msg, check } = await checkTextChannelAndMsg(this.guild, this.textChannel, this.msg);
if (!check) return;
this.textChannel = channel;
@@ -247,7 +269,7 @@ export class GuildPlayer {
files: embed.data.image?.url === default_embed(this.guild.id).data.image?.url ? [ default_image ] : [],
components: [ getButtons(
this.isPlaying || this.isPaused,
this.isPaused,
this.isPlaying && this.isPaused,
realQueue.length > 1,
) ]
});