add buttons logic

This commit is contained in:
Mylloon 2023-01-16 18:43:07 +01:00
parent 8ebc926d97
commit 2e1b350e15
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 48 additions and 36 deletions

View file

@ -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],
};

View file

@ -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],
};

View file

@ -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)

View file

@ -41,7 +41,7 @@
"c_reminder3": "Rappel non trouvé, pas sur le bon serveur ou qui ne vous appartiens pas.",
"c_reminder4": "Utilisateur inconnu.",
"c_reminder5": "Rappels de",
"c_reminder6": "Page ",
"c_reminder6": "Page",
"c_reminder7": "Pas de message",
"c_reminder8": "Expire dans",
"c_reminder9": "Fais le",