-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresign.js
62 lines (58 loc) · 1.62 KB
/
resign.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
50
51
52
53
54
55
56
57
58
59
60
61
62
const { SlashCommandBuilder } = require("discord.js");
const {
addPlyToPtnFile,
addToHistoryFile,
cleanupFiles,
clearInactiveTimer,
getGameData,
getLink,
renameChannel,
sendMessage,
setDeleteTimer,
} = require("../util");
module.exports = {
data: new SlashCommandBuilder()
.setName("resign")
.setDescription("Forfeit the current game."),
async execute(interaction) {
let gameData = getGameData(interaction);
if (!gameData) {
return sendMessage(
interaction,
"There is no ongoing game in this channel.",
true
);
}
let result;
if (interaction.member.id === gameData.player1Id) {
result = "0-1";
} else if (interaction.member.id === gameData.player2Id) {
result = "1-0";
} else {
return sendMessage(interaction, "You are not an active player.", true);
}
let nextPlayer = gameData.player1Id;
if (gameData.turnMarker === "1") nextPlayer = gameData.player2Id;
addPlyToPtnFile(gameData.gameId, result);
cleanupFiles(interaction.channel.id);
if (gameData.gameId) {
addToHistoryFile({
gameId: gameData.gameId,
player1: gameData.player1,
player2: gameData.player2,
komi: gameData.komi,
opening: gameData.opening,
result: result,
});
}
await sendMessage(
interaction,
`GG <@${nextPlayer}>! Game Ended ${result}\nHere's a link to the completed game:\nID: [${
gameData.gameId
}](${getLink(gameData.gameId)})`
);
clearInactiveTimer(interaction);
setDeleteTimer(interaction);
return renameChannel(interaction, false);
},
};