mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Merge pull request #23 from roflmaoqwerty/reminder-updates
Reminder updates
This commit is contained in:
commit
7562bf8fd1
4 changed files with 41 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -70,9 +70,20 @@ export class RemindersPlugin extends ZeppelinPlugin<TConfigSchema> {
|
||||||
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 +138,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 +163,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