summaryrefslogtreecommitdiff
path: root/commands/evening.js
blob: e7d7dd810b46f9fbaeb3d6eb9cf6da2a66eeb17e (plain)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const axios = require("axios");
const {isNumber} = require("matrix-js-sdk/lib/utils");

module.exports = (parameter, wrapper) => {
    if (wrapper.sender !== "@cloudburst:equestria.dev" && wrapper.sender !== "@raindrops:equestria.dev" && wrapper.sender !== "186730180872634368" && wrapper.sender !== "493845599469174794") {
        wrapper.send("⛔️ This command is private and you are not allowed to use it.");
        return;
    }

    let selectedDay;

    if (parameter && !isNaN(parseInt(parameter)) && parameter > -1 && parameter < 7) {
        selectedDay = parseInt(parameter);
    }

    /*

    [ - Will be 'null' if the day has been ignored
        [
            string[] - Full names of the members of Cloudburst fronting today
            string[] - Full names of the members of Raindrops fronting today
        ],
        [
            string[] - Full names of the members of Cloudburst fronting tomorrow
            string[] - Full names of the members of Raindrops fronting tomorrow
        ]
    ]

     */

    axios.get("https://ponies.equestria.horse/api/evening", {
        headers: {
            'Cookie': 'PEH2_SESSION_TOKEN=' + require('../credentials.json').coldhaze
        }
    }).then(res => {
        let data = res.data;
        let text = "";

        function appendDay(day, name, mini) {
            if (!mini) text += "\n* <u>" + name + ":</u> ";

            if (data[day]) {
                let locked = false;

                if (data[day][0].map(i => i.endsWith("*")).includes(true)) {
                    locked = true;
                    text += " **" + data[day][0].map(i => i.substring(0, i.length - 1)).join("** and **") + "** with";
                } else {
                    text += " **" + data[day][0].join("** and **") + "** with";
                }

                if (data[day][1].map(i => i.endsWith("*")).includes(true)) {
                    locked = true;
                    text += " **" + data[day][1].map(i => i.substring(0, i.length - 1)).join("** and **") + "**";
                } else {
                    text += " **" + data[day][1].join("** and **") + "**";
                }

                if (locked) {
                    text += " *(locked)*";
                }
            } else {
                text += "*(marked as ignored)*";
            }
        }

        if (selectedDay) {
            text = "🌙 Here is what is scheduled for " + (selectedDay === 0 ? "tonight" : (selectedDay === 1 ? "tomorrow" : "the " + new Intl.DateTimeFormat('en-IE', { weekday: "long", day: "numeric" }).format(new Date(new Date().getTime() + (86400000 * selectedDay))))) + ":";

            appendDay(selectedDay, "", true);
        } else {
            text = "🌙 Here is what is scheduled for the next nights:\n";

            appendDay(0, "Tonight");
            appendDay(1, "Tomorrow");
            appendDay(2, new Intl.DateTimeFormat('en-IE', { weekday: "long", day: "numeric" }).format(new Date(new Date().getTime() + (86400000 * 2))));
            appendDay(3, new Intl.DateTimeFormat('en-IE', { weekday: "long", day: "numeric" }).format(new Date(new Date().getTime() + (86400000 * 3))));
            appendDay(4, new Intl.DateTimeFormat('en-IE', { weekday: "long", day: "numeric" }).format(new Date(new Date().getTime() + (86400000 * 4))));
            appendDay(5, new Intl.DateTimeFormat('en-IE', { weekday: "long", day: "numeric" }).format(new Date(new Date().getTime() + (86400000 * 5))));
            appendDay(6, new Intl.DateTimeFormat('en-IE', { weekday: "long", day: "numeric" }).format(new Date(new Date().getTime() + (86400000 * 6))));
        }

        text += "\n\n[[View on Cold Haze](https://ponies.equestria.horse/-/evening)]";

        wrapper.send(text);
    });
}