-
Notifications
You must be signed in to change notification settings - Fork 9
/
tutorial.js
104 lines (100 loc) · 3.18 KB
/
tutorial.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
import { getInfoForUser, initBot, transcript } from '../utils'
function asyncReply(bot, message, reply, callback = () => {}) {
return new Promise((resolve, reject) => {
try {
const content = {
attachments: [
{
text: reply,
fallback: reply,
author_name: 'Tutorial',
},
],
}
bot.replyPrivateDelayed(message, content, () => {
callback()
resolve()
})
} catch (err) {
console.error(err)
reject(err)
}
})
}
// this is a weird interaction. users call it explicitly when we start running
// the command, but it's called by other interactions that should have a
// tutorial command
const interactionTutorial = async (bot, message) => {
const { user, command, text } = message
const { userRecord, club, history } = await getInfoForUser(user)
if (!club) {
asyncReply(bot, message, transcript('tutorial.notAuthed'))
return
}
switch (command) {
case '/rename-channel':
if (!userRecord.fields['Flag: renamed channel']) {
await asyncReply(
bot,
message,
transcript('tutorial.renameChannel.finished')
)
await asyncReply(bot, message, transcript('tutorial.getSticker.start'))
userRecord.patch({ 'Flag: renamed channel': true })
}
break
case '/meeting-add':
const finishedMeetingAddTutorial =
userRecord.fields['Flag: Tutorial /meeting-add']
const recordedMeetings = history.meetings.length
// if this is the first meeting recorded, let them know to add another
if (recordedMeetings == 1 && !finishedMeetingAddTutorial) {
await asyncReply(
bot,
message,
transcript('tutorial.meetingAdd.progress')
)
return
}
// if there are 2 meetings recorded, go to the next step in the tutorial
if (recordedMeetings >= 2 && !finishedMeetingAddTutorial) {
await asyncReply(
bot,
message,
transcript('tutorial.meetingAdd.finished')
)
userRecord.patch({ 'Flag: Tutorial /meeting-add': true })
await asyncReply(bot, message, transcript('tutorial.finished'))
}
break
case '/get':
const isStickerPromo = text.includes('sticker envelope')
const finishedStickerTutorial =
userRecord.fields['Flag: Tutorial /promo sticker envelope']
if (isStickerPromo && !finishedStickerTutorial) {
await asyncReply(
bot,
message,
transcript('tutorial.getSticker.finished')
)
await asyncReply(bot, message, transcript('tutorial.meetingAdd.start'))
userRecord.patch({ 'Flag: Tutorial /promo sticker envelope': true })
return
}
break
case '/orpheus-tutorial':
case '/meeting-tutorial':
default:
await asyncReply(bot, message, transcript('tutorial.start', { user }))
await asyncReply(
bot,
message,
transcript('tutorial.renameChannel.start', {
channel: club.fields['Slack Channel ID'],
})
)
userRecord.patch({ 'Flag: Initiated tutorial': true })
break
}
}
export default interactionTutorial