@@ -9,7 +9,7 @@ import { ClientExt } from "../types/DiscordTypes";
9
9
import { IAutomodRule } from "../types/util" ;
10
10
import { tall } from 'tall' ;
11
11
import { DiscordBotUser , DummyNexusModsUser } from "../api/DiscordBotUser" ;
12
- import axios from "axios" ;
12
+ import axios , { AxiosResponse } from "axios" ;
13
13
14
14
const pollTime : number = ( 1000 * 60 * 1 ) ; //1 mins
15
15
@@ -240,16 +240,13 @@ async function analyseMod(mod: Partial<IMod>, rules: IAutomodRule[], user: Disco
240
240
const anHourAgo = new Date ( now . valueOf ( ) - ( 60000 * 60 ) )
241
241
242
242
// Check the user
243
- if ( mod . uploader ! . membershipRoles . length > 1 ) {
244
- // logMessage("Mod Uploaded by a Supporter or Premium user", {mod: mod.name, user: mod.uploader?.name, created: new Date(mod.createdAt || 0)})
245
- return { mod, flags } ;
246
- }
247
- else {
248
- if ( new Date ( mod . uploader ! . joined ) . getTime ( ) >= anHourAgo . getTime ( ) ) {
249
- // logMessage('New uploader', { user: mod.uploader, name: mod.name, anHourAgo, joined: new Date(mod.uploader!.joined) })
250
- flags . low . push ( 'New account' ) ;
251
- }
252
- }
243
+ // if (mod.uploader!.membershipRoles.length > 1) {
244
+ // // logMessage("Mod Uploaded by a Supporter or Premium user", {mod: mod.name, user: mod.uploader?.name, created: new Date(mod.createdAt || 0)})
245
+ // return { mod, flags };
246
+ // }
247
+ // else
248
+
249
+ if ( new Date ( mod . uploader ! . joined ) . getTime ( ) >= anHourAgo . getTime ( ) ) flags . low . push ( 'New account' ) ;
253
250
254
251
if ( mod . uploader ! . modCount <= 1 && flags . low . includes ( 'New account' ) ) {
255
252
if ( ( mod . description ?? '' ) . length < 150 ) {
@@ -356,22 +353,16 @@ async function checkFilePreview(mod: Partial<IMod>, user: DiscordBotUser): Promi
356
353
357
354
// Check the content preview
358
355
try {
359
- const request = await axios ( {
356
+ const request : AxiosResponse < IPreviewDirectory , any > = await axios ( {
360
357
url : latestFile . content_preview_link ,
361
358
transformResponse : ( res ) => JSON . parse ( res ) ,
362
359
validateStatus : ( ) => true ,
363
360
} ) ;
364
361
// No content preview (there's always a link, but it's not always valid!)
365
- if ( request . status == 404 ) flags . low . push ( 'No content preview for latest file.' )
362
+ if ( request . status === 404 ) flags . low . push ( 'No content preview for latest file.' )
363
+ else if ( request . status !== 200 ) flags . low . push ( `Failed to get content preview. HTTP ERROR ${ request . status } ` ) ;
366
364
else {
367
- const allFiles : string [ ] = ( request . data . children as Array < any > ) . reduce ( ( prev , cur ) => {
368
- if ( cur . type === 'file' ) prev . push ( cur . name ) ;
369
- else if ( cur . type === 'directory' ) {
370
- const flattened = flattenDirectory ( cur ) ;
371
- prev = [ ...prev , ...flattened ]
372
- }
373
- return prev ;
374
- } , [ ] ) ;
365
+ const allFiles : string [ ] = flattenDirectory ( request . data ) ;
375
366
376
367
// Check if it's exclusively non-playable files
377
368
const playableFiles = allFiles . filter ( file => {
@@ -382,7 +373,7 @@ async function checkFilePreview(mod: Partial<IMod>, user: DiscordBotUser): Promi
382
373
} ) ;
383
374
384
375
if ( playableFiles . length === 0 ) {
385
- flags . high . push ( "Does not contain any playable files. Likely spam" ) ;
376
+ flags . high . push ( "Does not contain any playable files. Likely spam. " ) ;
386
377
}
387
378
388
379
}
0 commit comments