-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththeme.js
59 lines (57 loc) · 1.63 KB
/
theme.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
const { SlashCommandBuilder } = require("discord.js");
const { parseTheme } = require("../TPS-Ninja/src");
const {
getGameData,
getTheme,
isGameChannel,
isGameOngoing,
isPlayer,
sendMessage,
setTheme,
} = require("../util");
const handleRedraw = require("./redraw").execute;
module.exports = {
data: new SlashCommandBuilder()
.setName("theme")
.setDescription("Get or set the theme for the current channel.")
.addStringOption((option) =>
option
.setName("theme")
.setDescription("Theme name or JSON")
.setAutocomplete(true)
),
async execute(interaction) {
let theme = interaction.options.getString("theme");
if (!isGameChannel(interaction)) {
return sendMessage(interaction, "This isn't a game channel.", true);
} else if (theme) {
const gameData = getGameData(interaction);
const isOngoing = isGameOngoing(interaction);
if (!isPlayer(interaction.member.id, gameData)) {
return sendMessage(
interaction,
`Only the ${
isOngoing ? "current" : "previous"
} players may change the theme.`,
true
);
}
try {
parseTheme(theme);
} catch (err) {
console.error(err);
return sendMessage(interaction, "Invalid theme", true);
}
if (setTheme(interaction, theme)) {
if (!isGameOngoing(interaction)) {
return sendMessage(interaction, "Theme set.", true);
} else {
handleRedraw(interaction);
}
}
} else {
theme = getTheme(interaction);
return sendMessage(interaction, theme, true);
}
},
};