Skip to content

Commit

Permalink
/learn command
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed May 13, 2021
1 parent ad1102b commit d760273
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/modules/keyword/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Module from '@/module';
import config from '@/config';
import serifs from '@/serifs';
import { mecab } from './mecab';
import Message from '@/message';

function kanaToHira(str: string) {
return str.replace(/[\u30a1-\u30f6]/g, match => {
Expand All @@ -30,7 +31,9 @@ export default class extends Module {

setInterval(this.learn, 1000 * 60 * (config.keywordInterval || 60));

return {};
return {
mentionHook: this.mentionHook,
};
}

@autobind
Expand All @@ -48,7 +51,7 @@ export default class extends Module {

for (const note of interestedNotes) {
const tokens = await mecab(note.text, config.mecab, config.mecabDic);
const keywordsInThisNote = tokens.filter(token => token[2] == '固有名詞' && token[8] != null);
const keywordsInThisNote = tokens.filter(token => token[1] == '名詞' && token[8] != null);
keywords = keywords.concat(keywordsInThisNote);
}

Expand Down Expand Up @@ -78,4 +81,17 @@ export default class extends Module {
text: text
});
}

@autobind
private async mentionHook(msg: Message) {
if (!msg.or(['/learn']) || msg.user.username !== config.master) {
return false;
} else {
this.log('Manualy learn requested');
}

this.learn();

return true;
}
}

0 comments on commit d760273

Please sign in to comment.