diff --git a/src/utils/or.ts b/src/utils/or.ts index 27102fa..cc951de 100644 --- a/src/utils/or.ts +++ b/src/utils/or.ts @@ -12,20 +12,24 @@ export default function(text: string, words: (string | RegExp)[]): boolean { * 例えば「藍ちゃん好き!」のようなテキストを「好き」にする */ function cleanup(text: string): string { - return text.trim() + text = text.trim() .replace(/[!!]+$/, '') + .replace(/っ+$/, '') // 末尾の ー を除去 // 例えば「おはよー」を「おはよ」にする // ただそのままだと「セーラー」などの本来「ー」が含まれているワードも「ー」が除去され // 「セーラ」になり、「セーラー」を期待している場合はマッチしなくなり期待する動作にならなくなるので、 // 期待するワードの末尾にもともと「ー」が含まれている場合は(対象のテキストの「ー」をすべて除去した後に)「ー」を付けてあげる - .replace(/ー+$/, '') + ((typeof word == 'string' && word[word.length - 1] == 'ー') ? 'ー' : '') - .replace(/っ+$/, '') + .replace(/ー+$/, '') + ((typeof word == 'string' && word[word.length - 1] == 'ー') ? 'ー' : ''); + + text = text .replace(/。$/, '') .replace(/です$/, '') .replace(/^藍/, '') .replace(/^ちゃん/, '') .replace(/、+$/, ''); + + return text; } if (typeof word == 'string') {