feat: Reminders #44
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 { getFilename } from '../../utils/misc';
|
||||||
|
import { embedListReminders } from '../../utils/reminder';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: {
|
data: {
|
||||||
name: getFilename(__filename),
|
name: getFilename(__filename),
|
||||||
},
|
},
|
||||||
interaction: async (_: MessageComponentInteraction, client: Client) => {
|
interaction: async (interaction: MessageComponentInteraction, client: Client) => {
|
||||||
// TODO: Dynamically change that
|
const loc = getLocale(client, interaction.locale);
|
||||||
const pageMax = 1;
|
const embed_desc = interaction.message.embeds.at(0)?.description as string;
|
||||||
const page = 1;
|
|
||||||
|
// 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
|
// Fetch list
|
||||||
client.db;
|
const list = await embedListReminders(client, user, interaction.guildId, page, interaction.locale);
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId('reminderList-prec')
|
.setCustomId('reminderList-prec')
|
||||||
.setLabel('Prec')
|
.setLabel(loc.get('c_reminder12'))
|
||||||
.setStyle(ButtonStyle.Primary))
|
.setStyle(ButtonStyle.Primary))
|
||||||
.addComponents(
|
.addComponents(
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId('reminderList-next')
|
.setCustomId('reminderList-next')
|
||||||
.setLabel('Next')
|
.setLabel(loc.get('c_reminder13'))
|
||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Primary),
|
||||||
.setDisabled(page === pageMax ? true : false),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const list = new EmbedBuilder()
|
|
||||||
.setColor(Colors.DarkGrey)
|
|
||||||
.setTitle('List title')
|
|
||||||
.setDescription('List desc');
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content: 'next',
|
|
||||||
embeds: [list],
|
embeds: [list],
|
||||||
components: [row],
|
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 { getFilename } from '../../utils/misc';
|
||||||
|
import { embedListReminders } from '../../utils/reminder';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: {
|
data: {
|
||||||
name: getFilename(__filename),
|
name: getFilename(__filename),
|
||||||
},
|
},
|
||||||
interaction: async (_: MessageComponentInteraction, client: Client) => {
|
interaction: async (interaction: MessageComponentInteraction, client: Client) => {
|
||||||
// TODO: Dynamically change that
|
const loc = getLocale(client, interaction.locale);
|
||||||
const page = 1;
|
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
|
// Fetch list
|
||||||
client.db;
|
const list = await embedListReminders(client, user, interaction.guildId, page, interaction.locale);
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||||
.addComponents(
|
.addComponents(
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId('reminderList-prec')
|
.setCustomId('reminderList-prec')
|
||||||
.setLabel('Prec')
|
.setLabel(loc.get('c_reminder12'))
|
||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Primary))
|
||||||
.setDisabled(page === 1 ? true : false))
|
|
||||||
.addComponents(
|
.addComponents(
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId('reminderList-next')
|
.setCustomId('reminderList-next')
|
||||||
.setLabel('Next')
|
.setLabel(loc.get('c_reminder13'))
|
||||||
.setStyle(ButtonStyle.Primary),
|
.setStyle(ButtonStyle.Primary),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const list = new EmbedBuilder()
|
|
||||||
.setColor(Colors.DarkGrey)
|
|
||||||
.setTitle('List title')
|
|
||||||
.setDescription('List desc');
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content: 'prec',
|
|
||||||
embeds: [list],
|
embeds: [list],
|
||||||
components: [row],
|
components: [row],
|
||||||
};
|
};
|
||||||
|
|
|
@ -229,8 +229,7 @@ export default {
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId(idPrec)
|
.setCustomId(idPrec)
|
||||||
.setLabel(loc.get('c_reminder12'))
|
.setLabel(loc.get('c_reminder12'))
|
||||||
.setStyle(ButtonStyle.Primary)
|
.setStyle(ButtonStyle.Primary))
|
||||||
.setDisabled(true))
|
|
||||||
.addComponents(
|
.addComponents(
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId(idNext)
|
.setCustomId(idNext)
|
||||||
|
|
Loading…
Reference in a new issue