@@ -10,6 +10,7 @@ import {
1010 hasRole ,
1111 isMPStaff ,
1212 jsonFromXML ,
13+ UUID_LENGTH ,
1314 youNeedRole
1415} from "#util" ;
1516import type { BanFormat , DedicatedServerConfig , FarmFormat } from "#typings" ;
@@ -19,7 +20,7 @@ const allServersChoices = fs25Servers.entries().map(([serverAcro, { fullName }])
1920
2021export default new Command < "chatInput" > ( {
2122 async run ( interaction ) {
22- if ( ! isMPStaff ( interaction . member ) ) return await youNeedRole ( interaction , "mpStaff" ) ;
23+ if ( ! isMPStaff ( interaction . member ) ) return youNeedRole ( interaction , "mpStaff" ) ;
2324
2425 const now = Date . now ( ) ;
2526
@@ -108,7 +109,7 @@ export default new Command<"chatInput">({
108109 break ;
109110 } ;
110111 case "mop" : {
111- if ( ! hasRole ( interaction . member , "mpManager" ) ) return await youNeedRole ( interaction , "mpManager" ) ;
112+ if ( ! hasRole ( interaction . member , "mpManager" ) ) return youNeedRole ( interaction , "mpManager" ) ;
112113
113114 const chosenServer = interaction . options . getString ( "server" , true ) ;
114115 const chosenAction = interaction . options . getString ( "action" , true ) as "items.xml" | "players.xml" ;
@@ -139,24 +140,24 @@ export default new Command<"chatInput">({
139140 return ;
140141 }
141142
142- if ( ! hasRole ( interaction . member , "mpManager" ) ) return await youNeedRole ( interaction , "mpManager" ) ;
143+ if ( ! hasRole ( interaction . member , "mpManager" ) ) return youNeedRole ( interaction , "mpManager" ) ;
143144
144145 await interaction . deferReply ( ) ;
145146
146147 let data ;
147148 const banAttachment = interaction . options . getAttachment ( "bans" ) ;
148149
149- if ( ! banAttachment ) return await interaction . editReply ( "Canceled: A ban file must be supplied" ) ;
150+ if ( ! banAttachment ) return interaction . editReply ( "Canceled: A ban file must be supplied" ) ;
150151
151152 const banData = await ( await fetch ( banAttachment . url ) ) . text ( ) ;
152153
153154 try {
154155 data = jsonFromXML < BanFormat > ( banData ) ;
155156 } catch ( err ) {
156- return await interaction . editReply ( "Canceled: Improper file (not XML)" ) ;
157+ return interaction . editReply ( "Canceled: Improper file (not XML)" ) ;
157158 }
158159
159- if ( ! data . blockedUserIds ?. user [ 0 ] ?. _attributes ?. displayName ) return await interaction . editReply ( "Canceled: Improper file (data format)" ) ;
160+ if ( ! data . blockedUserIds ?. user [ 0 ] ?. _attributes ?. displayName ) return interaction . editReply ( "Canceled: Improper file (data format)" ) ;
160161
161162 await ftpActions . put ( banData , "blockedUserIds.xml" ) ;
162163
@@ -170,30 +171,30 @@ export default new Command<"chatInput">({
170171 const chosenServer = interaction . options . getString ( "server" , true ) ;
171172 const name = interaction . options . getString ( "name" , true ) ;
172173
173- function permIcon ( perm : string , key : string ) {
174- if ( perm === "true" ) {
174+ function formatPermission ( key : string , value : string ) {
175+ if ( value === "true" ) {
175176 return "✅" ;
176- } else if ( perm === "false" ) {
177+ } else if ( value === "false" ) {
177178 return "❌" ;
178179 } else if ( key === "timeLastConnected" ) {
179- const utcDate = new Date ( perm ) ;
180+ const utcDate = new Date ( value ) ;
180181
181182 utcDate . setMinutes ( utcDate . getMinutes ( ) - utcDate . getTimezoneOffset ( ) + fs25Servers . getPublicOne ( chosenServer ) . utcDiff ) ;
182183
183184 return utcDate . toUTCString ( ) ;
184- } else return perm ;
185+ } else return value ;
185186 }
186187
187188 const data = await new FTPActions ( fs25Servers . getPublicOne ( chosenServer ) . ftp ) . get ( "savegame1/farms.xml" ) ;
188189 const farmData = jsonFromXML < FarmFormat > ( data ) ;
189190 const playerData = farmData . farms . farm [ 0 ] . players . player . find ( x =>
190- ( name . length === 44 ? x . _attributes . uniqueUserId : x . _attributes . lastNickname ) === name
191+ ( name . length === UUID_LENGTH ? x . _attributes . uniqueUserId : x . _attributes . lastNickname ) === name
191192 ) ;
193+ const resultText = playerData
194+ ? codeBlock ( Object . entries ( playerData . _attributes ) . map ( x => x [ 0 ] . padEnd ( 18 , " " ) + formatPermission ( x [ 0 ] , x [ 1 ] ) ) . join ( "\n" ) )
195+ : "No green farm data found with that name/UUID" ;
192196
193- await interaction . editReply ( playerData
194- ? codeBlock ( Object . entries ( playerData . _attributes ) . map ( x => x [ 0 ] . padEnd ( 18 , " " ) + permIcon ( x [ 1 ] , x [ 0 ] ) ) . join ( "\n" ) )
195- : "No green farm data found with that name/UUID"
196- ) ;
197+ await interaction . editReply ( resultText ) ;
197198
198199 break ;
199200 } ;
@@ -202,7 +203,7 @@ export default new Command<"chatInput">({
202203 const user = interaction . options . getUser ( "user" , true ) ;
203204 const playerData = ( await db . select ( ) . from ( playerTimes25Table ) . where ( eq ( playerTimes25Table . uuid , uuid ) ) ) . at ( 0 ) ;
204205
205- if ( ! playerData ) return await interaction . reply ( "No playerTimes data found with that UUID" ) ;
206+ if ( ! playerData ) return interaction . reply ( "No playerTimes data found with that UUID" ) ;
206207
207208 await db . update ( playerTimes25Table ) . set ( { discordId : user . id } ) . where ( eq ( playerTimes25Table . uuid , uuid ) ) ;
208209
@@ -214,7 +215,7 @@ export default new Command<"chatInput">({
214215 const chosenServer = interaction . options . getString ( "server" , true ) ;
215216 const serverConfig = interaction . client . config . fs25 [ chosenServer ] ;
216217
217- if ( ! interaction . member . roles . cache . hasAny ( ...serverConfig . managerRoles ) ) return await youNeedRole ( interaction , "mpManager" ) ;
218+ if ( ! interaction . member . roles . cache . hasAny ( ...serverConfig . managerRoles ) ) return youNeedRole ( interaction , "mpManager" ) ;
218219
219220 await interaction . deferReply ( ) ;
220221
@@ -232,22 +233,22 @@ export default new Command<"chatInput">({
232233
233234 const chosenServer = interaction . options . getString ( "server" , true ) ;
234235 const data = await new FTPActions ( fs25Servers . getPublicOne ( chosenServer ) . ftp ) . get ( "dedicated_server/dedicatedServerConfig.xml" ) ;
235- const pw = jsonFromXML < DedicatedServerConfig > ( data ) . gameserver . settings . game_password . _text ;
236+ const password = jsonFromXML < DedicatedServerConfig > ( data ) . gameserver . settings . game_password . _text ;
237+ const resultText = password
238+ ? `Current password for **${ chosenServer . toUpperCase ( ) } ** is \`${ password } \``
239+ : `Password not set for **${ chosenServer . toUpperCase ( ) } **` ;
236240
237- await interaction . editReply ( pw
238- ? `Current password for **${ chosenServer . toUpperCase ( ) } ** \`${ pw } \``
239- : `Password not set for **${ chosenServer . toUpperCase ( ) } **`
240- ) ;
241+ await interaction . editReply ( resultText ) ;
241242
242243 break ;
243244 } ;
244245 case "roles" : {
245- if ( ! hasRole ( interaction . member , "mpManager" ) ) return await youNeedRole ( interaction , "mpManager" ) ;
246+ if ( ! hasRole ( interaction . member , "mpManager" ) ) return youNeedRole ( interaction , "mpManager" ) ;
246247
247248 const member = interaction . options . getMember ( "member" ) ;
248249 const mainRoles = interaction . client . config . mainServer . roles ;
249250
250- if ( ! member ) return await interaction . reply ( { content : "You need to select a member that is in this server" , flags : MessageFlags . Ephemeral } ) ;
251+ if ( ! member ) return interaction . reply ( { content : "You need to select a member that is in this server" , flags : MessageFlags . Ephemeral } ) ;
251252
252253 const roleName = interaction . options . getString ( "role" , true ) as "trustedFarmer" | "mpFarmManager" | "mpJrAdmin" | "mpSrAdmin" ;
253254 const roleId = mainRoles [ roleName ] ;
@@ -261,7 +262,9 @@ export default new Command<"chatInput">({
261262 . setColor ( interaction . client . config . EMBED_COLOR )
262263 ] } ,
263264 async confirm ( int ) {
264- if ( roleName !== "trustedFarmer" ) {
265+ if ( roleName === "trustedFarmer" ) {
266+ await member . roles . remove ( roleId ) ;
267+ } else {
265268 const slicedNick = {
266269 mpFarmManager : "MP Farm Manager" ,
267270 mpJrAdmin : "MP Jr. Admin" ,
@@ -272,9 +275,9 @@ export default new Command<"chatInput">({
272275 roles : roles
273276 . filter ( x => x !== roleId && x !== mainRoles . mpStaff )
274277 . concat ( [ mainRoles . formerStaff , mainRoles . trustedFarmer ] ) ,
275- nick : member . nickname ! . replace ( slicedNick , "Former Staff" )
278+ nick : member . nickname ? .replace ( slicedNick , "Former Staff" )
276279 } ) ;
277- } else await member . roles . remove ( roleId ) ;
280+ }
278281
279282 await int . update ( {
280283 embeds : [ new EmbedBuilder ( )
0 commit comments