forked from gathertown/mod-basic-player-listener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack.ts
69 lines (62 loc) · 1.79 KB
/
slack.ts
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
import { Player } from ".";
import { ChatPostMessageArguments, WebClient } from "@slack/web-api";
const client = new WebClient(process.env.SLACK_BOT_TOKEN);
const hype = [
"it's lit af",
"party's just gettin started",
"things are crazy rn",
"don't you dare miss this",
"everyone's talking about it",
"don't get fomo",
"go nuts",
"the team needs u",
"🦫🦫🦫",
"let's fucking go"
]
const getHype = (): string => {
return hype[Math.min(Math.floor(Math.random() * hype.length), hype.length - 1)]
}
export const postMessage = async (newPlayers: Player[], leftPlayers: Player[]) => {
const blocks = [
{
type: "header",
text: {
type: "plain_text",
text: `beavertown poppin off`,
}
},
];
if (newPlayers.length > 0) {
blocks.push({
type: "section",
text: {
type: "mrkdwn",
text: newPlayers.map(player => player.name).join(", ") + " just joined",
}
});
}
if (leftPlayers.length > 0) {
blocks.push({
type: "section",
text: {
type: "mrkdwn",
text: leftPlayers.map(player => player.name).join(", ") + " dipped",
}
});
}
blocks.push({
type: "section",
text: {
type: "mrkdwn",
text: `${getHype()}, <https://app.gather.town/app/PQR3oEaLR3HhjuWh/stunning-beaver|roll thru>`,
}
});
const payload: ChatPostMessageArguments = {
channel: process.env.SLACK_CHANNEL_ID ?? "",
text: `Update from beavertown:\n${newPlayers.length > 0 ? `${newPlayers.length} new ${newPlayers.length > 1 ? 'people' : 'person'}` : ''}\n${leftPlayers.length > 0 ? `${leftPlayers.length} ${leftPlayers.length > 1 ? 'people' : 'person'} bailed` : ''}`,
blocks,
unfurl_links: false,
}
const resp = await client.chat.postMessage(payload)
console.log({ resp })
}