From 2894d45aa7db3c909e3ced6fef2160843741b513 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 2 Sep 2018 22:23:10 +0900 Subject: [PATCH] Improve AI --- src/message-like.ts | 7 +++++++ src/modules/core/index.ts | 15 +++++++++++++++ src/serifs.ts | 8 ++++++++ src/utils/or.ts | 17 +++++++++++++++++ torisetu.md | 1 + 5 files changed, 48 insertions(+) create mode 100644 src/utils/or.ts diff --git a/src/message-like.ts b/src/message-like.ts index b720029..f897cd7 100644 --- a/src/message-like.ts +++ b/src/message-like.ts @@ -2,6 +2,7 @@ import 藍 from './ai'; import Friend from './friend'; import { User } from './misskey/user'; import includes from './utils/includes'; +import includes from './utils/or'; const delay = require('timeout-as-promise'); export default class MessageLike { @@ -47,6 +48,8 @@ export default class MessageLike { } public reply = async (text: string, cw?: string) => { + if (text == null) return; + console.log(`sending reply of ${this.id} ...`); await delay(2000); @@ -67,4 +70,8 @@ export default class MessageLike { public includes = (words: string[]): boolean => { return includes(this.text, words); } + + public or = (words: string[]): boolean => { + return or(this.text, words); + } } diff --git a/src/modules/core/index.ts b/src/modules/core/index.ts index 14a7a26..1cdc46a 100644 --- a/src/modules/core/index.ts +++ b/src/modules/core/index.ts @@ -32,6 +32,7 @@ export default class CoreModule implements IModule { this.greet(msg) || this.nadenade(msg) || this.kawaii(msg) || + this.suki(msg) || this.humu(msg) || this.batou(msg) || this.ponkotu(msg) @@ -208,6 +209,20 @@ export default class CoreModule implements IModule { return true; } + private suki = (msg: MessageLike): boolean => { + if (!msg.or(['好き', 'すき'])) return false; + + // メッセージのみ + if (!msg.isMessage) return true; + + msg.reply( + msg.friend.love >= 5 ? serifs.core.suki.love : + msg.friend.love <= -3 ? serifs.core.suki.hate : + serifs.core.suki.normal); + + return true; + } + private humu = (msg: MessageLike): boolean => { if (!msg.includes(['踏んで'])) return false; diff --git a/src/serifs.ts b/src/serifs.ts index 00d0b0b..f7f7ae4 100644 --- a/src/serifs.ts +++ b/src/serifs.ts @@ -46,6 +46,14 @@ export default { hate: '…ありがとうございます' }, + suki: { + normal: 'えっ… ありがとうございます…♪', + + love: name => `私も${name}のこと好きですよ♪`, + + hate: null + }, + humu: { normal: 'え、えっと…… ふみふみ……… どうですか…?', diff --git a/src/utils/or.ts b/src/utils/or.ts new file mode 100644 index 0000000..0a871b0 --- /dev/null +++ b/src/utils/or.ts @@ -0,0 +1,17 @@ +import { hiraganaToKatagana, hankakuToZenkaku } from './japanese'; + +export default function(text: string, words: string[]): boolean { + if (text == null) return false; + + text = cleanup(hankakuToZenkaku(hiraganaToKatagana(text))); + words = words.map(word => hiraganaToKatagana(word)); + + return words.some(word => text == word); +} + +function cleanup(text: string): string { + return text.trim() + .replace(/[!!]+$/, '') + .replace(/。$/, '') + .replace(/(です|デス)$/, ''); +} diff --git a/torisetu.md b/torisetu.md index 15da087..b15524c 100644 --- a/torisetu.md +++ b/torisetu.md @@ -51,6 +51,7 @@ PONGを返します。生存確認にどうぞ ### その他反応するフレーズ * かわいい +* 好き (メッセージのみ) * 罵って (メッセージのみ) * 踏んで (メッセージのみ)