Skip to content

Commit 6147ede

Browse files
committed
create-minigame command
1 parent dca9adb commit 6147ede

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

src/commands/create-minigame.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
const { Command } = require("@sapphire/framework");
2+
const { PermissionFlagsBits, EmbedBuilder, time } = require("discord.js");
3+
const { api_secret } = require("../config.json");
4+
const { fetch, FetchResultTypes } = require("@sapphire/fetch");
5+
const { FetchMethods } = require("@sapphire/fetch");
6+
const { Embed } = require("discord.js");
7+
8+
class UserCommand extends Command {
9+
/**
10+
* @param {Command.Context} context
11+
*/
12+
constructor(context) {
13+
super(context, {
14+
// Any Command options you want here
15+
name: "create-minigame",
16+
description: "Rebuild the minigame server with the specified minigame",
17+
});
18+
}
19+
20+
/**
21+
* @param {Command.Registry} registry
22+
*/
23+
registerApplicationCommands(registry) {
24+
registry.registerChatInputCommand((builder) =>
25+
builder //
26+
.setName(this.name)
27+
.setDescription(this.description)
28+
.addStringOption((option) =>
29+
option //
30+
.setName("minigame")
31+
32+
.setDescription("The minigame you want")
33+
.addChoices(
34+
{
35+
name: "UHC",
36+
value: "uhc",
37+
},
38+
{
39+
name: "Missile Wars",
40+
value: "missile-wars",
41+
},
42+
{
43+
name: "Bingo",
44+
value: "bingo",
45+
},
46+
)
47+
.setRequired(true),
48+
),
49+
);
50+
}
51+
52+
/**
53+
* @param {Command.ChatInputCommandInteraction} interaction
54+
*/
55+
async chatInputRun(interaction) {
56+
const minigame = interaction.options.getString("minigame");
57+
const randomstring = Math.random().toString(36).substring(7);
58+
const data = JSON.stringify({
59+
actionId: "4",
60+
arguments: [
61+
{
62+
name: "minigame",
63+
value: `${minigame}`,
64+
},
65+
],
66+
uniqueTrackingId: `${randomstring}`,
67+
});
68+
69+
const embed = new EmbedBuilder()
70+
.setTitle("Minigame Server Created")
71+
.setDescription(
72+
`${interaction.user.username} created a minigame server for ${minigame}`,
73+
);
74+
75+
const options = {
76+
hostname: "localhost:1337",
77+
path: "/api",
78+
method: "POST",
79+
headers: {
80+
"Content-Type": "application/json",
81+
Accept: "application/json",
82+
},
83+
};
84+
85+
const req = https
86+
.request(options, (res) => {
87+
let data = "";
88+
89+
console.log("Status Code:", res.statusCode);
90+
91+
res.on("data", (chunk) => {
92+
data += chunk;
93+
});
94+
95+
res.on("end", () => {
96+
console.log("Response: ", JSON.parse(data));
97+
const Data = JSON.parse(data);
98+
});
99+
})
100+
.on("error", (err) => {
101+
console.log("Error: ", err.message);
102+
});
103+
104+
req.write(data);
105+
req.end();
106+
107+
await interaction.reply({ embeds: [embed] });
108+
}
109+
}
110+
111+
module.exports = {
112+
UserCommand,
113+
};

0 commit comments

Comments
 (0)