-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlink.js
49 lines (47 loc) · 1.35 KB
/
link.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
43
44
45
46
47
48
49
const { SlashCommandBuilder } = require("discord.js");
const { getGameData, getLink, sendMessage } = require("../util");
module.exports = {
data: new SlashCommandBuilder()
.setName("link")
.setDescription(
"Get a ptn.ninja link for the current game, or the game specified by ID."
)
.addStringOption((option) =>
option.setName("game").setDescription("ID of completed game")
),
async execute(interaction) {
let gameId = interaction.options
? interaction.options.getString("game")
: null;
let message = "";
if (gameId) {
message = `Game ID: ${gameId}\n`;
} else {
let gameData = getGameData(interaction);
if (!gameData) {
return sendMessage(
interaction,
"You must use the game ID to get a link for a completed game. See `/history` to get the game ID.",
true
);
} else if (gameData.allowLinks === false) {
return sendMessage(
interaction,
"Requests for links have been disallowed for this game.",
true
);
}
gameId = gameData.gameId;
}
try {
const link = getLink(gameId);
return sendMessage(interaction, message + link);
} catch (error) {
return sendMessage(
interaction,
"I couldn't find a game with that ID.",
true
);
}
},
};