1
0
Fork 0
mirror of https://github.com/JonnyBro/JaBa.git synced 2024-12-23 11:53:02 +05:00
JaBa/commands/General/remindme.js

99 lines
2.9 KiB
JavaScript
Raw Normal View History

2024-09-19 23:58:06 +05:00
const { SlashCommandBuilder, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand"),
2024-02-09 23:26:57 +05:00
ms = require("ms");
class Remindme extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("remindme")
.setDescription(client.translate("general/remindme:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("general/remindme:DESCRIPTION", null, "uk-UA"),
ru: client.translate("general/remindme:DESCRIPTION", null, "ru-RU"),
})
2024-09-19 23:58:06 +05:00
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall])
2024-09-14 19:52:56 +05:00
.setContexts([InteractionContextType.BotDM, InteractionContextType.PrivateChannel, InteractionContextType.Guild])
2023-07-05 00:58:06 +05:00
.addStringOption(option =>
option
.setName("time")
.setDescription(client.translate("general/remindme:TIME"))
.setDescriptionLocalizations({
uk: client.translate("general/remindme:TIME", null, "uk-UA"),
ru: client.translate("general/remindme:TIME", null, "ru-RU"),
})
.setRequired(true),
)
.addStringOption(option =>
option
.setName("message")
.setDescription(client.translate("common:MESSAGE"))
.setDescriptionLocalizations({
uk: client.translate("common:MESSAGE", null, "uk-UA"),
ru: client.translate("common:MESSAGE", null, "ru-RU"),
})
.setRequired(true),
),
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
2024-02-09 23:26:57 +05:00
async execute(client, interaction) {
2024-11-10 17:28:24 +05:00
await interaction.deferReply({ ephemeral: true });
2024-09-19 23:58:06 +05:00
const conditions = ["s", "m", "h", "d", "w", "y"],
time = interaction.options.getString("time"),
message = interaction.options.getString("message");
if (!conditions.some(s => time.includes(s))) return interaction.error("general/remindme:TIME", null, { edit: true });
2024-02-09 23:26:57 +05:00
const userData = interaction.data.user;
if (!userData.reminds) userData.reminds = [];
2024-01-27 16:31:34 +05:00
const dateNow = Date.now();
2024-02-09 23:26:57 +05:00
const reminder = {
2024-09-19 23:58:06 +05:00
message: message,
2024-02-09 23:26:57 +05:00
createdAt: Math.floor(dateNow / 1000),
2024-09-19 23:58:06 +05:00
sendAt: Math.floor((dateNow + ms(time)) / 1000),
};
2024-02-09 23:26:57 +05:00
userData.reminds.push(reminder);
2024-02-09 23:26:57 +05:00
await userData.save();
2024-02-09 23:26:57 +05:00
client.databaseCache.usersReminds.set(interaction.user.id, userData);
const embed = client.embed({
author: interaction.translate("general/remindme:EMBED_SAVED"),
fields: [
2024-01-27 16:31:34 +05:00
{
name: interaction.translate("general/remindme:EMBED_TIME"),
2024-02-09 23:26:57 +05:00
value: `<t:${reminder.sendAt}:R>`,
2024-01-27 16:31:34 +05:00
},
{
name: interaction.translate("common:MESSAGE"),
2024-02-09 23:26:57 +05:00
value: reminder.message,
2024-01-27 16:31:34 +05:00
},
],
});
2024-01-27 16:31:34 +05:00
interaction.editReply({
embeds: [embed],
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Remindme;