From 17decd09d5b5700b9a49329485c95f5db1123d82 Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Wed, 8 Jan 2020 14:29:49 +1100 Subject: [PATCH 1/4] Added created_at field to reminders table. Added time remaining timestamp to reminders command. Added creation date timestamp to reminder activation message --- backend/src/data/GuildReminders.ts | 3 ++- backend/src/data/entities/Reminder.ts | 2 ++ ...8445483917-CreateReminderCreatedAtField.ts | 18 +++++++++++++ backend/src/plugins/Reminders.ts | 27 +++++++++++++++---- 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 backend/src/migrations/1578445483917-CreateReminderCreatedAtField.ts diff --git a/backend/src/data/GuildReminders.ts b/backend/src/data/GuildReminders.ts index 13f2f5b2..6425ff61 100644 --- a/backend/src/data/GuildReminders.ts +++ b/backend/src/data/GuildReminders.ts @@ -34,13 +34,14 @@ export class GuildReminders extends BaseGuildRepository { }); } - async add(userId: string, channelId: string, remindAt: string, body: string) { + async add(userId: string, channelId: string, remindAt: string, body: string, created_at: string) { await this.reminders.insert({ guild_id: this.guildId, user_id: userId, channel_id: channelId, remind_at: remindAt, body, + created_at }); } } diff --git a/backend/src/data/entities/Reminder.ts b/backend/src/data/entities/Reminder.ts index a069ddcf..b232c796 100644 --- a/backend/src/data/entities/Reminder.ts +++ b/backend/src/data/entities/Reminder.ts @@ -15,4 +15,6 @@ export class Reminder { @Column() remind_at: string; @Column() body: string; + + @Column() created_at: string } diff --git a/backend/src/migrations/1578445483917-CreateReminderCreatedAtField.ts b/backend/src/migrations/1578445483917-CreateReminderCreatedAtField.ts new file mode 100644 index 00000000..b078d18f --- /dev/null +++ b/backend/src/migrations/1578445483917-CreateReminderCreatedAtField.ts @@ -0,0 +1,18 @@ +import {MigrationInterface, QueryRunner, TableColumn} from "typeorm"; + +export class CreateReminderCreatedAtField1578445483917 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.addColumn("reminders", + new TableColumn({ + name: "created_at", + type: "datetime", + isNullable: false + })); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.dropColumn("reminders", "created_at"); + } + +} diff --git a/backend/src/plugins/Reminders.ts b/backend/src/plugins/Reminders.ts index b97dc72d..22678f96 100644 --- a/backend/src/plugins/Reminders.ts +++ b/backend/src/plugins/Reminders.ts @@ -11,8 +11,10 @@ import { errorMessage, sorter, successMessage, + tDateTime, } from "../utils"; import * as t from "io-ts"; +import { EventListenerTypes } from "typeorm/metadata/types/EventListenerTypes"; const ConfigSchema = t.type({ can_use: t.boolean, @@ -68,11 +70,23 @@ export class RemindersPlugin extends ZeppelinPlugin { const pendingReminders = await this.reminders.getDueReminders(); for (const reminder of pendingReminders) { const channel = this.guild.channels.get(reminder.channel_id); + if (channel && channel instanceof TextChannel) { try { - await channel.createMessage( - disableLinkPreviews(`<@!${reminder.user_id}> You asked me to remind you: ${reminder.body}`), - ); + //Only show created at date if one exists + if(moment(reminder.created_at).isValid()){ + const target = moment(); + const diff = target.diff(moment(reminder.created_at , "YYYY-MM-DD HH:mm:ss")); + const result = humanizeDuration(diff, { largest: 2, round: true }); + await channel.createMessage( + disableLinkPreviews(`Reminder for <@!${reminder.user_id}>: ${reminder.body} \n\`Set at ${reminder.created_at} (${result} ago)\``), + ); + } + else{ + await channel.createMessage( + disableLinkPreviews(`Reminder for <@!${reminder.user_id}>: ${reminder.body}`), + ); + } } catch (e) { // Probably random Discord internal server error or missing permissions or somesuch // Try again next round unless we've already tried to post this a bunch of times @@ -127,7 +141,7 @@ export class RemindersPlugin extends ZeppelinPlugin { } const reminderBody = args.reminder || `https://discordapp.com/channels/${this.guildId}/${msg.channel.id}/${msg.id}`; - await this.reminders.add(msg.author.id, msg.channel.id, reminderTime.format("YYYY-MM-DD HH:mm:ss"), reminderBody); + await this.reminders.add(msg.author.id, msg.channel.id, reminderTime.format("YYYY-MM-DD HH:mm:ss"), reminderBody, moment().format("YYYY-MM-DD HH:mm:ss")); const msUntilReminder = reminderTime.diff(now); const timeUntilReminder = humanizeDuration(msUntilReminder, { largest: 2, round: true }); @@ -152,7 +166,10 @@ export class RemindersPlugin extends ZeppelinPlugin { const lines = Array.from(reminders.entries()).map(([i, reminder]) => { const num = i + 1; const paddedNum = num.toString().padStart(longestNum, " "); - return `\`${paddedNum}.\` \`${reminder.remind_at}\` ${reminder.body}`; + const target = moment(reminder.remind_at , "YYYY-MM-DD HH:mm:ss"); + const diff = target.diff(moment()); + const result = humanizeDuration(diff, { largest: 2, round: true }); + return `\`${paddedNum}.\` \`${reminder.remind_at} (${result})\` ${reminder.body}`; }); createChunkedMessage(msg.channel, lines.join("\n")); From 34aed027f47e60c2855390ba77db45707f11bda1 Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Wed, 8 Jan 2020 14:33:12 +1100 Subject: [PATCH 2/4] removed unnecessary code lines --- backend/src/plugins/Reminders.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/plugins/Reminders.ts b/backend/src/plugins/Reminders.ts index 22678f96..5f59e9bf 100644 --- a/backend/src/plugins/Reminders.ts +++ b/backend/src/plugins/Reminders.ts @@ -11,7 +11,6 @@ import { errorMessage, sorter, successMessage, - tDateTime, } from "../utils"; import * as t from "io-ts"; import { EventListenerTypes } from "typeorm/metadata/types/EventListenerTypes"; From a1cb358d16062ff3a191e3df880f7f09508577ec Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Wed, 8 Jan 2020 14:34:36 +1100 Subject: [PATCH 3/4] removed unnecessary code lines 2: electric boogaloo --- backend/src/plugins/Reminders.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/plugins/Reminders.ts b/backend/src/plugins/Reminders.ts index 5f59e9bf..2d1a6a82 100644 --- a/backend/src/plugins/Reminders.ts +++ b/backend/src/plugins/Reminders.ts @@ -13,7 +13,6 @@ import { successMessage, } from "../utils"; import * as t from "io-ts"; -import { EventListenerTypes } from "typeorm/metadata/types/EventListenerTypes"; const ConfigSchema = t.type({ can_use: t.boolean, From 329de665f519bc96066dc73de5a1cd016b415bbd Mon Sep 17 00:00:00 2001 From: roflmaoqwerty Date: Wed, 8 Jan 2020 14:35:44 +1100 Subject: [PATCH 4/4] removed unnecessary code lines 2: electric boogaloo 2 --- backend/src/plugins/Reminders.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/plugins/Reminders.ts b/backend/src/plugins/Reminders.ts index 2d1a6a82..3f15161a 100644 --- a/backend/src/plugins/Reminders.ts +++ b/backend/src/plugins/Reminders.ts @@ -68,7 +68,6 @@ export class RemindersPlugin extends ZeppelinPlugin { const pendingReminders = await this.reminders.getDueReminders(); for (const reminder of pendingReminders) { const channel = this.guild.channels.get(reminder.channel_id); - if (channel && channel instanceof TextChannel) { try { //Only show created at date if one exists