added loop
This commit is contained in:
@@ -7,6 +7,7 @@ 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,
|
||||||
@@ -18,5 +19,6 @@ export const commands: { [key: string]: Command } = {
|
|||||||
stop,
|
stop,
|
||||||
pause,
|
pause,
|
||||||
skip,
|
skip,
|
||||||
|
loop,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
34
src/commands/loop.ts
Normal file
34
src/commands/loop.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
9
src/global.d.ts
vendored
9
src/global.d.ts
vendored
@@ -10,12 +10,13 @@ type AudioFile = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Queue = {
|
type Queue = {
|
||||||
songList: AudioFile[],
|
songList: AudioFile[]
|
||||||
current: AudioFile | null,
|
current: AudioFile | null
|
||||||
|
loop: AudioFile | null
|
||||||
}
|
}
|
||||||
|
|
||||||
type HistoryObject = {
|
type HistoryObject = {
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
interaction: ChatInputCommandInteraction<CacheType>
|
||||||
url: string,
|
url: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,14 @@ 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(
|
||||||
@@ -36,7 +43,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.songList.shift()
|
const nextSong = queue.loop ?? queue.songList.shift()
|
||||||
if (!nextSong) {
|
if (!nextSong) {
|
||||||
queue.current = null
|
queue.current = null
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user