3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Added created_at field to reminders table. Added time remaining timestamp to reminders command. Added creation date timestamp to reminder activation message

This commit is contained in:
roflmaoqwerty 2020-01-08 14:29:49 +11:00
parent 4e1b135724
commit 17decd09d5
4 changed files with 44 additions and 6 deletions

View file

@ -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
});
}
}

View file

@ -15,4 +15,6 @@ export class Reminder {
@Column() remind_at: string;
@Column() body: string;
@Column() created_at: string
}

View file

@ -0,0 +1,18 @@
import {MigrationInterface, QueryRunner, TableColumn} from "typeorm";
export class CreateReminderCreatedAtField1578445483917 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.addColumn("reminders",
new TableColumn({
name: "created_at",
type: "datetime",
isNullable: false
}));
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.dropColumn("reminders", "created_at");
}
}

View file

@ -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<TConfigSchema> {
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<TConfigSchema> {
}
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<TConfigSchema> {
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"));