add buttons logic
This commit is contained in:
parent
8ebc926d97
commit
2e1b350e15
4 changed files with 48 additions and 36 deletions
|
@ -1,40 +1,46 @@
|
|||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, Colors, EmbedBuilder, MessageComponentInteraction } from 'discord.js';
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, MessageComponentInteraction, User } from 'discord.js';
|
||||
import { getLocale } from '../../utils/locales';
|
||||
import { getFilename } from '../../utils/misc';
|
||||
import { embedListReminders } from '../../utils/reminder';
|
||||
|
||||
export default {
|
||||
data: {
|
||||
name: getFilename(__filename),
|
||||
},
|
||||
interaction: async (_: MessageComponentInteraction, client: Client) => {
|
||||
// TODO: Dynamically change that
|
||||
const pageMax = 1;
|
||||
const page = 1;
|
||||
interaction: async (interaction: MessageComponentInteraction, client: Client) => {
|
||||
const loc = getLocale(client, interaction.locale);
|
||||
const embed_desc = interaction.message.embeds.at(0)?.description as string;
|
||||
|
||||
// Retrieve Pages
|
||||
const pageMax = Number(/(\d+)(?!.*\d)/gm.exec(embed_desc)?.[0]);
|
||||
let page = Number(/(?!• \s+)\d(?=\/)/gm.exec(embed_desc)?.[0]);
|
||||
if (page + 1 > pageMax) {
|
||||
page = 1;
|
||||
} else {
|
||||
page++;
|
||||
}
|
||||
|
||||
// Retrieve user
|
||||
const userId = /(?!<@)\d+(?=>)/gm.exec(embed_desc)?.[0] as string;
|
||||
const user = client.users.cache.get(userId) as User;
|
||||
|
||||
// Fetch list
|
||||
client.db;
|
||||
const list = await embedListReminders(client, user, interaction.guildId, page, interaction.locale);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('reminderList-prec')
|
||||
.setLabel('Prec')
|
||||
.setLabel(loc.get('c_reminder12'))
|
||||
.setStyle(ButtonStyle.Primary))
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('reminderList-next')
|
||||
.setLabel('Next')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(page === pageMax ? true : false),
|
||||
.setLabel(loc.get('c_reminder13'))
|
||||
.setStyle(ButtonStyle.Primary),
|
||||
);
|
||||
|
||||
|
||||
const list = new EmbedBuilder()
|
||||
.setColor(Colors.DarkGrey)
|
||||
.setTitle('List title')
|
||||
.setDescription('List desc');
|
||||
|
||||
return {
|
||||
content: 'next',
|
||||
embeds: [list],
|
||||
components: [row],
|
||||
};
|
||||
|
|
|
@ -1,39 +1,46 @@
|
|||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, Colors, EmbedBuilder, MessageComponentInteraction } from 'discord.js';
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, Client, MessageComponentInteraction, User } from 'discord.js';
|
||||
import { getLocale } from '../../utils/locales';
|
||||
import { getFilename } from '../../utils/misc';
|
||||
import { embedListReminders } from '../../utils/reminder';
|
||||
|
||||
export default {
|
||||
data: {
|
||||
name: getFilename(__filename),
|
||||
},
|
||||
interaction: async (_: MessageComponentInteraction, client: Client) => {
|
||||
// TODO: Dynamically change that
|
||||
const page = 1;
|
||||
interaction: async (interaction: MessageComponentInteraction, client: Client) => {
|
||||
const loc = getLocale(client, interaction.locale);
|
||||
const embed_desc = interaction.message.embeds.at(0)?.description as string;
|
||||
|
||||
// Retrieve Pages
|
||||
const pageMax = Number(/(\d+)(?!.*\d)/gm.exec(embed_desc)?.[0]);
|
||||
let page = Number(/(?!• \s+)\d(?=\/)/gm.exec(embed_desc)?.[0]);
|
||||
if (page - 1 == 0) {
|
||||
page = pageMax;
|
||||
} else {
|
||||
page--;
|
||||
}
|
||||
|
||||
// Retrieve user
|
||||
const userId = /(?!<@)\d+(?=>)/gm.exec(embed_desc)?.[0] as string;
|
||||
const user = client.users.cache.get(userId) as User;
|
||||
|
||||
// Fetch list
|
||||
client.db;
|
||||
const list = await embedListReminders(client, user, interaction.guildId, page, interaction.locale);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('reminderList-prec')
|
||||
.setLabel('Prec')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(page === 1 ? true : false))
|
||||
.setLabel(loc.get('c_reminder12'))
|
||||
.setStyle(ButtonStyle.Primary))
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('reminderList-next')
|
||||
.setLabel('Next')
|
||||
.setLabel(loc.get('c_reminder13'))
|
||||
.setStyle(ButtonStyle.Primary),
|
||||
);
|
||||
|
||||
|
||||
const list = new EmbedBuilder()
|
||||
.setColor(Colors.DarkGrey)
|
||||
.setTitle('List title')
|
||||
.setDescription('List desc');
|
||||
|
||||
return {
|
||||
content: 'prec',
|
||||
embeds: [list],
|
||||
components: [row],
|
||||
};
|
||||
|
|
|
@ -229,8 +229,7 @@ export default {
|
|||
new ButtonBuilder()
|
||||
.setCustomId(idPrec)
|
||||
.setLabel(loc.get('c_reminder12'))
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(true))
|
||||
.setStyle(ButtonStyle.Primary))
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(idNext)
|
||||
|
|
Loading…
Reference in a new issue