2019-07-28 01:52:06 +09:00
|
|
|
const { useTokenize } = require("./util/morpheme");
|
|
|
|
const random = require("./util/random");
|
|
|
|
const tellme = require("./util/tellme");
|
|
|
|
|
|
|
|
// ときどきうんちくを語ります
|
|
|
|
|
|
|
|
module.exports = [
|
|
|
|
/[^\x01-\x7e]{4,}/,
|
|
|
|
async ({ context, say }) => {
|
|
|
|
if (random([...Array(15).keys()]) !== 0) return;
|
|
|
|
try {
|
|
|
|
const tokenize = await useTokenize();
|
|
|
|
const words = tokenize(context.matches[0])
|
|
|
|
.filter(({ pos }) => pos === "名詞")
|
|
|
|
.map(({ surface_form }) => surface_form)
|
2020-04-09 00:16:46 +09:00
|
|
|
.filter((t) => !/^[\u3040-\u309F]$/.test(t)) //ひらがな1文字 http://www.unicode.org/charts/PDF/U3040.pdf
|
|
|
|
.filter((t) => !/^[\u30A0-\u30FF]$/.test(t)) //かたかな1文字 http://www.unicode.org/charts/PDF/U30A0.pdf
|
|
|
|
.filter((t) => !/^[\uFF65-\uFF9F]$/.test(t)) //半角カナ1文字 http://www.unicode.org/charts/PDF/UFF00.pdf
|
|
|
|
.filter((t) => !/[、・…]/.test(t));
|
2019-07-28 01:52:06 +09:00
|
|
|
const word = random(words);
|
|
|
|
const ans = await tellme(word);
|
|
|
|
if (/^(|…|しらないにゃーん)$/.test(ans)) {
|
|
|
|
throw new Error(`don't know ${word} : ${ans}`);
|
|
|
|
}
|
2020-04-09 00:24:48 +09:00
|
|
|
return say(`:nya-n: < 【う・ん・ち・く】${ans}`);
|
2019-07-28 01:52:06 +09:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2020-04-09 00:16:46 +09:00
|
|
|
},
|
2019-07-28 01:52:06 +09:00
|
|
|
];
|