This commit is contained in:
syuilo 2018-08-13 18:17:38 +09:00
parent 6e2c87cdfc
commit b17a828895
4 changed files with 65 additions and 67 deletions

80
package-lock.json generated
View file

@ -3,24 +3,11 @@
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"@types/doublearray": {
"version": "0.0.29",
"resolved": "https://registry.npmjs.org/@types/doublearray/-/doublearray-0.0.29.tgz",
"integrity": "sha1-PL5rthavUkZI1EC733hOnB40AJ0="
},
"@types/events": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
"integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA=="
},
"@types/kuromoji": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/@types/kuromoji/-/kuromoji-0.1.0.tgz",
"integrity": "sha512-gEAkIk4qxsK5ry64fCYFGjb3a+NQVOiNOT6fz0OyXizob+yewF4GFVX23GG4YNwKM2hB0J6fnMPMffFK+cYHnw==",
"requires": {
"@types/doublearray": "*"
}
},
"@types/lokijs": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/@types/lokijs/-/lokijs-1.5.2.tgz",
@ -77,6 +64,21 @@
"color-convert": "^1.9.0"
}
},
"array-filter": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/array-filter/-/array-filter-0.0.1.tgz",
"integrity": "sha1-fajPLiZijtcygDWB/SH2fKzS7uw="
},
"array-map": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/array-map/-/array-map-0.0.0.tgz",
"integrity": "sha1-iKK6tz0c97zVwbEYoAP2b2ZfpmI="
},
"array-reduce": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/array-reduce/-/array-reduce-0.0.0.tgz",
"integrity": "sha1-FziZ0//Rx9k4PkR5Ul2+J4yrXys="
},
"arrify": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz",
@ -95,14 +97,6 @@
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
"integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU="
},
"async": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz",
"integrity": "sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==",
"requires": {
"lodash": "^4.17.10"
}
},
"async-limiter": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
@ -201,11 +195,6 @@
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA=="
},
"doublearray": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/doublearray/-/doublearray-0.0.2.tgz",
"integrity": "sha1-Yxhv6NNEEydtNiH2qg7F954ifvk="
},
"ecc-jsbn": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
@ -329,6 +318,11 @@
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
},
"jsonify": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz",
"integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM="
},
"jsprim": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
@ -340,16 +334,6 @@
"verror": "1.10.0"
}
},
"kuromoji": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/kuromoji/-/kuromoji-0.1.2.tgz",
"integrity": "sha512-V0dUf+C2LpcPEXhoHLMAop/bOht16Dyr+mDiIE39yX3vqau7p80De/koFqpiTcL1zzdZlc3xuHZ8u5gjYRfFaQ==",
"requires": {
"async": "^2.0.1",
"doublearray": "0.0.2",
"zlibjs": "^0.3.1"
}
},
"lodash": {
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
@ -365,6 +349,14 @@
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.4.tgz",
"integrity": "sha512-0Dab5btKVPhibSalc9QGXb559ED7G7iLjFXBaj9Wq8O3vorueR5K5jaE3hkG6ZQINyhA/JgG6Qk4qdFQjsYV6g=="
},
"mecab-async": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/mecab-async/-/mecab-async-0.1.2.tgz",
"integrity": "sha512-/hruCkDWB+jM1bYMFM53HLzG6ENKVtC3n45qD1qxQUW99pz3rrsU4HKEqlYPVCr+/wv0ErBR0vNlVwAv92f2Wg==",
"requires": {
"shell-quote": "*"
}
},
"mime-db": {
"version": "1.35.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.35.0.tgz",
@ -517,6 +509,17 @@
"resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-2.4.3.tgz",
"integrity": "sha1-JDhQTa0zkXMUv/GKxNeU8W1qrsw="
},
"shell-quote": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.6.1.tgz",
"integrity": "sha1-9HgZSczkAmlxJ0MOo7PFR29IF2c=",
"requires": {
"array-filter": "~0.0.0",
"array-map": "~0.0.0",
"array-reduce": "~0.0.0",
"jsonify": "~0.0.0"
}
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
@ -635,11 +638,6 @@
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz",
"integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo="
},
"zlibjs": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/zlibjs/-/zlibjs-0.3.1.tgz",
"integrity": "sha1-UBl+2yihxCymWcyLTmqd3W1ERVQ="
}
}
}

View file

@ -5,14 +5,13 @@
"build": "tsc"
},
"dependencies": {
"@types/kuromoji": "0.1.0",
"@types/lokijs": "1.5.2",
"@types/node": "10.0.5",
"@types/promise-retry": "1.1.2",
"@types/seedrandom": "2.4.27",
"@types/ws": "5.1.2",
"kuromoji": "0.1.2",
"lokijs": "1.5.5",
"mecab-async": "0.1.2",
"misskey-reversi": "0.0.5",
"promise-retry": "1.1.1",
"reconnecting-websocket": "4.0.0-rc5",

View file

@ -5,7 +5,7 @@ type Config = {
apiUrl: string;
keywordEnabled: boolean;
reversiEnabled: boolean;
mecabDic?: string;
mecab?: string;
};
const config = require('../config.json');

View file

@ -1,57 +1,58 @@
import from '../../ai';
import IModule from '../../module';
import config from '../../config';
import * as kuromoji from 'kuromoji';
import MessageLike from '../../message-like';
import serifs from '../../serifs';
const MeCab = require('mecab-async');
export default class KeywordModule implements IModule {
public name = 'keyword';
private ai: ;
private tokenizer: kuromoji.Tokenizer<kuromoji.IpadicFeatures>;
private tokenizer: any;
public install = (ai: ) => {
this.ai = ai;
kuromoji.builder({
dicPath: config.mecabDic
}).build((err, tokenizer) => {
if (err) {
console.error(err);
} else {
this.tokenizer = tokenizer;
this.tokenizer = new MeCab();
this.tokenizer.command = config.mecab;
setTimeout(this.say, 1000 * 60 * 60);
}
});
}
private say = async () => {
private say = async (msg?: MessageLike) => {
const tl = await this.ai.api('notes/local-timeline');
const interestedNotes = tl.filter(note => note.userId !== this.ai.account.id && note.text != null);
let keywords: kuromoji.IpadicFeatures[] = [];
let keywords: string[][] = [];
interestedNotes.forEach(note => {
const tokens = this.tokenizer.tokenize(note.text);
const keywordsInThisNote = tokens.filter(token => token.pos_detail_1 == '固有名詞');
await Promise.all(interestedNotes.map(note => new Promise((res, rej) => {
this.tokenizer.parse(note.text, (err, tokens) => {
const keywordsInThisNote = tokens.filter(token => token[2] == '固有名詞');
keywords = keywords.concat(keywordsInThisNote);
res();
});
})));
console.log(keywords);
const keyword = keywords[Math.floor(Math.random() * keywords.length)];
this.ai.post(serifs.KEYWORD
.replace('{word}', keyword.surface_form)
.replace('{reading}', keyword.reading));
const text = serifs.KEYWORD
.replace('{word}', keyword[0])
.replace('{reading}', keyword[8])
if (msg) {
msg.reply(text);
} else {
this.ai.post(text);
}
}
public onMention = (msg: MessageLike) => {
if (msg.user.isAdmin && msg.text && msg.text.includes('なんか言って')) {
this.say();
this.say(msg);
return true;
} else {
return false;