mirror of
https://github.com/syuilo/ai.git
synced 2024-11-09 15:38:00 +00:00
Improve AI
This commit is contained in:
parent
9872ef158b
commit
53a07d0d06
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
// Utilities for Japanese
|
||||
|
||||
const kanaMap: string[][] = [
|
||||
['ガ', 'ガ'], ['ギ', 'ギ'], ['グ', 'グ'], ['ゲ', 'ゲ'], ['ゴ', 'ゴ'],
|
||||
['ザ', 'ザ'], ['ジ', 'ジ'], ['ズ', 'ズ'], ['ゼ', 'ゼ'], ['ゾ', 'ゾ'],
|
||||
['ダ', 'ダ'], ['ヂ', 'ヂ'], ['ヅ', 'ヅ'], ['デ', 'デ'], ['ド', 'ド'],
|
||||
['バ', 'バ'], ['ビ', 'ビ'], ['ブ', 'ブ'], ['ベ', 'ベ'], ['ボ', 'ボ'],
|
||||
['パ', 'パ'], ['ピ', 'ピ'], ['プ', 'プ'], ['ペ', 'ペ'], ['ポ', 'ポ'],
|
||||
['ヴ', 'ヴ'], ['ヷ', 'ヷ'], ['ヺ', 'ヺ'],
|
||||
['ア', 'ア'], ['イ', 'イ'], ['ウ', 'ウ'], ['エ', 'エ'], ['オ', 'オ'],
|
||||
['カ', 'カ'], ['キ', 'キ'], ['ク', 'ク'], ['ケ', 'ケ'], ['コ', 'コ'],
|
||||
['サ', 'サ'], ['シ', 'シ'], ['ス', 'ス'], ['セ', 'セ'], ['ソ', 'ソ'],
|
||||
|
@ -11,12 +17,6 @@ const kanaMap: string[][] = [
|
|||
['ヤ', 'ヤ'], ['ユ', 'ユ'], ['ヨ', 'ヨ'],
|
||||
['ラ', 'ラ'], ['リ', 'リ'], ['ル', 'ル'], ['レ', 'レ'], ['ロ', 'ロ'],
|
||||
['ワ', 'ワ'], ['ヲ', 'ヲ'], ['ン', 'ン'],
|
||||
['ガ', 'ガ'], ['ギ', 'ギ'], ['グ', 'グ'], ['ゲ', 'ゲ'], ['ゴ', 'ゴ'],
|
||||
['ザ', 'ザ'], ['ジ', 'ジ'], ['ズ', 'ズ'], ['ゼ', 'ゼ'], ['ゾ', 'ゾ'],
|
||||
['ダ', 'ダ'], ['ヂ', 'ヂ'], ['ヅ', 'ヅ'], ['デ', 'デ'], ['ド', 'ド'],
|
||||
['バ', 'バ'], ['ビ', 'ビ'], ['ブ', 'ブ'], ['ベ', 'ベ'], ['ボ', 'ボ'],
|
||||
['パ', 'パ'], ['ピ', 'ピ'], ['プ', 'プ'], ['ペ', 'ペ'], ['ポ', 'ポ'],
|
||||
['ヴ', 'ヴ'], ['ヷ', 'ヷ'], ['ヺ', 'ヺ'],
|
||||
['ァ', 'ァ'], ['ィ', 'ィ'], ['ゥ', 'ゥ'], ['ェ', 'ェ'], ['ォ', 'ォ'],
|
||||
['ッ', 'ッ'], ['ャ', 'ャ'], ['ュ', 'ュ'], ['ョ', 'ョ'],
|
||||
['ー', 'ー']
|
||||
|
|
|
@ -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(/、+$/, '');
|
||||
}
|
||||
|
||||
if (typeof word == 'string') {
|
||||
return (text == word) || (cleanup(text) == word);
|
||||
} else {
|
||||
return (word.test(text)) || (word.test(cleanup(text)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ PONGを返します。生存確認にどうぞ
|
|||
### その他反応するフレーズ
|
||||
* かわいい
|
||||
* 好き (メッセージのみ)
|
||||
* ぎゅー (メッセージのみ)
|
||||
* 罵って (メッセージのみ)
|
||||
* 踏んで (メッセージのみ)
|
||||
|
||||
|
|
Loading…
Reference in a new issue