-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.ts
49 lines (40 loc) · 1.09 KB
/
index.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
const express = require('express');
const sayings = require('./sayings');
const emoticons = [
':ryanjones:',
':seven:',
':cherries:',
':woman:'
];
const app = express();
app.use(express.urlencoded({extended: true}));
app.post('/', (req, res) => {
const {username = ''} = req.body || {};
let emoji = [];
let message = '';
let responseType = 'ephemeral';
if (username === 'ryan') {
emoji = [':woman:', ':woman:', ':woman:'];
}
for (let i = 0; i < 3; i++) {
emoji.push(emoticons[Math.floor(Math.random() * emoticons.length)]);
}
if (emoji.every((e) => e === ':ryanjones:')) {
message = 'Ryan Jooooooooooones!';
responseType = 'in_channel';
} else if (emoji.every(e => e === ':woman:')) {
message = 'Ryan Jones always gets the ladies';
} else {
message = sayings[Math.floor(Math.random() * sayings.length)];
}
res.json({
response_type: responseType,
text: emoji.join(''),
attachments: [
{
text: message
}
]
});
});
app.listen(8080);