-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbb.js
64 lines (59 loc) · 2.37 KB
/
bb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require("dotenv").config();
const axios = require('axios');
const ical = require('node-ical');
const moment = require("moment-timezone");
moment().tz("Asia/Tokyo").format();
(async () => {
// or just parse some iCalendar data directly
const events = ical.sync.parseICS((await axios.get(process.env.BB_ICS_URL)).data);
for (const event of Object.values(events)) {
if (!event.end || event.type !== "VEVENT") {
continue;
}
const end = moment(event.end).tz('Asia/Tokyo').startOf('day');
const now = moment(new Date()).tz('Asia/Tokyo').startOf("day");
const diff = end.diff(now, "days");
if (diff < 0 || diff > 1) {
continue;
}
if(process.env.DEBUG === "TRUE"){
console.log(
'Summary: ' + event.summary +
'\nDescription: ' + event.description +
'\nEnd Date: ' + event.end?.toISOString()
);
console.log(event);
console.log(moment(event.end).tz('Asia/Tokyo'));
console.log("残り: ", end.diff(now, "days"));
}
axios.post(process.env.DISCORD_WEBHOOK_URL, {
"content": `${process.env.MENTIONID} ${diff >= 1 ? '明日' : '**本日**'}: ${event.summary}`,
"embeds": [
{
"title": event.summary,
"description": `${diff >= 1 ? '明日' : '**本日**'}のイベントです`,
"url": "https://bb.kosen-ac.jp/",
"color": diff >= 1 ? 11515392 : 16711680, //#afb600 : #FF0000
"fields": [
{
"name": "期日",
"value": moment(event.end).tz('Asia/Tokyo').format("YYYY/MM/DD HH:mm:ss"),
"inline": true
},
{
"name": "提出先",
"value": "BB"
},
{
"name": "課題を提出",
"value": "[こちらから](https://bb.kosen-ac.jp/)"
}
]
}
],
"username": "Blackboard 課題",
"avatar_url": process.env.BB_ICON_URL,
"attachments": []
})
};
})();