forked from hackclub/toriel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup-cave.js
42 lines (37 loc) · 1.11 KB
/
cleanup-cave.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
const { client } = require('../app')
const { transcript } = require('../util/transcript')
async function cleanupCaveChannel(dryRun = true) {
const channel = transcript('channels.cave')
const data = await client.conversations.history({
channel,
})
const { messages } = data
const selfUserID = transcript('selfUserID')
const messagesToRemove = messages.filter((message) => {
return message.user != selfUserID
})
if (dryRun) {
console.log(
`[DRY RUN] Found ${messagesToRemove.length} message(s) from other users in #cave channel, run with dryRun=false to remove`
)
} else {
console.log(
`Found ${messagesToRemove.length} message(s) from other users in #cave channel, cleaning up...`
)
await Promise.all(
messagesToRemove.map((message) =>
client.chat
.delete({
token: process.env.SLACK_LEGACY_TOKEN, // sudo
channel,
ts: message?.ts,
thread_ts: message?.thread_ts,
})
.catch((e) => {
console.warn(e)
})
)
)
}
}
module.exports = { cleanupCaveChannel }