feat: Reminders #44

Merged
Anri merged 54 commits from feat/reminders into main 2023-01-17 12:15:15 +01:00
4 changed files with 48 additions and 36 deletions
Showing only changes of commit 2e1b350e15 - Show all commits

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

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

View file

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

View file

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