mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-06-27 17:22:42 +02:00
feat: add optional pageSize to /queue command
This commit is contained in:
parent
1e17b94321
commit
6e39c8d09e
3 changed files with 16 additions and 7 deletions
|
@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- An optional `pageSize` to `/queue` command
|
||||||
|
|
||||||
## [2.9.3] - 2024-08-19
|
## [2.9.3] - 2024-08-19
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
@ -14,6 +14,10 @@ export default class implements Command {
|
||||||
.addIntegerOption(option => option
|
.addIntegerOption(option => option
|
||||||
.setName('page')
|
.setName('page')
|
||||||
.setDescription('page of queue to show [default: 1]')
|
.setDescription('page of queue to show [default: 1]')
|
||||||
|
.setRequired(false))
|
||||||
|
.addIntegerOption(option => option
|
||||||
|
.setName('pageSize')
|
||||||
|
.setDescription('how many items to display per page [default: 10]')
|
||||||
.setRequired(false));
|
.setRequired(false));
|
||||||
|
|
||||||
private readonly playerManager: PlayerManager;
|
private readonly playerManager: PlayerManager;
|
||||||
|
@ -25,7 +29,11 @@ export default class implements Command {
|
||||||
public async execute(interaction: ChatInputCommandInteraction) {
|
public async execute(interaction: ChatInputCommandInteraction) {
|
||||||
const player = this.playerManager.get(interaction.guild!.id);
|
const player = this.playerManager.get(interaction.guild!.id);
|
||||||
|
|
||||||
const embed = buildQueueEmbed(player, interaction.options.getInteger('page') ?? 1);
|
const embed = buildQueueEmbed(
|
||||||
|
player,
|
||||||
|
interaction.options.getInteger('page') ?? 1,
|
||||||
|
interaction.options.getInteger('pageSize') ?? 10,
|
||||||
|
);
|
||||||
|
|
||||||
await interaction.reply({embeds: [embed]});
|
await interaction.reply({embeds: [embed]});
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@ import getProgressBar from './get-progress-bar.js';
|
||||||
import {prettyTime} from './time.js';
|
import {prettyTime} from './time.js';
|
||||||
import {truncate} from './string.js';
|
import {truncate} from './string.js';
|
||||||
|
|
||||||
const PAGE_SIZE = 10;
|
|
||||||
|
|
||||||
const getMaxSongTitleLength = (title: string) => {
|
const getMaxSongTitleLength = (title: string) => {
|
||||||
// eslint-disable-next-line no-control-regex
|
// eslint-disable-next-line no-control-regex
|
||||||
const nonASCII = /[^\x00-\x7F]+/;
|
const nonASCII = /[^\x00-\x7F]+/;
|
||||||
|
@ -77,7 +75,7 @@ export const buildPlayingMessageEmbed = (player: Player): EmbedBuilder => {
|
||||||
return message;
|
return message;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const buildQueueEmbed = (player: Player, page: number): EmbedBuilder => {
|
export const buildQueueEmbed = (player: Player, page: number, pageSize: number): EmbedBuilder => {
|
||||||
const currentlyPlaying = player.getCurrent();
|
const currentlyPlaying = player.getCurrent();
|
||||||
|
|
||||||
if (!currentlyPlaying) {
|
if (!currentlyPlaying) {
|
||||||
|
@ -85,14 +83,14 @@ export const buildQueueEmbed = (player: Player, page: number): EmbedBuilder => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const queueSize = player.queueSize();
|
const queueSize = player.queueSize();
|
||||||
const maxQueuePage = Math.ceil((queueSize + 1) / PAGE_SIZE);
|
const maxQueuePage = Math.ceil((queueSize + 1) / pageSize);
|
||||||
|
|
||||||
if (page > maxQueuePage) {
|
if (page > maxQueuePage) {
|
||||||
throw new Error('the queue isn\'t that big');
|
throw new Error('the queue isn\'t that big');
|
||||||
}
|
}
|
||||||
|
|
||||||
const queuePageBegin = (page - 1) * PAGE_SIZE;
|
const queuePageBegin = (page - 1) * pageSize;
|
||||||
const queuePageEnd = queuePageBegin + PAGE_SIZE;
|
const queuePageEnd = queuePageBegin + pageSize;
|
||||||
const queuedSongs = player
|
const queuedSongs = player
|
||||||
.getQueue()
|
.getQueue()
|
||||||
.slice(queuePageBegin, queuePageEnd)
|
.slice(queuePageBegin, queuePageEnd)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue