Skip to content

Commit

Permalink
encrypt reminder id
Browse files Browse the repository at this point in the history
  • Loading branch information
wdhdev committed Dec 3, 2024
1 parent c7d049c commit b346e60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
12 changes: 3 additions & 9 deletions src/commands/reminders/remindme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import ExtendedClient from "../../classes/ExtendedClient";
import { ChatInputCommandInteraction, ColorResolvable, TextChannel } from "discord.js";

import { emojis as emoji } from "../../../config.json";
import { randomUUID } from "crypto";

import Reminder from "../../models/Reminder";

Expand Down Expand Up @@ -98,23 +97,18 @@ const command: Command = {
return;
}

const id = randomUUID().slice(0, 8) as string;

const reminder = await new Reminder({
reminder_id: id,
user: interaction.user.id,
channel: interaction.channel?.id ? interaction.channel?.id : null,
reminder_set: (Date.now()).toString(),
reminder_due: (Date.now() + time).toString(),
delay: time,
reason: reason,
send_in_channel: sendInChannel
}).save()

if(time < client.config.reminders.timeTillSet) {
client.reminders.set(`${interaction.user.id}-${id}`, setTimeout(async () => {
client.reminders.delete(`${interaction.user.id}-${id}`);
await Reminder.findOneAndDelete({ reminder_id: id, user: interaction.user.id });
client.reminders.set(`${interaction.user.id}-${reminder.reminder_id}`, setTimeout(async () => {
client.reminders.delete(`${interaction.user.id}-${reminder.reminder_id}`);
await Reminder.findOneAndDelete({ reminder_id: reminder.reminder_id, user: interaction.user.id });

const embed = new Discord.EmbedBuilder()
.setColor(client.config.embeds.default as ColorResolvable)
Expand Down
5 changes: 4 additions & 1 deletion src/models/Reminder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const reminderSchema = new Schema<Reminder>(
type: String,
required: true,
unique: true,
index: true
index: true,
default: () => crypto.randomBytes(4).toString("hex"),
set: (value: string) => encrypt(value),
get: (value: string) => decrypt(value)
},
user: {
type: String,
Expand Down

0 comments on commit b346e60

Please sign in to comment.