added rzeczy
This commit is contained in:
57
src/playback.ts
Normal file
57
src/playback.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { AudioPlayer, AudioPlayerStatus } from "@discordjs/voice";
|
||||
import { player } from "./main";
|
||||
import { CacheType, ChatInputCommandInteraction } from "discord.js";
|
||||
import { getAudioFile } from "./util/downloader";
|
||||
import { playSong } from "./util/helpers";
|
||||
|
||||
const queue: Queue = {
|
||||
songList: [],
|
||||
current: null
|
||||
}
|
||||
|
||||
export async function requestSong(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
url: string) {
|
||||
|
||||
const path = await getAudioFile(url)
|
||||
queue.songList.push(path)
|
||||
updatePlayer()
|
||||
|
||||
}
|
||||
|
||||
export async function forceRequestSong(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
url: string) {
|
||||
|
||||
const path = await getAudioFile(url)
|
||||
queue.songList.push(path)
|
||||
playSong(player, path);
|
||||
}
|
||||
|
||||
|
||||
export async function updatePlayer() {
|
||||
if (player.state.status === AudioPlayerStatus.Idle) {
|
||||
const nextSong = queue.songList.shift()
|
||||
if (!nextSong) {
|
||||
queue.current = null
|
||||
return
|
||||
};
|
||||
playSong(player, nextSong);
|
||||
}
|
||||
}
|
||||
|
||||
export function pause_playback(player: AudioPlayer) {
|
||||
player.pause()
|
||||
}
|
||||
|
||||
export function stop_playback(player: AudioPlayer) {
|
||||
player.stop()
|
||||
}
|
||||
|
||||
export function resume_playback(player: AudioPlayer) {
|
||||
player.unpause()
|
||||
}
|
||||
|
||||
export function getQueue(): Queue {
|
||||
return queue
|
||||
}
|
||||
Reference in New Issue
Block a user