mirror of
https://github.com/BluemediaDev/muse.git
synced 2025-06-27 09:12:43 +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]
|
||||
|
||||
### Added
|
||||
- An optional `pageSize` to `/queue` command
|
||||
|
||||
## [2.9.3] - 2024-08-19
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -14,6 +14,10 @@ export default class implements Command {
|
|||
.addIntegerOption(option => option
|
||||
.setName('page')
|
||||
.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));
|
||||
|
||||
private readonly playerManager: PlayerManager;
|
||||
|
@ -25,7 +29,11 @@ export default class implements Command {
|
|||
public async execute(interaction: ChatInputCommandInteraction) {
|
||||
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]});
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ import getProgressBar from './get-progress-bar.js';
|
|||
import {prettyTime} from './time.js';
|
||||
import {truncate} from './string.js';
|
||||
|
||||
const PAGE_SIZE = 10;
|
||||
|
||||
const getMaxSongTitleLength = (title: string) => {
|
||||
// eslint-disable-next-line no-control-regex
|
||||
const nonASCII = /[^\x00-\x7F]+/;
|
||||
|
@ -77,7 +75,7 @@ export const buildPlayingMessageEmbed = (player: Player): EmbedBuilder => {
|
|||
return message;
|
||||
};
|
||||
|
||||
export const buildQueueEmbed = (player: Player, page: number): EmbedBuilder => {
|
||||
export const buildQueueEmbed = (player: Player, page: number, pageSize: number): EmbedBuilder => {
|
||||
const currentlyPlaying = player.getCurrent();
|
||||
|
||||
if (!currentlyPlaying) {
|
||||
|
@ -85,14 +83,14 @@ export const buildQueueEmbed = (player: Player, page: number): EmbedBuilder => {
|
|||
}
|
||||
|
||||
const queueSize = player.queueSize();
|
||||
const maxQueuePage = Math.ceil((queueSize + 1) / PAGE_SIZE);
|
||||
const maxQueuePage = Math.ceil((queueSize + 1) / pageSize);
|
||||
|
||||
if (page > maxQueuePage) {
|
||||
throw new Error('the queue isn\'t that big');
|
||||
}
|
||||
|
||||
const queuePageBegin = (page - 1) * PAGE_SIZE;
|
||||
const queuePageEnd = queuePageBegin + PAGE_SIZE;
|
||||
const queuePageBegin = (page - 1) * pageSize;
|
||||
const queuePageEnd = queuePageBegin + pageSize;
|
||||
const queuedSongs = player
|
||||
.getQueue()
|
||||
.slice(queuePageBegin, queuePageEnd)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue