mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +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:
parent
4e1b135724
commit
17decd09d5
4 changed files with 44 additions and 6 deletions
|
@ -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({
|
await this.reminders.insert({
|
||||||
guild_id: this.guildId,
|
guild_id: this.guildId,
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
channel_id: channelId,
|
channel_id: channelId,
|
||||||
remind_at: remindAt,
|
remind_at: remindAt,
|
||||||
body,
|
body,
|
||||||
|
created_at
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,4 +15,6 @@ export class Reminder {
|
||||||
@Column() remind_at: string;
|
@Column() remind_at: string;
|
||||||
|
|
||||||
@Column() body: string;
|
@Column() body: string;
|
||||||
|
|
||||||
|
@Column() created_at: string
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -11,8 +11,10 @@ import {
|
||||||
errorMessage,
|
errorMessage,
|
||||||
sorter,
|
sorter,
|
||||||
successMessage,
|
successMessage,
|
||||||
|
tDateTime,
|
||||||
} from "../utils";
|
} from "../utils";
|
||||||
import * as t from "io-ts";
|
import * as t from "io-ts";
|
||||||
|
import { EventListenerTypes } from "typeorm/metadata/types/EventListenerTypes";
|
||||||
|
|
||||||
const ConfigSchema = t.type({
|
const ConfigSchema = t.type({
|
||||||
can_use: t.boolean,
|
can_use: t.boolean,
|
||||||
|
@ -68,11 +70,23 @@ export class RemindersPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
const pendingReminders = await this.reminders.getDueReminders();
|
const pendingReminders = await this.reminders.getDueReminders();
|
||||||
for (const reminder of pendingReminders) {
|
for (const reminder of pendingReminders) {
|
||||||
const channel = this.guild.channels.get(reminder.channel_id);
|
const channel = this.guild.channels.get(reminder.channel_id);
|
||||||
|
|
||||||
if (channel && channel instanceof TextChannel) {
|
if (channel && channel instanceof TextChannel) {
|
||||||
try {
|
try {
|
||||||
await channel.createMessage(
|
//Only show created at date if one exists
|
||||||
disableLinkPreviews(`<@!${reminder.user_id}> You asked me to remind you: ${reminder.body}`),
|
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) {
|
} catch (e) {
|
||||||
// Probably random Discord internal server error or missing permissions or somesuch
|
// 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
|
// 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}`;
|
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 msUntilReminder = reminderTime.diff(now);
|
||||||
const timeUntilReminder = humanizeDuration(msUntilReminder, { largest: 2, round: true });
|
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 lines = Array.from(reminders.entries()).map(([i, reminder]) => {
|
||||||
const num = i + 1;
|
const num = i + 1;
|
||||||
const paddedNum = num.toString().padStart(longestNum, " ");
|
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"));
|
createChunkedMessage(msg.channel, lines.join("\n"));
|
||||||
|
|
Loading…
Add table
Reference in a new issue