-
Notifications
You must be signed in to change notification settings - Fork 9
/
meetingTime.js
80 lines (69 loc) · 2.24 KB
/
meetingTime.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
import { parseDate } from 'chrono-node'
import { getInfoForUser, airPatch, transcript } from '../utils'
const interactionMeetingTime = (bot, message) => {
const { user, text } = message
if (text === '' || text === 'help') {
bot.replyPrivateDelayed(message, transcript('meetingTime.help'))
return
}
getInfoForUser(user).then(({ leader, club, slackUser, userRecord }) => {
if (!leader) {
console.log(`${user} isn't a leader, so I told them this was restricted`)
bot.replyPrivateDelayed(message, transcript('meetingTime.invalidUser'))
return
}
if (!club) {
console.log(`${user} doesn't have a club`)
bot.replyPrivateDelayed(message, transcript('meetingTime.invalidClub'))
return
}
const currDay = club.fields['Checkin Day']
const currHour = club.fields['Checkin Hour']
const inputDate = parseDate(text)
if (inputDate) {
const offsetDate = new Date(
inputDate.getTime() - slackUser.tz_offset * 1000
)
const updatedFields = {
'Checkin Hour': offsetDate.getUTCHours().toString(),
'First Meeting Time': offsetDate,
'Checkin Day': offsetDate.toLocaleString('en-GB', {
weekday: 'long',
timeZone: 'UTC',
}),
}
airPatch('Clubs', club.id, updatedFields)
.then(record => {
bot.replyPrivateDelayed(
message,
transcript('meetingTime.success', {
offsetDate,
channelID: club.fields['Slack Channel ID'],
}),
(err, res) => {
if (err) {
throw err
}
}
)
})
.catch(err => {
bot.replyPrivateDelayed(message, transcript('errors.memory', { err }))
})
} else {
bot.replyPrivateDelayed(message, transcript('meetingTime.parsingError'))
if (!currDay || !currHour) {
bot.replyPrivateDelayed(
message,
`_Currently, ${club.fields['Name']} doesn't have a meeting time set_`
)
} else {
bot.replyPrivateDelayed(
message,
`_The club's current meeting time is *${currDay}* at *${currHour}:00*_`
)
}
}
})
}
export default interactionMeetingTime