-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathapp-mentions.js
More file actions
127 lines (125 loc) · 4.82 KB
/
Copy pathapp-mentions.js
File metadata and controls
127 lines (125 loc) · 4.82 KB
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
const utils = require('./utils/utils');
const helpBlocks = require('./bot-response/blocks-help');
const msgText = require('./bot-response/message-text');
// Commands
const cmdNew = require('./app-mentions/new');
const cmdDescription = require('./app-mentions/description');
const cmdStaff = require('./app-mentions/staff');
const cmdResetStaff = require('./app-mentions/reset-staff');
const cmdDelete = require('./app-mentions/delete');
const cmdAbout = require('./app-mentions/about');
const cmdAssign = require('./app-mentions/assign');
const cmdAssignNext = require('./app-mentions/assign-next');
const cmdWho = require('./app-mentions/who');
const cmdUnassign = require('./app-mentions/unassign');
const cmdList = require('./app-mentions/list');
const cmdHelp = require('./app-mentions/help');
const cmdMessage = require('./app-mentions/message');
// Error handling
const errHandler = require('./utils/error');
/*------------------
APP MENTIONS
------------------*/
const app_mentions = (app, store) => {
app.event('app_mention', utils.ignoreMention, async({ event, context }) => {
// Event and context data
const ec = {
text: event.text, // raw text from the mention
sentByUserID: event.user, // ID of user who sent the message
channelID: event.channel, // channel ID
botToken: context.botToken, // bot access token
rotaList: await store.getRotations() // rotations in db
}
// Decision logic establishing how to respond to mentions
const isNew = await utils.isCmd('new', ec.text);
const isDescription = await utils.isCmd('description', ec.text);
const isStaff = await utils.isCmd('staff', ec.text);
const isResetStaff = await utils.isCmd('reset staff', ec.text);
const isAssign = await utils.isCmd('assign', ec.text);
const isAssignNext = await utils.isCmd('assign next', ec.text);
const isWho = await utils.isCmd('who', ec.text);
const isAbout = await utils.isCmd('about', ec.text);
const isUnassign = await utils.isCmd('unassign', ec.text);
const isDelete = await utils.isCmd('delete', ec.text);
const isHelp = await utils.isCmd('help', ec.text);
const isList = await utils.isCmd('list', ec.text);
const testMessage = await utils.isCmd('message', ec.text);
const isMessage =
testMessage &&
!isNew &&
!isDescription &&
!isStaff &&
!isResetStaff &&
!isAssign &&
!isAssignNext &&
!isWho &&
!isAbout &&
!isUnassign &&
!isDelete;
// @rota new "[rotation]" [optional description]
if (isNew) {
cmdNew(app, event, context, ec, utils, store, msgText, errHandler);
}
// @rota "[rotation]" description [new description]
else if (isDescription) {
cmdDescription(app, event, context, ec, utils, store, msgText, errHandler);
}
// @rota "[rotation]" staff [@user @user @user]
else if (isStaff) {
cmdStaff(app, event, context, ec, utils, store, msgText, errHandler);
}
// @rota "[rotation]" reset staff
else if (isResetStaff) {
cmdResetStaff(app, event, context, ec, utils, store, msgText, errHandler);
}
// @rota "[rotation]" delete
else if (isDelete) {
cmdDelete(app, event, context, ec, utils, store, msgText, errHandler);
}
// @rota "[rotation]" about
else if (isAbout) {
cmdAbout(app, event, context, ec, utils, store, msgText, errHandler);
}
// @rota "[rotation]" assign [@user] [handoff message]
else if (isAssign) {
cmdAssign(app, event, context, ec, utils, store, msgText, errHandler);
}
// @rota "[rotation]" assign next [handoff message]
else if (isAssignNext) {
cmdAssignNext(app, event, context, ec, utils, store, msgText, errHandler);
}
// @rota "[rotation]" who
else if (isWho) {
cmdWho(app, event, context, ec, utils, store, msgText, errHandler);
}
// @rota "[rotation]" unassign
else if (isUnassign) {
cmdUnassign(app, event, context, ec, utils, store, msgText, errHandler);
}
// @rota list
else if (isList) {
cmdList(app, ec, utils, msgText, errHandler);
}
// @rota help
else if (isHelp) {
cmdHelp(app, ec, utils, helpBlocks, msgText, errHandler);
}
// @rota "[rotation]" free form message for on-call user
else if (isMessage) {
cmdMessage(app, event, context, ec, utils, store, msgText, errHandler);
}
// @rota anything else
else {
try {
// console.log('Event: ', event, 'Clean Text: ', utils.cleanText(ec.text));
const result = await app.client.chat.postMessage(
utils.msgConfig(ec.botToken, ec.channelID, msgText.didntUnderstand(ec, msgText))
);
}
catch (err) {
errHandler(app, ec, utils, err, msgText);
}
}
});
}
module.exports = app_mentions;