-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
78 lines (73 loc) · 1.86 KB
/
server.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
//node packages
require("dotenv").config();
//local packages
const { app } = require("./utilities/bolt.js");
const { isModerator } = require("./utilities/helperFunctions.js");
const { slashChannel } = require("./handlers/slashCommands.js");
const {
approveMessage,
approveNoAt,
rejectMessage,
cancelRequest
} = require("./handlers/buttons.js");
app.command(
"/channel",
async ({ ack, next }) => {
ack();
next();
},
slashChannel
);
app.action(
/** Actions for if message was approved, approved without @channel, or rejected:
* determines which case and handles all related actions */
//APP = approved; NOAT = approved without @channel; REJ = reject
/^(APP|NOAT|REJ)_.*/,
async ({ ack, next }) => {
ack();
next();
},
isModerator,
async ({
action: { action_id },
body: {
message: { ts, blocks },
user: { id }
}
}) => {
const channel_id = /<#(.*?)[a-zA-Z0-9]{7,10}>/
.exec(blocks[0].text.text)[0]
.replace("<#", "")
.replace(">", "");
const text = blocks[1].text.text.replace(">>>", "");
const user_id = /<@(.*?)[a-zA-Z0-9]{7,10}>/
.exec(blocks[0].text.text)[0]
.replace("<@", "")
.replace(">", "");
if (/^APP_.*/.test(action_id)) {
approveMessage(channel_id, text, user_id, ts, id);
} else if (/^NOAT_.*/.test(action_id)) {
approveNoAt(channel_id, text, user_id, ts, id);
} else if (/^REJ_.*/.test(action_id)) {
rejectMessage(channel_id, text, user_id, ts, id);
}
}
);
app.action(
/** Action for when poster cancels @channel request */
/^CAN_.*/,
async ({ ack, next }) => {
ack();
next();
},
async ({
action: { action_id },
body: {
channel: { id: channel_id },
user: { id: user_id }
}
}) => {
const ts = action_id.replace("CAN_", "");
cancelRequest(channel_id, user_id, ts);
}
);