-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
184 lines (148 loc) · 4.2 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* @file Zoom reminders program.
*
* @name Zoom
*/
let [cron, links] = [require(`cron`), require(`./links.js`)]
/**
* Open link from notification button.
*
* @name open
* @param {string} link The URL to open.
* @return {null}
*/
this.open = link => {
// Get user platform.
let platform = (url, platform = new String()) => {
switch (process.platform) {
// Platform linux.
case `linux`: {
platform = `xdg-open ${url}`
break
}
// Platform macos.
case `darwin`: {
platform = `open ${url}`
break
}
// Platform windows.
case `win32`: {
platform = `cmd /c start ${url}`
break
}
}
return platform
}
// Open link.
require(`child_process`).exec(platform(link))
}
/**
* Send notification and get response.
*
* @name notify
* @param {array} links An array of objects with link data.
* @return {null}
*/
this.notify = links => {
// If no links, stop running.
if (links.length < 1) return
// Send notification.
require(`node-notifier`).notify(
// Notification data.
{
title: `Your 5 Minute Zoom Reminder!`,
message: `This is your ${links.map(set => set.case).join(`/`)} Reminder!`,
icon: `./assets/jonin.png`,
actions: links.map(set => `Open link for ${set.case}`),
sound: true,
wait: true
},
/**
* Button response event.
*
* @name button
* @param {string} res Case to open.
* @return {null}
*/
(_, res) => {
let other
// Filter links.
links.forEach(set => `open link for ${set.case.toLowerCase()}` === res ? this.open(set.data) : other = set)
// If only 1 link available, stop running.
if (!other) return
// Send notification for other link.
require(`node-notifier`).notify(
// Notification data.
{
title: `Open other link?`,
message: `Accidently clicked the wrong link? Click here to open other link.`,
icon: `./assets/jonin.png`,
actions: [`Open link for ${other.case}`],
sound: false,
wait: false
},
/**
* Open other link.
*
* @name other
* @return {null}
*/
_ => this.open(other.data)
)
}
)
}
/**
* Links parser.
*
* @name linkify
* @param {string} input A string with the link params.
* @param {array} array A preset param.
* @return {array} An array of objects with link data.
*/
this.linkify = (input, array = new Array()) => {
// Parser logic.
input.split(``).forEach(num => links[`period${num}`] ? array.push({ case: `Period ${num}`, data: links[`period${num}`] }) : null)
return array
}
/**
* First/Fifth period notification.
*
* @name first
* @return {null}
*/
this.first = _ => this.notify(this.linkify(`15`))
/**
* Second/Sixth period notification.
*
* @name second
* @return {null}
*/
this.second = _ => this.notify(this.linkify(`26`))
/**
* Third/Seventh period notification.
*
* @name third
* @return {null}
*/
this.third = _ => this.notify(this.linkify(`37`))
/**
* Fourth/Eighth period notification.
*
* @name fourth
* @return {null}
*/
this.fourth = _ => this.notify(this.linkify(`48`))
// Cron Job setup.
let [first, second, third, fourth] = [
new cron.CronJob(`0 45 8 * * 1,2,3,4,5`, this.first, null, true, `America/Chicago`),
new cron.CronJob(`0 25 10 * * 1,2,3,4,5`, this.second, null, true, `America/Chicago`),
new cron.CronJob(`0 5 12 * * 1,2,3,4,5`, this.third, null, true, `America/Chicago`),
new cron.CronJob(`0 35 14 * * 1,2,3,4,5`, this.fourth, null, true, `America/Chicago`)
]
// Init cron job.
first.start()
second.start()
third.start()
fourth.start()
// 🔒 This is protected code, see https://kura.gq?to=share for more information.