Skip to content

Commit

Permalink
Reply to originally invoking message for reminders
Browse files Browse the repository at this point in the history
We only do this if we have a reminder body, otherwise we would link to the original message twice.
  • Loading branch information
DarkView committed Sep 13, 2021
1 parent 7edfe15 commit 68a55f5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend/src/data/GuildReminders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ export class GuildReminders extends BaseGuildRepository {
});
}

async add(userId: string, channelId: string, remindAt: string, body: string, created_at: string) {
async add(userId: string, channelId: string, remindAt: string, body: string, created_at: string, source_id?: string) {
await this.reminders.insert({
guild_id: this.guildId,
user_id: userId,
channel_id: channelId,
remind_at: remindAt,
body,
created_at,
source_message_id: source_id,
});
}
}
2 changes: 2 additions & 0 deletions backend/src/data/entities/Reminder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ export class Reminder {
@Column() body: string;

@Column() created_at: string;

@Column() source_message_id: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner, TableColumn } from "typeorm";

export class AddSourceMessageIdToReminders1631494429170 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.addColumns("reminders", [
new TableColumn({
name: "source_message_id",
type: "bigint",
isNullable: true,
default: null,
unsigned: true,
}),
]);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropColumn("reminders", "source_message_id");
}
}
1 change: 1 addition & 0 deletions backend/src/plugins/Reminders/commands/RemindCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const RemindCmd = remindersCmd({
reminderTime.clone().tz("Etc/UTC").format("YYYY-MM-DD HH:mm:ss"),
reminderBody,
moment.utc().format("YYYY-MM-DD HH:mm:ss"),
args.reminder ? msg.id : undefined,
);

const msUntilReminder = reminderTime.diff(now);
Expand Down
2 changes: 2 additions & 0 deletions backend/src/plugins/Reminders/utils/postDueRemindersLoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export async function postDueRemindersLoop(pluginData: GuildPluginData<Reminders
content: disableLinkPreviews(
`Reminder for <@!${reminder.user_id}>: ${reminder.body} \n\`Set at ${reminder.created_at} (${result} ago)\``,
),
reply: { messageReference: reminder.source_message_id, failIfNotExists: false },
allowedMentions: {
users: [reminder.user_id as Snowflake],
},
});
} else {
await channel.send({
content: disableLinkPreviews(`Reminder for <@!${reminder.user_id}>: ${reminder.body}`),
reply: { messageReference: reminder.source_message_id, failIfNotExists: false },
allowedMentions: {
users: [reminder.user_id as Snowflake],
},
Expand Down

0 comments on commit 68a55f5

Please sign in to comment.