mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-10 02:33:06 +00:00
chore: split db file into multiple files and centralized pagination
This commit is contained in:
parent
2f5c3499e7
commit
be8df5f6a2
11 changed files with 1612 additions and 1401 deletions
|
@ -1,9 +1,7 @@
|
|||
import {
|
||||
SlashCommandBuilder,
|
||||
EmbedBuilder,
|
||||
ButtonBuilder,
|
||||
ActionRowBuilder,
|
||||
ButtonStyle,
|
||||
StringSelectMenuBuilder,
|
||||
APIEmbed,
|
||||
JSONEncodable,
|
||||
|
@ -11,6 +9,7 @@ import {
|
|||
|
||||
import { OptionsCommand } from '@/types/CommandTypes.js';
|
||||
import { getLevelLeaderboard } from '@/db/db.js';
|
||||
import { createPaginationButtons } from '@/util/helpers.js';
|
||||
|
||||
const command: OptionsCommand = {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -78,18 +77,7 @@ const command: OptionsCommand = {
|
|||
let currentPage = 0;
|
||||
|
||||
const getButtonActionRow = () =>
|
||||
new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('previous')
|
||||
.setLabel('Previous')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(currentPage === 0),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('next')
|
||||
.setLabel('Next')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(currentPage === pages.length - 1),
|
||||
);
|
||||
createPaginationButtons(pages.length, currentPage);
|
||||
|
||||
const getSelectMenuRow = () => {
|
||||
const options = pages.map((_, index) => ({
|
||||
|
@ -119,7 +107,7 @@ const command: OptionsCommand = {
|
|||
if (pages.length <= 1) return;
|
||||
|
||||
const collector = message.createMessageComponentCollector({
|
||||
time: 60000,
|
||||
time: 300000,
|
||||
});
|
||||
|
||||
collector.on('collect', async (i) => {
|
||||
|
@ -132,10 +120,19 @@ const command: OptionsCommand = {
|
|||
}
|
||||
|
||||
if (i.isButton()) {
|
||||
if (i.customId === 'previous' && currentPage > 0) {
|
||||
currentPage--;
|
||||
} else if (i.customId === 'next' && currentPage < pages.length - 1) {
|
||||
currentPage++;
|
||||
switch (i.customId) {
|
||||
case 'first':
|
||||
currentPage = 0;
|
||||
break;
|
||||
case 'prev':
|
||||
if (currentPage > 0) currentPage--;
|
||||
break;
|
||||
case 'next':
|
||||
if (currentPage < pages.length - 1) currentPage++;
|
||||
break;
|
||||
case 'last':
|
||||
currentPage = pages.length - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue