Improve reminder

This commit is contained in:
syuilo 2020-11-01 14:37:44 +09:00
parent 4482cceffe
commit f36a63c23e
3 changed files with 39 additions and 8 deletions

View file

@ -1,5 +1,5 @@
{
"_v": "1.4.1",
"_v": "1.4.2",
"main": "./built/index.js",
"scripts": {
"start": "node ./built",

View file

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

View file

@ -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: `わかりました。`,
},