Skip to content

Commit 862f89a

Browse files
committed
Add install-mod command for private servers
1 parent 25b3f1f commit 862f89a

4 files changed

Lines changed: 76 additions & 26 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
},
2222
"dependencies": {
2323
"@napi-rs/canvas": "^0.1.77",
24-
"discord.js": "^14.22.1",
24+
"discord.js": "^14.23.0",
2525
"drizzle-orm": "^0.44.4",
26-
"farming-simulator-types": "^2.0.1",
26+
"farming-simulator-types": "^3.0.0",
2727
"ftp": "^0.3.10",
2828
"lodash": "^4.17.21",
2929
"ms": "^2.1.3",

pnpm-lock.yaml

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/chatInput/mp25.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default new Command<"chatInput">({
6565
if (state !== "confirm") return;
6666
} else await interaction.deferReply();
6767

68-
const [sessionCookie] = await fetch(configServer.url + Routes.webPageLogin(configServer.username, configServer.password))
68+
const [sessionCookie] = await fetch(configServer.url + Routes.webInterfaceLogin(configServer.username, configServer.password))
6969
.then(res => res.headers.getSetCookie());
7070

7171
const response = await fetch(

src/commands/chatInput/private25.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import {
88
roleMention,
99
MessageFlags
1010
} from "discord.js";
11+
import { Routes } from "farming-simulator-types/2025";
1112
import { Command } from "#structures";
12-
import { collectAck, fs25Servers, onPrivate25Farms, youNeedRole } from "#util";
13+
import { collectAck, formatRequestInit, fs25Servers, onPrivate25Farms, youNeedRole } from "#util";
14+
15+
const modLinkRegex = new RegExp(/https:\/\/(www\.)?farming-simulator\.com\/mod\.php\?mod_id=(?<code>\d+)/);
1316

1417
export default new Command<"chatInput">({
1518
async autocomplete(interaction) {
@@ -189,6 +192,40 @@ export default new Command<"chatInput">({
189192

190193
break;
191194
};
195+
case "install-mod": {
196+
if (!interaction.member.roles.cache.hasAny(...serverObj.managerRoles)) return youNeedRole(interaction, "mpManager");
197+
198+
if (interaction.client.fs25Cache[serverAcro].state === 1) return interaction.reply({
199+
content: "Cannot install mod while server is online!",
200+
flags: MessageFlags.Ephemeral
201+
});
202+
203+
const modLink = interaction.options.getString("link", true);
204+
const regexResult = modLinkRegex.exec(modLink);
205+
const foundModId = regexResult?.groups?.code;
206+
207+
if (!regexResult || !foundModId) return interaction.reply({
208+
content: "Invalid link provided! Must be ModHub link from <https://farming-simulator.com/mods.php>",
209+
flags: MessageFlags.Ephemeral
210+
});
211+
212+
await interaction.deferReply();
213+
214+
const res = await fetch(
215+
serverObj.url + Routes.startModDownload(serverObj.username, serverObj.password, foundModId),
216+
formatRequestInit(10_000, `ModInstall-${foundModId}`)
217+
).catch(() => null);
218+
219+
console.log(res);
220+
221+
if (res?.status === 200) {
222+
await interaction.editReply("Successfully started installing mod");
223+
} else {
224+
await interaction.editReply("Failed to start installing mod");
225+
}
226+
227+
break;
228+
}
192229
case "rename-role": {
193230
if (!interaction.member.roles.cache.hasAny(...serverObj.managerRoles)) return youNeedRole(interaction, "mpManager");
194231

@@ -325,6 +362,19 @@ export default new Command<"chatInput">({
325362
}
326363
]
327364
},
365+
{
366+
type: ApplicationCommandOptionType.Subcommand,
367+
name: "install-mod",
368+
description: "Install a ModHub mod onto the server",
369+
options: [
370+
{
371+
type: ApplicationCommandOptionType.String,
372+
name: "link",
373+
description: "The ModHub mod link",
374+
required: true
375+
}
376+
]
377+
},
328378
{
329379
type: ApplicationCommandOptionType.Subcommand,
330380
name: "rename-role",

0 commit comments

Comments
 (0)