From 6a43a55b0b322c6dd862abafdafcecf45fb540df Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 31 Oct 2020 12:24:30 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=98=E3=82=83=E3=82=93=E3=81=91=E3=82=93?= =?UTF-8?q?=E9=AB=98=E9=80=9F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/emoji-react/index.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/modules/emoji-react/index.ts b/src/modules/emoji-react/index.ts index da00a9a..1bac52c 100644 --- a/src/modules/emoji-react/index.ts +++ b/src/modules/emoji-react/index.ts @@ -1,5 +1,6 @@ import autobind from 'autobind-decorator'; import { parse } from 'twemoji-parser'; +const delay = require('timeout-as-promise'); import { Note } from '@/misskey/note'; import Module from '@/module'; @@ -25,13 +26,14 @@ export default class extends Module { if (note.text == null) return; if (note.text.includes('@')) return; // (自分または他人問わず)メンションっぽかったらreject - const react = (reaction: string) => { - setTimeout(() => { - this.ai.api('notes/reactions/create', { - noteId: note.id, - reaction: reaction - }); - }, 1500); + const react = async (reaction: string, immediate = false) => { + if (!immediate) { + await delay(1500); + } + this.ai.api('notes/reactions/create', { + noteId: note.id, + reaction: reaction + }); }; const customEmojis = note.text.match(/:([^\n:]+?):/g); @@ -54,9 +56,9 @@ export default class extends Module { let reaction = emojis[0]; switch (reaction) { - case '✊': reaction = '🖐'; break; - case '✌': reaction = '✊'; break; - case '🖐': reaction = '✌'; break; + case '✊': return react('🖐', true); + case '✌': return react('✊', true); + case '🖐': return react('✌', true); } return react(reaction);