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

23 lines
699 B
JavaScript
Raw Normal View History

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) {
2020-04-09 00:24:48 +09:00
return say("APODの画像が取れなかったにゃーん");
}
const dict = await response.json();
const url =
dict.media_type === "video"
? `https://www.youtube.com/watch?v=${get_video_id(dict.url)}`
: dict.url;
2020-04-09 00:24:48 +09:00
return say(`宇宙って良いにゃーん\n${dict.title}\n${url}`);
2020-04-09 00:16:46 +09:00
},
];