-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
106 lines (81 loc) · 2.93 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
const { App, LogLevel, ExpressReceiver } = require("@slack/bolt");
require("dotenv").config();
const { getPrisma } = require('./utils/prismaConnector.js');
const prisma = getPrisma();
const express = require('express')
const receiver = new ExpressReceiver({
signingSecret: process.env.SLACK_SIGNING_SECRET,
})
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
receiver,
// socketMode: true,
// appToken: process.env.SLACK_APP_TOKEN,
// Using socket mode, however we still want for it to reply to OAuth
port: process.env.PORT || 3000,
});
receiver.router.use(express.json())
receiver.router.get('/', require('./endpoints/index'))
receiver.router.get('/ping', require('./endpoints/ping'))
app.client.chat.postMessage({
channel: process.env.MIRRORCHANNEL,
text: `Firehose is online again!`
})
app.event("channel_created", async ({ event, client }) => {
try {
const channelId = event.channel.id;
await client.conversations.join({ channel: channelId });
} catch (e) {
app.logger.error(e)
}
});
app.event('message', async (args) => {
// begin the firehose
const { body, client } = args
const { event } = body
const { type, subtype, user, channel, ts, text } = event
const cleanupChannel = await require("./interactions/cleanupChannel.js");
await cleanupChannel(args);
const shushBan = await require("./interactions/listenforBannedUser.js");
await shushBan(args);
const startSlowMode = await require("./interactions/startSlowMode.js");
await startSlowMode(args);
const listenforChannelBannedUser = await require("./interactions/listenforChannelBannedUser.js");
await listenforChannelBannedUser(args);
});
app.command(/.*?/, async (args) => {
const { ack, command, respond } = args;
await ack();
switch (command.command) {
case '/channelban':
await require('./commands/channelBan')(args);
break;
case '/unban':
await require('./commands/unban')(args);
break;
case '/read-only':
await require('./commands/readOnly')(args);
break;
case '/slowmode':
await require('./commands/slowmode.js')(args);
break;
case '/whitelist':
await require('./commands/whitelist.js')(args);
break;
case '/shush':
await require('./commands/shush.js')(args);
break;
case '/unshush':
await require('./commands/unshush.js')(args);
break;
default:
await respond(`I don't know how to respond to the command ${command.command}`);
break;
}
})
// Start the app on the specified port
const port = process.env.PORT || 3000; // Get the port from environment variable or default to 3000
app.start(port).then(() => {
app.logger.info(`Bolt is running on ${port}`)
});