-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (49 loc) · 1.32 KB
/
Copy pathindex.js
File metadata and controls
59 lines (49 loc) · 1.32 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require("dotenv").config();
const axios = require("axios");
const { App } = require("@slack/bolt");
const app = new App({
token: process.env.SLACK_BOT_TOKEN,
appToken: process.env.SLACK_APP_TOKEN,
socketMode: true
});
app.command("/dsb-ping", async ({ command, ack, respond }) => {
const start = Date.now();
await ack();
const latency = Date.now() - start;
await respond({ text: `Pong!\nLatency: ${latency}ms` });
});
(async () => {
await app.start();
console.log("bot is running!");
})();
app.command("/dsb-help", async ({ ack, respond }) => {
await ack();
await respond({
text:
`Available Commands:
/dsb-ping - Check bot latency
/dsb-catfact - Get a cat fact`
});
});
app.command("/dsb-catfact", async ({ ack, respond }) => {
await ack();
try {
const response = await axios.get("https://catfact.ninja/fact");
await respond({ text: `Cat Fact:\n${response.data.fact}` });
} catch (err) {
await respond({ text: "Failed to fetch a cat fact." });
}
});
app.command("/dsb-joke", async ({ ack, respond }) => {
await ack();
try {
const response = await axios.get("https://official-joke-api.appspot.com/random_joke");
await respond({
text:
`${response.data.setup}
${response.data.punchline}`
});
} catch (err) {
await respond({ text: "Failed to fetch a joke." });
}
});