From 83068eb8ffdedbf4e7c93156a4369f9891dc69d2 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Fri, 11 Feb 2022 00:16:53 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A8=80=E8=91=89=E3=81=AE=E6=84=8F=E5=91=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/dic/index.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/modules/dic/index.ts diff --git a/src/modules/dic/index.ts b/src/modules/dic/index.ts new file mode 100644 index 0000000..29d2dce --- /dev/null +++ b/src/modules/dic/index.ts @@ -0,0 +1,32 @@ +import autobind from 'autobind-decorator'; +import Module from '@/module'; +import Message from '@/message'; + +export default class extends Module { + public readonly name = 'dic'; + + @autobind + public install() { + return { + mentionHook: this.mentionHook + }; + } + + @autobind + private async mentionHook(msg: Message) { + if (msg.text && msg.text.includes('って何')) { + // msg.textのうち、「の意味は」の直前で、「@ai」よりも後の物を抽出 + const dic_prefix = "https://www.weblio.jp/content/"; + const raw_word = msg.text.split('って何')[0].split('@ai_dev')[1].trim(); + // スペースがある場合は、半角スペースを除去 + const word = raw_word.replace(/\s/g, ''); + const url = dic_prefix + encodeURIComponent(word); + msg.reply(`こんな意味っぽい?> [${word}](${url})`, { + immediate: true + }); + return true; + } else { + return false; + } + } +}