1
0
Fork 0
mirror of https://github.com/kou029w/daraz-san.git synced 2025-01-18 16:08:06 +00:00

scripts を移行

主要な変更点
- CoffeeScript をやめる
- cron.coffee は機能していないため削除
- ruby.coffee は機能していないため削除
- www.coffee は #general でしか使われていないため削除
- *便器*はリンク切れしていたため削除
- *鳥取*は栃木県ではないため削除

Co-authored-by: SAKAGUCHI Takashi <takashi.sakaguchi@ummm.info>
Co-authored-by: Masayuki Higashino <mh61503891@users.noreply.github.com>
Co-authored-by: Kazuki Shigemichi <shigemichik@gmail.com>
This commit is contained in:
Nebel 2019-07-28 01:52:06 +09:00
parent 7c822a33a4
commit 5152efc6ff
22 changed files with 553 additions and 1581 deletions

11
app.js
View file

@ -1,15 +1,14 @@
const { App } = require("@slack/bolt");
const patternsOrMiddleware = require("./")
const daraz = require("./");
const app = new App({
const app = daraz(
new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET
});
app.message(...patternsOrMiddleware);
})
);
(async () => {
await app.start(process.env.PORT || 80);
console.log("Daraz-san ⚡ running");
})();

View file

@ -1,6 +1,11 @@
module.exports = [
"daraz",
({ message, say }) => {
say(`<@${message.user}>`);
}
];
const scripts = require("glob")
.sync("./scripts/*.js")
.map(require);
module.exports = app => {
scripts.forEach(script => {
if (Array.isArray(script)) return app.message(...script);
if (script instanceof Function) return script(app);
});
return app;
};

View file

@ -4,13 +4,24 @@
"description": "Daraz-san ⚡",
"main": "index.js",
"author": "Kohei Watanabe <kou029w@gmail.com>",
"contributors": [
"SAKAGUCHI Takashi <takashi.sakaguchi@ummm.info>",
"Masayuki Higashino <mh61503891@users.noreply.github.com>",
"Kazuki Shigemichi <shigemichik@gmail.com>"
],
"license": "MIT",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"@slack/bolt": "^1.2.0"
"@slack/bolt": "^1.2.0",
"date-fns": "^2.0.0-beta.3",
"get-video-id": "^3.1.4",
"glob": "^7.1.4",
"kuromoji": "^0.1.2",
"node-fetch": "^2.6.0",
"tldjs": "^2.3.1"
},
"engines": {
"node": "12.x",

23
scripts/apod.js Normal file
View file

@ -0,0 +1,23 @@
const fetch = require("node-fetch");
const get_video_id = require("get-video-id");
const API_KEY = "Q8mtkFkP4Zru4mlDd812iw2vcQwx5B0qIsUKsxit";
module.exports = [
/apod|galaxy|spa+ce|宇宙|コスモ|銀河/i,
async ({ say }) => {
const response = await fetch(
`https://api.nasa.gov/planetary/apod?api_key=${API_KEY}`
);
if (!response.ok) {
say("APODの画像が取れなかったにゃーん");
return;
}
const dict = await response.json();
const url =
dict.media_type === "video"
? `https://www.youtube.com/watch?v=${get_video_id(dict.url)}`
: dict.url;
say(`宇宙って良いにゃーん\n${dict.title}\n${url}`);
}
];

22
scripts/dns.js Normal file
View file

@ -0,0 +1,22 @@
const dns = require("dns");
const { tldExists } = require("tldjs");
module.exports = [
/(([a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)+([a-z]+)/,
async ({ context, say }) => {
const domain = context.matches[0];
const ignores = ["daraz-tek.slack.com"];
if (ignores.includes(domain)) return;
if (!tldExists(domain)) return;
try {
const records = await new Promise((resolve, reject) =>
dns.resolve(domain, (err, records) =>
err ? reject(err) : resolve(records)
)
);
say(`:nya-n: < ${domain}${records.join(" *,* ")} ですにゃん`);
} catch {
say(`:nya-n: < ${domain} はわかんなかったにゃん`);
}
}
];

35
scripts/faiz.js Normal file
View file

@ -0,0 +1,35 @@
module.exports = app => {
app.message(/555/, ({ say }) => {
say(
[
"Standing by... > :nya-n:",
"キュィーン…キュィーン…キュィーン… > :nya-n:",
"Complete > :nya-n:",
"変身! > :nya-n:",
":555: ノシ"
].join("\n")
);
});
app.message(/551/, ({ say }) => {
say(
[
"551の豚まんがあるときー > :nya-n:",
"```",
" ♪ ∧, _∧  ♪",
"   ( ´・ω・) ))",
" (((  つ ヽ、   ♪",
"   〉 とノ )))",
" __ ^ (_)",
"```",
"ないときー? > :nya-n:",
"```",
"  /⌒ヽ",
" く / ・〝 ⌒ヽ",
"  | 3 (∪ ̄]",
" く、・〟 (∩ ̄]",
" ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄",
"```"
].join("\n")
);
});
};

6
scripts/goku.js Normal file
View file

@ -0,0 +1,6 @@
module.exports = [
/([\s\S]*(ぱい|パイ)[\s\S]*)/,
({ context, say }) => {
say(`:goku: < ${context.matches[0].replace(/ぱい|パイ/g, "ぺぇ")}`);
}
];

19
scripts/ipinfo.js Normal file
View file

@ -0,0 +1,19 @@
const fetch = require("node-fetch");
module.exports = [
/(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])/,
async ({ context, say }) => {
const ip = context.matches[0];
const url = `https://ipinfo.io/${ip}`;
const options = {
timeout: 2000,
headers: { Accept: "application/json" }
};
const response = await fetch(url, options);
say(
response.ok
? `:nya-n: < ${await response.text()}`
: `:nya-n: < がんばったけど ${ip} よくわからんかったにゃん`
);
}
];

22
scripts/json.js Normal file
View file

@ -0,0 +1,22 @@
const { directMention } = require("@slack/bolt");
const nyanco = require("./util/nyanco");
// Description:
// だらずさんは JSON のお掃除がだいすきです
//
// Synopsis:
// json <jsonstring> - あなたの JSON をぷりちーにするにゃん
module.exports = [
directMention(),
/json +(.*)/i,
({ context, say }) => {
try {
const json = JSON.parse(context.matches[1]);
const res = JSON.stringify(json, null, 2);
say([`${nyanco()}`, "```", res, "```"].join("\n"));
} catch (e) {
console.error(e);
}
}
];

24
scripts/morpheme.js Normal file
View file

@ -0,0 +1,24 @@
const { directMention } = require("@slack/bolt");
const { useTokenize, toCSV } = require("./util/morpheme");
const nyanco = require("./util/nyanco");
// Description:
// すもももももももものうち
//
// Synopsis:
// morpheme <phrase> - <phrase> を形態素解析器にかけるにゃーん
module.exports = [
directMention(),
/morpheme (.*)/i,
async ({ context, say }) => {
try {
const tokenize = await useTokenize();
const tokens = tokenize(context.matches[1]);
const readings = tokens.map(({ reading }) => reading);
say([`${nyanco()} ${readings.join("")}`, toCSV(tokens)].join("\n"));
} catch (e) {
console.error(e);
}
}
];

109
scripts/nurupo.js Normal file
View file

@ -0,0 +1,109 @@
const random = require("./util/random");
const nyanco = require("./util/nyanco");
const patterns = [
[/ぬ.*る.*ぽ/, ({ say }) => say(`${nyanco()} < にゃーん`)],
[
/だらず((さん)?.*)/,
({ context, say }) =>
say(
`${nyanco()} < ${
context.matches[2] ? "にゃーん" : "さんを付けろよデコスケ野郎っ!"
}`
)
],
[/こたつ/, ({ say }) => say(`${nyanco()} < しまえ`)],
[/(しお|塩)/, ({ say }) => say(`${nyanco()} < しお`)],
[
/(らーめん|ラーメン|拉麺|らうめん)/,
({ say }) => say(`${nyanco()} < :ramen:`)
],
[/しりとり/, ({ say }) => say(`${nyanco()} < うどん。`)],
[
/(糞|くそ|クソ)(すれ|スレ)/,
({ say }) => say(`${nyanco()} < クソスレで悪かったな!!`)
],
[
/(すし|鮨|寿司|スシ|まぐろ|マグロ|sushi)/i,
({ say }) => say(`${nyanco()} < あいよ っ :sushi:`)
],
[/ちゃ|茶/, ({ say }) => say(`お茶どぞー < ${nyanco()}っ :tea:`)],
[
/風邪|かぜ|カゼ|体調|つらい|くるしい|痛い|ひぎぃ|うぐぅ/,
({ say }) => say(`おくすりどぞー < ${nyanco()}っ :pill:`)
],
[
/(ちらし|チラシ|広告)/,
({ say }) => say(`${nyanco()} < スタンプラリーやめれ`)
],
[
/進捗どうですか/,
({ message, say }) => {
const from = `<@${message.user}>`;
say(
[
`${nyanco()} < そう言うと ${from} は永い眠りについた。`,
`メールとチケットが山のように積もった部屋の片隅で・・・。`,
`主を失ったモニタのあかりだけが、動かなくなった ${from} を優しく照らし続けた。`
].join("")
);
}
],
[
/(のむら|さちよ|野村|沙知代|さっちー|サッチー|のむさん|ノムサン)/,
({ say }) =>
say(
[
":nomura-exodia-1::nomura-exodia-2::nomura-exodia-3:",
":nomura-exodia-4::nomura-exodia-5::nomura-exodia-6: :exclamation::question:",
":nomura-exodia-7::nomura-exodia-8::nomura-exodia-9:"
].join("\n")
)
],
[
/(肉|にく|ニク)/,
({ say }) => {
if (random([...Array(3).keys()]) !== 0) return;
say(
[
":spark-exodia-00::spark-exodia-01::spark-exodia-02::spark-exodia-03::spark-exodia-04::spark-exodia-05:",
":spark-exodia-06::spark-exodia-07::spark-exodia-08::spark-exodia-09::spark-exodia-10::spark-exodia-11:",
":spark-exodia-12::spark-exodia-13::spark-exodia-14::spark-exodia-15::spark-exodia-16::spark-exodia-17:",
":spark-exodia-18::spark-exodia-19::spark-exodia-20::spark-exodia-21::spark-exodia-22::spark-exodia-23:"
].join("\n")
);
}
],
[
/(野球|やきゅう|やきう)/,
({ say }) => {
if (random([...Array(10).keys()]) !== 0) return;
say(
[
":nomura-exodia-1::nomura-exodia-2::nomura-exodia-3:",
":nomura-exodia-4::nomura-exodia-5::nomura-exodia-6: :exclamation::question:",
":nomura-exodia-7::nomura-exodia-8::nomura-exodia-9:"
].join("\n")
);
}
],
[
/.*(ね|ネ).+(ハム|はむ)(たろう|たろー|タロウ|タロー|太郎)/,
({ context, say }) => {
if (
/(死|亡|殺)/.test(context.matches[0]) ||
random([...Array(10).keys()]) === 0
) {
say(":hamster: < まったくなのだ!万死に値するのだ!!");
} else {
say(":hamster: < まったくなのだ!!!");
}
}
],
[
/^(?=.*[eE]macs)(?=.*[vV]i)/,
({ say }) => say(`${nyanco()} < Emacs vs. Vi ファイ!`)
]
];
module.exports = app => patterns.forEach(pattern => app.message(...pattern));

10
scripts/nyanchu.js Normal file
View file

@ -0,0 +1,10 @@
const { directMention } = require("@slack/bolt");
module.exports = [
directMention(),
/(ニャンちゅう) +(.*)/,
({ context, say }) => {
const oon = context.matches[2].split("").map(c => `${c}`);
say(`お゛ぉ゛ん!${oon.join("")}た゛に゛ゃあ゛ん! > :nyanchu:`);
}
];

23
scripts/random.js Normal file
View file

@ -0,0 +1,23 @@
const { directMention } = require("@slack/bolt");
const random = require("./util/random");
// Description:
// だらずさんはランダムにどれか選べます
//
// Synopsis:
// choice <word1> <word2> ... <wordN> - どれか選ぶにゃん、 word の区切りは空白あるいはカンマにゃん。
// random <word1> <word2> ... <wordN> - どれか選ぶにゃん、 word の区切りは空白あるいはカンマにゃん。
// えらべ <word1> <word2> ... <wordN> - どれか選ぶにゃん、 word の区切りは空白あるいはカンマにゃん。
// 選べ <word1> <word2> ... <wordN> - どれか選ぶにゃん、 word の区切りは空白あるいはカンマにゃん。
module.exports = [
directMention(),
/(choice|random|えらべ|選べ) +(.*)/,
({ context, say }) => {
const words = [
...context.matches[2].split(/(?:,|\s)+/),
"人に決められるだけの人生でいいのか?自分で決めようず"
];
say(`:nya-n: < ${random(words)}`);
}
];

18
scripts/tellme.js Normal file
View file

@ -0,0 +1,18 @@
const { directMention } = require("@slack/bolt");
const tellme = require("./util/tellme");
const nyanco = require("./util/nyanco");
// Description:
// だらずさんは何でも知っているので教えてくれます
//
// Synopsis:
// tell me <phrase> - <phrase> について教えてあげよう、妖怪ウィキウィキペディアは使ってないよ!
module.exports = [
directMention(),
/tell( ?me)? (.*)/i,
async ({ context, say }) => {
const ans = await tellme(context.matches[2]);
if (ans != null) say(`${nyanco()} ${ans}`);
}
];

30
scripts/unchiku.js Normal file
View file

@ -0,0 +1,30 @@
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)
.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));
const word = random(words);
const ans = await tellme(word);
if (/^(|…|しらないにゃーん)$/.test(ans)) {
throw new Error(`don't know ${word} : ${ans}`);
}
say(`:nya-n: < 【う・ん・ち・く】${ans}`);
} catch (e) {
console.error(e);
}
}
];

38
scripts/util/morpheme.js Normal file
View file

@ -0,0 +1,38 @@
const kuromoji = require("kuromoji");
const dicPath = require("path").resolve(
require.resolve("kuromoji"),
"../../dict"
);
const useTokenize = () =>
new Promise((resolve, reject) =>
kuromoji
.builder({ dicPath })
.build((err, tokenizer) =>
err ? reject(err) : resolve(tokenizer.tokenize.bind(tokenizer))
)
);
const features = new Map([
["surface_form", "表層形"],
["pos", "品詞"],
["pos_detail_1", "品詞細分類1"],
["pos_detail_2", "品詞細分類2"],
["pos_detail_3", "品詞細分類3"],
["conjugated_type", "活用型"],
["conjugated_form", "活用形"],
["basic_form", "基本形"],
["reading", "読み"],
["pronunciation", "発音"]
]);
const toCSV = tokens =>
[
[...features.values()].join(","),
...tokens.map(token =>
[...features.keys()].map(feature => token[feature]).join(",")
)
].join("\n");
module.exports = { useTokenize, toCSV };

5
scripts/util/nyanco.js Normal file
View file

@ -0,0 +1,5 @@
const random = require("./random");
const nyans = [":nya-n1:", ":nya-n2:", ":nya-n3:", ":nya-n4:", ":nya-n5:"];
module.exports = nyanco = () => random(nyans);

1
scripts/util/random.js Normal file
View file

@ -0,0 +1 @@
module.exports = array => array[Math.floor(Math.random() * array.length)];

31
scripts/util/tellme.js Normal file
View file

@ -0,0 +1,31 @@
const fetch = require("node-fetch");
module.exports = async titles => {
const url = new URL("https://ja.wikipedia.org/w/api.php");
const params = new URLSearchParams({
action: "query",
format: "json",
prop: "extracts",
titles,
redirects: "",
exchars: 120,
explaintext: ""
});
try {
const response = await fetch([url, params].join("?"));
if (!response.ok) {
throw new Error([response.status, response.statusText].join(":"));
}
const json = await response.json();
if (json == null || json.query == null || json.query.pages == null) {
throw new Error(["response is invalid", JSON.stringify(json)].join(":"));
}
const pages = new Map(Object.entries(json.query.pages));
return pages.size > 0
? [...pages.values()].map(({ extract }) => extract).join("\n")
: "しらないにゃーん";
} catch (e) {
console.error(e);
}
return null;
};

30
scripts/weather.js Normal file
View file

@ -0,0 +1,30 @@
const subMinutes = require("date-fns/subMinutes");
const roundToNearestMinutes = require("date-fns/roundToNearestMinutes");
const format = require("date-fns/format");
const nyanco = require("./util/nyanco");
const prefNumber = 34;
const pageURL = `https://www.tenki.jp/radar/7/${prefNumber}/`;
const imgURL = target =>
[
"https://static.tenki.jp/static-images/radar/",
format(target, "yyyy/MM/dd/HH/mm/ss"),
`/pref-${prefNumber}-large.jpg`
].join("");
module.exports = [
/天気/,
async ({ say }) => {
const target = roundToNearestMinutes(subMinutes(new Date(), 5), {
nearestTo: 5
});
say(
[
`${nyanco()} ${format(target, "HH時mm分の雨雲の様子にゃーん")}`,
imgURL(target),
pageURL
].join("\n")
);
}
];

19
scripts/yakitori.js Normal file
View file

@ -0,0 +1,19 @@
const random = require("./util/random");
const nyanco = require("./util/nyanco");
const yakitoris = [
"―ロ@ロ@ロ- ヤキトリ",
"―{ニ}ニ}ニ}ニ}- 豚",
"―@@@- つくね",
"―{}@{}@{}- ねぎ",
"―∬∬∬- 鳥かわ",
"―зεз- 軟骨",
"―⊂ZZZ⊃ ソーセージ",
"―<コ:彡- イカ丸焼き",
"―>゚)))彡- 魚丸焼き"
];
module.exports = [
/焼鳥|焼き鳥|やきとり|ヤキトリ|串|プロキシ|プロクシ|proxy|Proxy|PROXY|ピロシキ/,
({ say }) => say(`串焼きでも食べるにゃん < ${nyanco()}${random(yakitoris)}`)
];

1624
yarn.lock

File diff suppressed because it is too large Load diff