From f36a63c23e612d858b916b651c553d0b7dbfcad9 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 1 Nov 2020 14:37:44 +0900 Subject: [PATCH] Improve reminder --- package.json | 2 +- src/modules/reminder/index.ts | 33 +++++++++++++++++++++++++++------ src/serifs.ts | 12 +++++++++++- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 809b5d0..42b9198 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "_v": "1.4.1", + "_v": "1.4.2", "main": "./built/index.js", "scripts": { "start": "node ./built", diff --git a/src/modules/reminder/index.ts b/src/modules/reminder/index.ts index dc1cccb..1bc16f9 100644 --- a/src/modules/reminder/index.ts +++ b/src/modules/reminder/index.ts @@ -2,8 +2,9 @@ import autobind from 'autobind-decorator'; import * as loki from 'lokijs'; import Module from '@/module'; import Message from '@/message'; -import serifs from '@/serifs'; +import serifs, { getSerif } from '@/serifs'; import { acct } from '@/utils/acct'; +import config from '@/config'; const NOTIFY_INTERVAL = 1000 * 60 * 60 * 12; @@ -37,6 +38,18 @@ export default class extends Module { private async mentionHook(msg: Message) { let text = msg.extractedText.toLowerCase(); if (!text.startsWith('remind') && !text.startsWith('todo')) return false; + + if (text.startsWith('reminds') || text.startsWith('todos')) { + const reminds = this.reminds.find({ + userId: msg.userId, + }); + + const getQuoteLink = id => `[${id}](${config.host}/notes/${id})`; + + msg.reply(serifs.reminder.reminds + '\n' + reminds.map(remind => `・${remind.thing ? remind.thing : getQuoteLink(remind.quoteId)}`).join('\n')); + return true; + } + if (text.match(/^(.+?)\s(.+)/)) { text = text.replace(/^(.+?)\s/, ''); } else { @@ -61,13 +74,21 @@ export default class extends Module { createdAt: Date.now(), }); - this.subscribeReply(msg.id, msg.isDm, msg.isDm ? msg.userId : msg.id, { + // メンションをsubscribe + this.subscribeReply(remind!.id, msg.isDm, msg.isDm ? msg.userId : msg.id, { id: remind!.id }); + if (msg.quoteId) { + // 引用元をsubscribe + this.subscribeReply(remind!.id, false, msg.quoteId, { + id: remind!.id + }); + } + // タイマーセット this.setTimeoutWithPersistence(NOTIFY_INTERVAL, { - id: msg.id, + id: remind!.id, }); return { @@ -89,13 +110,13 @@ export default class extends Module { return; } - const done = msg.includes(['done', 'やった']); - const cancel = msg.includes(['やめる']); + const done = msg.includes(['done', 'やった', 'やりました', 'はい']); + const cancel = msg.includes(['やめる', 'やめた', 'キャンセル']); if (done || cancel) { this.unsubscribeReply(key); this.reminds.remove(remind); - msg.reply(done ? serifs.reminder.done(msg.friend.name) : serifs.reminder.cancel); + msg.reply(done ? getSerif(serifs.reminder.done(msg.friend.name)) : serifs.reminder.cancel); return; } else { if (msg.isDm) this.unsubscribeReply(key); diff --git a/src/serifs.ts b/src/serifs.ts index 716da15..b6d4761 100644 --- a/src/serifs.ts +++ b/src/serifs.ts @@ -341,11 +341,21 @@ export default { reminder: { invalid: 'うーん...?', + reminds: 'やること一覧です!', + notify: (name) => name ? `${name}、これやりましたか?` : `これやりましたか?`, notifyWithThing: (thing, name) => name ? `${name}、「${thing}」やりましたか?` : `「${thing}」やりましたか?`, - done: (name) => name ? `よく出来ました、${name}♪` : `よく出来ました♪`, + done: (name) => name ? [ + `よく出来ました、${name}♪`, + `${name}、さすがですっ!`, + `${name}、えらすぎます...!`, + ] : [ + `よく出来ました♪`, + `さすがですっ!`, + `えらすぎます...!`, + ], cancel: `わかりました。`, },