Improve AI

This commit is contained in:
syuilo 2018-09-02 22:23:10 +09:00
parent ee82078f79
commit 2894d45aa7
5 changed files with 48 additions and 0 deletions

View file

@ -2,6 +2,7 @@ import 藍 from './ai';
import Friend from './friend'; import Friend from './friend';
import { User } from './misskey/user'; import { User } from './misskey/user';
import includes from './utils/includes'; import includes from './utils/includes';
import includes from './utils/or';
const delay = require('timeout-as-promise'); const delay = require('timeout-as-promise');
export default class MessageLike { export default class MessageLike {
@ -47,6 +48,8 @@ export default class MessageLike {
} }
public reply = async (text: string, cw?: string) => { public reply = async (text: string, cw?: string) => {
if (text == null) return;
console.log(`sending reply of ${this.id} ...`); console.log(`sending reply of ${this.id} ...`);
await delay(2000); await delay(2000);
@ -67,4 +70,8 @@ export default class MessageLike {
public includes = (words: string[]): boolean => { public includes = (words: string[]): boolean => {
return includes(this.text, words); return includes(this.text, words);
} }
public or = (words: string[]): boolean => {
return or(this.text, words);
}
} }

View file

@ -32,6 +32,7 @@ export default class CoreModule implements IModule {
this.greet(msg) || this.greet(msg) ||
this.nadenade(msg) || this.nadenade(msg) ||
this.kawaii(msg) || this.kawaii(msg) ||
this.suki(msg) ||
this.humu(msg) || this.humu(msg) ||
this.batou(msg) || this.batou(msg) ||
this.ponkotu(msg) this.ponkotu(msg)
@ -208,6 +209,20 @@ export default class CoreModule implements IModule {
return true; 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 => { private humu = (msg: MessageLike): boolean => {
if (!msg.includes(['踏んで'])) return false; if (!msg.includes(['踏んで'])) return false;

View file

@ -46,6 +46,14 @@ export default {
hate: '…ありがとうございます' hate: '…ありがとうございます'
}, },
suki: {
normal: 'えっ… ありがとうございます…♪',
love: name => `私も${name}のこと好きですよ♪`,
hate: null
},
humu: { humu: {
normal: 'え、えっと…… ふみふみ……… どうですか…?', normal: 'え、えっと…… ふみふみ……… どうですか…?',

17
src/utils/or.ts Normal file
View file

@ -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(/(です|デス)$/, '');
}

View file

@ -51,6 +51,7 @@ PONGを返します。生存確認にどうぞ
### その他反応するフレーズ ### その他反応するフレーズ
* かわいい * かわいい
* 好き (メッセージのみ)
* 罵って (メッセージのみ) * 罵って (メッセージのみ)
* 踏んで (メッセージのみ) * 踏んで (メッセージのみ)