From 5b6941a1f6e3c2186c43d14a8af4abe5d546d3bb Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Tue, 30 Apr 2019 06:28:10 +0300 Subject: [PATCH] Allow using !remind without a reminder text (the bot uses a message link then instead) --- src/plugins/Reminders.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/plugins/Reminders.ts b/src/plugins/Reminders.ts index bbda379e..47fe5f93 100644 --- a/src/plugins/Reminders.ts +++ b/src/plugins/Reminders.ts @@ -4,7 +4,14 @@ import { GuildReminders } from "../data/GuildReminders"; import { Message, TextChannel } from "eris"; import moment from "moment-timezone"; import humanizeDuration from "humanize-duration"; -import { convertDelayStringToMS, createChunkedMessage, errorMessage, sorter, successMessage } from "../utils"; +import { + convertDelayStringToMS, + createChunkedMessage, + disableLinkPreviews, + errorMessage, + sorter, + successMessage, +} from "../utils"; const REMINDER_LOOP_TIME = 10 * 1000; const MAX_TRIES = 3; @@ -50,7 +57,9 @@ export class RemindersPlugin extends ZeppelinPlugin { const channel = this.guild.channels.get(reminder.channel_id); if (channel && channel instanceof TextChannel) { try { - await channel.createMessage(`<@!${reminder.user_id}> You asked me to remind you: ${reminder.body}`); + await channel.createMessage( + disableLinkPreviews(`<@!${reminder.user_id}> You asked me to remind you: ${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 @@ -68,11 +77,11 @@ export class RemindersPlugin extends ZeppelinPlugin { this.postRemindersTimeout = setTimeout(() => this.postDueRemindersLoop(), REMINDER_LOOP_TIME); } - @d.command("remind", " ", { + @d.command("remind", " [reminder:string$]", { aliases: ["remindme"], }) @d.permission("can_use") - async addReminderCmd(msg: Message, args: { time: string; reminder: string }) { + async addReminderCmd(msg: Message, args: { time: string; reminder?: string }) { const now = moment(); let reminderTime; @@ -102,7 +111,8 @@ export class RemindersPlugin extends ZeppelinPlugin { return; } - await this.reminders.add(msg.author.id, msg.channel.id, reminderTime.format("YYYY-MM-DD HH:mm:ss"), args.reminder); + 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); const msUntilReminder = reminderTime.diff(now); const timeUntilReminder = humanizeDuration(msUntilReminder, { largest: 2, round: true });