mirror of
https://github.com/syuilo/ai.git
synced 2024-11-09 23:48:01 +00:00
✌️
This commit is contained in:
parent
6e2c87cdfc
commit
b17a828895
80
package-lock.json
generated
80
package-lock.json
generated
|
@ -3,24 +3,11 @@
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/doublearray": {
|
|
||||||
"version": "0.0.29",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/doublearray/-/doublearray-0.0.29.tgz",
|
|
||||||
"integrity": "sha1-PL5rthavUkZI1EC733hOnB40AJ0="
|
|
||||||
},
|
|
||||||
"@types/events": {
|
"@types/events": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
|
||||||
"integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA=="
|
"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": {
|
"@types/lokijs": {
|
||||||
"version": "1.5.2",
|
"version": "1.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/lokijs/-/lokijs-1.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/lokijs/-/lokijs-1.5.2.tgz",
|
||||||
|
@ -77,6 +64,21 @@
|
||||||
"color-convert": "^1.9.0"
|
"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": {
|
"arrify": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
|
||||||
"integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU="
|
"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": {
|
"async-limiter": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
|
||||||
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA=="
|
"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": {
|
"ecc-jsbn": {
|
||||||
"version": "0.1.2",
|
"version": "0.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
|
||||||
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
|
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
|
||||||
},
|
},
|
||||||
|
"jsonify": {
|
||||||
|
"version": "0.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz",
|
||||||
|
"integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM="
|
||||||
|
},
|
||||||
"jsprim": {
|
"jsprim": {
|
||||||
"version": "1.4.1",
|
"version": "1.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
|
||||||
|
@ -340,16 +334,6 @@
|
||||||
"verror": "1.10.0"
|
"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": {
|
"lodash": {
|
||||||
"version": "4.17.10",
|
"version": "4.17.10",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.4.tgz",
|
||||||
"integrity": "sha512-0Dab5btKVPhibSalc9QGXb559ED7G7iLjFXBaj9Wq8O3vorueR5K5jaE3hkG6ZQINyhA/JgG6Qk4qdFQjsYV6g=="
|
"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": {
|
"mime-db": {
|
||||||
"version": "1.35.0",
|
"version": "1.35.0",
|
||||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.35.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-2.4.3.tgz",
|
||||||
"integrity": "sha1-JDhQTa0zkXMUv/GKxNeU8W1qrsw="
|
"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": {
|
"source-map": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||||
|
@ -635,11 +638,6 @@
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz",
|
||||||
"integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo="
|
"integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo="
|
||||||
},
|
|
||||||
"zlibjs": {
|
|
||||||
"version": "0.3.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/zlibjs/-/zlibjs-0.3.1.tgz",
|
|
||||||
"integrity": "sha1-UBl+2yihxCymWcyLTmqd3W1ERVQ="
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,14 +5,13 @@
|
||||||
"build": "tsc"
|
"build": "tsc"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/kuromoji": "0.1.0",
|
|
||||||
"@types/lokijs": "1.5.2",
|
"@types/lokijs": "1.5.2",
|
||||||
"@types/node": "10.0.5",
|
"@types/node": "10.0.5",
|
||||||
"@types/promise-retry": "1.1.2",
|
"@types/promise-retry": "1.1.2",
|
||||||
"@types/seedrandom": "2.4.27",
|
"@types/seedrandom": "2.4.27",
|
||||||
"@types/ws": "5.1.2",
|
"@types/ws": "5.1.2",
|
||||||
"kuromoji": "0.1.2",
|
|
||||||
"lokijs": "1.5.5",
|
"lokijs": "1.5.5",
|
||||||
|
"mecab-async": "0.1.2",
|
||||||
"misskey-reversi": "0.0.5",
|
"misskey-reversi": "0.0.5",
|
||||||
"promise-retry": "1.1.1",
|
"promise-retry": "1.1.1",
|
||||||
"reconnecting-websocket": "4.0.0-rc5",
|
"reconnecting-websocket": "4.0.0-rc5",
|
||||||
|
|
|
@ -5,7 +5,7 @@ type Config = {
|
||||||
apiUrl: string;
|
apiUrl: string;
|
||||||
keywordEnabled: boolean;
|
keywordEnabled: boolean;
|
||||||
reversiEnabled: boolean;
|
reversiEnabled: boolean;
|
||||||
mecabDic?: string;
|
mecab?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const config = require('../config.json');
|
const config = require('../config.json');
|
||||||
|
|
|
@ -1,57 +1,58 @@
|
||||||
import 藍 from '../../ai';
|
import 藍 from '../../ai';
|
||||||
import IModule from '../../module';
|
import IModule from '../../module';
|
||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import * as kuromoji from 'kuromoji';
|
|
||||||
import MessageLike from '../../message-like';
|
import MessageLike from '../../message-like';
|
||||||
import serifs from '../../serifs';
|
import serifs from '../../serifs';
|
||||||
|
const MeCab = require('mecab-async');
|
||||||
|
|
||||||
export default class KeywordModule implements IModule {
|
export default class KeywordModule implements IModule {
|
||||||
public name = 'keyword';
|
public name = 'keyword';
|
||||||
|
|
||||||
private ai: 藍;
|
private ai: 藍;
|
||||||
private tokenizer: kuromoji.Tokenizer<kuromoji.IpadicFeatures>;
|
private tokenizer: any;
|
||||||
|
|
||||||
public install = (ai: 藍) => {
|
public install = (ai: 藍) => {
|
||||||
this.ai = ai;
|
this.ai = ai;
|
||||||
|
|
||||||
kuromoji.builder({
|
this.tokenizer = new MeCab();
|
||||||
dicPath: config.mecabDic
|
this.tokenizer.command = config.mecab;
|
||||||
}).build((err, tokenizer) => {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
} else {
|
|
||||||
this.tokenizer = tokenizer;
|
|
||||||
|
|
||||||
setTimeout(this.say, 1000 * 60 * 60);
|
setTimeout(this.say, 1000 * 60 * 60);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private say = async () => {
|
private say = async (msg?: MessageLike) => {
|
||||||
const tl = await this.ai.api('notes/local-timeline');
|
const tl = await this.ai.api('notes/local-timeline');
|
||||||
|
|
||||||
const interestedNotes = tl.filter(note => note.userId !== this.ai.account.id && note.text != null);
|
const interestedNotes = tl.filter(note => note.userId !== this.ai.account.id && note.text != null);
|
||||||
|
|
||||||
let keywords: kuromoji.IpadicFeatures[] = [];
|
let keywords: string[][] = [];
|
||||||
|
|
||||||
interestedNotes.forEach(note => {
|
await Promise.all(interestedNotes.map(note => new Promise((res, rej) => {
|
||||||
const tokens = this.tokenizer.tokenize(note.text);
|
this.tokenizer.parse(note.text, (err, tokens) => {
|
||||||
const keywordsInThisNote = tokens.filter(token => token.pos_detail_1 == '固有名詞');
|
const keywordsInThisNote = tokens.filter(token => token[2] == '固有名詞');
|
||||||
keywords = keywords.concat(keywordsInThisNote);
|
keywords = keywords.concat(keywordsInThisNote);
|
||||||
|
res();
|
||||||
});
|
});
|
||||||
|
})));
|
||||||
|
|
||||||
console.log(keywords);
|
console.log(keywords);
|
||||||
|
|
||||||
const keyword = keywords[Math.floor(Math.random() * keywords.length)];
|
const keyword = keywords[Math.floor(Math.random() * keywords.length)];
|
||||||
|
|
||||||
this.ai.post(serifs.KEYWORD
|
const text = serifs.KEYWORD
|
||||||
.replace('{word}', keyword.surface_form)
|
.replace('{word}', keyword[0])
|
||||||
.replace('{reading}', keyword.reading));
|
.replace('{reading}', keyword[8])
|
||||||
|
|
||||||
|
if (msg) {
|
||||||
|
msg.reply(text);
|
||||||
|
} else {
|
||||||
|
this.ai.post(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public onMention = (msg: MessageLike) => {
|
public onMention = (msg: MessageLike) => {
|
||||||
if (msg.user.isAdmin && msg.text && msg.text.includes('なんか言って')) {
|
if (msg.user.isAdmin && msg.text && msg.text.includes('なんか言って')) {
|
||||||
this.say();
|
this.say(msg);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue