@@ -8,8 +8,11 @@ import {
88 roleMention ,
99 MessageFlags
1010} from "discord.js" ;
11+ import { Routes } from "farming-simulator-types/2025" ;
1112import { 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 ( / h t t p s : \/ \/ ( w w w \. ) ? f a r m i n g - s i m u l a t o r \. c o m \/ m o d \. p h p \? m o d _ i d = (?< code > \d + ) / ) ;
1316
1417export default new Command < "chatInput" > ( {
1518 async autocomplete ( interaction ) {
@@ -189,6 +192,38 @@ 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+ if ( res ?. status === 200 ) {
220+ await interaction . editReply ( "Successfully started installing mod" ) ;
221+ } else {
222+ await interaction . editReply ( "Failed to start installing mod" ) ;
223+ }
224+
225+ break ;
226+ }
192227 case "rename-role" : {
193228 if ( ! interaction . member . roles . cache . hasAny ( ...serverObj . managerRoles ) ) return youNeedRole ( interaction , "mpManager" ) ;
194229
@@ -325,6 +360,19 @@ export default new Command<"chatInput">({
325360 }
326361 ]
327362 } ,
363+ {
364+ type : ApplicationCommandOptionType . Subcommand ,
365+ name : "install-mod" ,
366+ description : "Install a ModHub mod onto the server" ,
367+ options : [
368+ {
369+ type : ApplicationCommandOptionType . String ,
370+ name : "link" ,
371+ description : "The ModHub mod link" ,
372+ required : true
373+ }
374+ ]
375+ } ,
328376 {
329377 type : ApplicationCommandOptionType . Subcommand ,
330378 name : "rename-role" ,
0 commit comments