Skip to content

Commit

Permalink
remove reminder_due field
Browse files Browse the repository at this point in the history
  • Loading branch information
wdhdev committed Dec 3, 2024
1 parent 3fb2181 commit 441910a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/commands/reminders/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const command: Command = {
.addFields(
{ name: "Reason", value: reminder.reason },
{ name: "Set", value: `<t:${reminder.reminder_set.toString().slice(0, -3)}:f>`, inline: true },
{ name: "Due", value: `<t:${reminder.reminder_due.toString().slice(0, -3)}:R>`, inline: true }
{ name: "Due", value: `<t:${(reminder.reminder_set + reminder.delay).toString().slice(0, -3)}:R>`, inline: true }
)

await interaction.editReply({ embeds: [info] });
Expand Down
2 changes: 1 addition & 1 deletion src/commands/reminders/reminders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const command: Command = {
const list = new Discord.EmbedBuilder()
.setColor(client.config.embeds.default as ColorResolvable)
.setTitle("Your Reminders")
.setDescription(cap(reminders.map(r => `\`${r.reminder_id}\` (<t:${r.reminder_due.toString().slice(0, -3)}:R>):\n*${!fullReasons ? cap(r.reason, 100): r.reason}*`).join("\n"), 4000))
.setDescription(cap(reminders.map(r => `\`${r.reminder_id}\` (<t:${(r.reminder_set + r.delay).toString().slice(0, -3)}:R>):\n*${!fullReasons ? cap(r.reason, 100): r.reason}*`).join("\n"), 4000))

await interaction.editReply({ embeds: [list] });
} catch(err) {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/reminders/remindme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ const command: Command = {
user: interaction.user.id,
channel: interaction.channel?.id ? interaction.channel?.id : null,
delay: time,
reminder_due: (Date.now() + time).toString(),
reason: reason,
send_in_channel: sendInChannel
}).save()
Expand Down Expand Up @@ -150,7 +149,7 @@ const command: Command = {

const reminderSet = new Discord.EmbedBuilder()
.setColor(client.config.embeds.default as ColorResolvable)
.setDescription(`${emoji.tick} Your reminder has been set for <t:${reminder.reminder_due.toString().slice(0, -3)}:f> with ID \`${reminder.reminder_id}\`!`)
.setDescription(`${emoji.tick} Your reminder has been set for <t:${(reminder.reminder_set + reminder.delay).toString().slice(0, -3)}:f> with ID \`${reminder.reminder_id}\`!`)

await interaction.editReply({ embeds: [reminderSet] });
} catch(err) {
Expand Down
4 changes: 2 additions & 2 deletions src/events/client/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const event: Event = {
// Manage timeouts
async function manageExistingTimeouts() {
let reminders = await Reminder.find({});
const dueReminders = reminders.filter(reminder => reminder.reminder_due <= Date.now().toString());
const dueReminders = reminders.filter(reminder => (reminder.reminder_set + reminder.delay) <= Date.now().toString());

for(const reminder of dueReminders) {
await reminder.deleteOne();
Expand All @@ -33,7 +33,7 @@ const event: Event = {
.setDescription(reminder.reason)
.addFields (
{ name: "Set", value: `<t:${reminder.reminder_set.toString().slice(0, -3)}:f>`, inline: true },
{ name: "Overdue Since", value: `<t:${reminder.reminder_due.toString().slice(0, -3)}:R>`, inline: true }
{ name: "Overdue Since", value: `<t:${(reminder.reminder_set + reminder.delay).toString().slice(0, -3)}:R>`, inline: true }
)
.setFooter({ text: `ID: ${reminder.reminder_id}` })
.setTimestamp()
Expand Down
11 changes: 3 additions & 8 deletions src/models/Reminder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ function decrypt(text: string): string {
return decrypted;
}

interface Reminder extends Document {
export interface Reminder extends Document {
reminder_id: string;
user: string;
channel?: string;
delay: number;
reminder_set: string;
reminder_due: string;
reason: string;
send_in_channel?: boolean;
}

const reminderSchema = new Schema<Reminder>(
const schema = new Schema<Reminder>(
{
reminder_id: {
type: String,
Expand Down Expand Up @@ -67,10 +66,6 @@ const reminderSchema = new Schema<Reminder>(
required: true,
default: () => Number(Date.now()).toString()
},
reminder_due: {
type: String,
required: true
},
reason: {
type: String,
required: true,
Expand All @@ -85,4 +80,4 @@ const reminderSchema = new Schema<Reminder>(
{ timestamps: true }
);

export default model<Reminder>("reminders", reminderSchema, "reminders");
export default model<Reminder>("reminders", schema, "reminders");
6 changes: 4 additions & 2 deletions src/util/setReminder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { ColorResolvable, EmbedBuilder, TextChannel } from "discord.js";

import ExtendedClient from "../classes/ExtendedClient";

export default async function (reminder: any, client: ExtendedClient): Promise<Boolean> {
const delay = Number(reminder.reminder_due) - Date.now();
import { Reminder } from "../models/Reminder";

export default async function (reminder: Reminder, client: ExtendedClient): Promise<Boolean> {
const delay = Number(reminder.reminder_set + reminder.delay) - Date.now();

if(delay > client.config.reminders.timeTillSet) return false;

Expand Down

0 comments on commit 441910a

Please sign in to comment.