From 53a07d0d06372b180ed825725de9d2b0322d7b5c Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 2 Sep 2018 23:40:03 +0900 Subject: [PATCH] Improve AI --- src/message-like.ts | 2 +- src/modules/core/index.ts | 2 +- src/utils/includes.ts | 6 +++--- src/utils/japanese.ts | 12 ++++++------ src/utils/or.ts | 22 +++++++++++++--------- torisetu.md | 1 + 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/message-like.ts b/src/message-like.ts index 34b63df..59a7f94 100644 --- a/src/message-like.ts +++ b/src/message-like.ts @@ -71,7 +71,7 @@ export default class MessageLike { return includes(this.text, words); } - public or = (words: string[]): boolean => { + public or = (words: (string | RegExp)[]): boolean => { return or(this.text, words); } } diff --git a/src/modules/core/index.ts b/src/modules/core/index.ts index fe1c1ff..bc7676b 100644 --- a/src/modules/core/index.ts +++ b/src/modules/core/index.ts @@ -225,7 +225,7 @@ export default class CoreModule implements IModule { } private hug = (msg: MessageLike): boolean => { - if (!msg.or(['ぎゅ'])) return false; + if (!msg.or(['ぎゅ', /^はぐ(し(て|よ|よう)?)?$/])) return false; // メッセージのみ if (!msg.isMessage) return true; diff --git a/src/utils/includes.ts b/src/utils/includes.ts index 3f66967..694b404 100644 --- a/src/utils/includes.ts +++ b/src/utils/includes.ts @@ -1,10 +1,10 @@ -import { hiraganaToKatagana, hankakuToZenkaku } from './japanese'; +import { katakanaToHiragana, hankakuToZenkaku } from './japanese'; export default function(text: string, words: string[]): boolean { if (text == null) return false; - text = hankakuToZenkaku(hiraganaToKatagana(text)); - words = words.map(word => hiraganaToKatagana(word)); + text = katakanaToHiragana(hankakuToZenkaku(text)); + words = words.map(word => katakanaToHiragana(word)); return words.some(word => text.includes(word)); } diff --git a/src/utils/japanese.ts b/src/utils/japanese.ts index 43ab538..a8ca01e 100644 --- a/src/utils/japanese.ts +++ b/src/utils/japanese.ts @@ -1,6 +1,12 @@ // Utilities for Japanese const kanaMap: string[][] = [ + ['ガ', 'ガ'], ['ギ', 'ギ'], ['グ', 'グ'], ['ゲ', 'ゲ'], ['ゴ', 'ゴ'], + ['ザ', 'ザ'], ['ジ', 'ジ'], ['ズ', 'ズ'], ['ゼ', 'ゼ'], ['ゾ', 'ゾ'], + ['ダ', 'ダ'], ['ヂ', 'ヂ'], ['ヅ', 'ヅ'], ['デ', 'デ'], ['ド', 'ド'], + ['バ', 'バ'], ['ビ', 'ビ'], ['ブ', 'ブ'], ['ベ', 'ベ'], ['ボ', 'ボ'], + ['パ', 'パ'], ['ピ', 'ピ'], ['プ', 'プ'], ['ペ', 'ペ'], ['ポ', 'ポ'], + ['ヴ', 'ヴ'], ['ヷ', 'ヷ'], ['ヺ', 'ヺ'], ['ア', 'ア'], ['イ', 'イ'], ['ウ', 'ウ'], ['エ', 'エ'], ['オ', 'オ'], ['カ', 'カ'], ['キ', 'キ'], ['ク', 'ク'], ['ケ', 'ケ'], ['コ', 'コ'], ['サ', 'サ'], ['シ', 'シ'], ['ス', 'ス'], ['セ', 'セ'], ['ソ', 'ソ'], @@ -11,12 +17,6 @@ const kanaMap: string[][] = [ ['ヤ', 'ヤ'], ['ユ', 'ユ'], ['ヨ', 'ヨ'], ['ラ', 'ラ'], ['リ', 'リ'], ['ル', 'ル'], ['レ', 'レ'], ['ロ', 'ロ'], ['ワ', 'ワ'], ['ヲ', 'ヲ'], ['ン', 'ン'], - ['ガ', 'ガ'], ['ギ', 'ギ'], ['グ', 'グ'], ['ゲ', 'ゲ'], ['ゴ', 'ゴ'], - ['ザ', 'ザ'], ['ジ', 'ジ'], ['ズ', 'ズ'], ['ゼ', 'ゼ'], ['ゾ', 'ゾ'], - ['ダ', 'ダ'], ['ヂ', 'ヂ'], ['ヅ', 'ヅ'], ['デ', 'デ'], ['ド', 'ド'], - ['バ', 'バ'], ['ビ', 'ビ'], ['ブ', 'ブ'], ['ベ', 'ベ'], ['ボ', 'ボ'], - ['パ', 'パ'], ['ピ', 'ピ'], ['プ', 'プ'], ['ペ', 'ペ'], ['ポ', 'ポ'], - ['ヴ', 'ヴ'], ['ヷ', 'ヷ'], ['ヺ', 'ヺ'], ['ァ', 'ァ'], ['ィ', 'ィ'], ['ゥ', 'ゥ'], ['ェ', 'ェ'], ['ォ', 'ォ'], ['ッ', 'ッ'], ['ャ', 'ャ'], ['ュ', 'ュ'], ['ョ', 'ョ'], ['ー', 'ー'] diff --git a/src/utils/or.ts b/src/utils/or.ts index 3358f4f..27102fa 100644 --- a/src/utils/or.ts +++ b/src/utils/or.ts @@ -1,10 +1,10 @@ -import { hiraganaToKatagana, hankakuToZenkaku } from './japanese'; +import { hankakuToZenkaku, katakanaToHiragana } from './japanese'; -export default function(text: string, words: string[]): boolean { +export default function(text: string, words: (string | RegExp)[]): boolean { if (text == null) return false; - text = hankakuToZenkaku(hiraganaToKatagana(text)); - words = words.map(word => hiraganaToKatagana(word)); + text = katakanaToHiragana(hankakuToZenkaku(text)); + words = words.map(word => typeof word == 'string' ? katakanaToHiragana(word) : word); return words.some(word => { /** @@ -19,16 +19,20 @@ export default function(text: string, words: string[]): boolean { // ただそのままだと「セーラー」などの本来「ー」が含まれているワードも「ー」が除去され // 「セーラ」になり、「セーラー」を期待している場合はマッチしなくなり期待する動作にならなくなるので、 // 期待するワードの末尾にもともと「ー」が含まれている場合は(対象のテキストの「ー」をすべて除去した後に)「ー」を付けてあげる - .replace(/ー+$/, '') + (word[word.length - 1] == 'ー' ? 'ー' : '') - .replace(/ッ+$/, '') + .replace(/ー+$/, '') + ((typeof word == 'string' && word[word.length - 1] == 'ー') ? 'ー' : '') + .replace(/っ+$/, '') .replace(/。$/, '') - .replace(/デス$/, '') + .replace(/です$/, '') .replace(/^藍/, '') - .replace(/^チャン/, '') + .replace(/^ちゃん/, '') .replace(/、+$/, ''); } - return (text == word) || (cleanup(text) == word); + if (typeof word == 'string') { + return (text == word) || (cleanup(text) == word); + } else { + return (word.test(text)) || (word.test(cleanup(text))); + } }); } diff --git a/torisetu.md b/torisetu.md index b15524c..a088928 100644 --- a/torisetu.md +++ b/torisetu.md @@ -52,6 +52,7 @@ PONGを返します。生存確認にどうぞ ### その他反応するフレーズ * かわいい * 好き (メッセージのみ) +* ぎゅー (メッセージのみ) * 罵って (メッセージのみ) * 踏んで (メッセージのみ)