-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (32 loc) · 1.26 KB
/
Copy pathserver.js
File metadata and controls
38 lines (32 loc) · 1.26 KB
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
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const PORT = 3000;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Handle Slack Slash Command (e.g., /roll or /draw)
app.post('/slack/commands', (req, res) => {
const commandText = req.body.command;
let responseText = '';
if (commandText.startsWith('/roll')) {
const roll = Math.floor(Math.random() * 6) + 1;
responseText = `🎲 You rolled a ${roll}! 🎉`;
} else if (commandText.startsWith('/draw')) {
const suits = ["Hearts", "Diamonds", "Clubs", "Spades"];
const ranks = ["Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"];
const suit = suits[Math.floor(Math.random() * suits.length)];
const rank = ranks[Math.floor(Math.random() * ranks.length)];
responseText = `🃏 You drew the ${rank} of ${suit}! 🎉`;
} else {
responseText = "Unknown command. Try `/roll` or `/draw`.";
}
// Respond to Slack with the result
res.json({
response_type: 'in_channel',
text: responseText,
});
});
// Start the server
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});