This commit is contained in:
syuilo 2018-08-13 18:26:45 +09:00
parent 73c8874749
commit 0b665efb7d

View file

@ -5,6 +5,13 @@ import MessageLike from '../../message-like';
import serifs from '../../serifs'; import serifs from '../../serifs';
const MeCab = require('mecab-async'); const MeCab = require('mecab-async');
function kanaToHira(str: string) {
return str.replace(/[\u30a1-\u30f6]/g, match => {
const chr = match.charCodeAt(0) - 0x60;
return String.fromCharCode(chr);
});
}
export default class KeywordModule implements IModule { export default class KeywordModule implements IModule {
public name = 'keyword'; public name = 'keyword';
@ -41,7 +48,7 @@ export default class KeywordModule implements IModule {
const text = serifs.KEYWORD const text = serifs.KEYWORD
.replace('{word}', keyword[0]) .replace('{word}', keyword[0])
.replace('{reading}', keyword[8]) .replace('{reading}', kanaToHira(keyword[8]))
if (msg) { if (msg) {
msg.reply(text); msg.reply(text);
@ -51,7 +58,10 @@ export default class KeywordModule implements IModule {
} }
public onMention = (msg: MessageLike) => { public onMention = (msg: MessageLike) => {
if (msg.user.isAdmin && msg.text && msg.text.includes('なんか言って')) { if (msg.user.isAdmin && msg.isMessage && msg.text && msg.text.includes('なんか皆に言って')) {
this.say(msg);
return true;
} else if (msg.text && msg.text.includes('なんか言って')) {
this.say(msg); this.say(msg);
return true; return true;
} else { } else {