@@ -522,19 +522,38 @@ class serverHandler {
522
522
. deleteOne ( toDelete ) ;
523
523
}
524
524
}
525
- async discordHandler ( data ) {
525
+ async discordHandler ( data : OutputData ) {
526
526
if ( data . server . dev ) return ; // ignore dev server
527
527
if ( data . server . hidden ) return ; // return if server is hidden
528
528
const message = data . line . replace (
529
529
"${serverName}" ,
530
530
`<#${ data . server . discordid } >`
531
531
) ;
532
- const embed = JSON . parse ( message ) ;
532
+ const embedData = JSON . parse ( message ) ;
533
+ const embed = new MessageEmbed ( embedData ) ;
534
+ let shouldPing = true ;
535
+ if ( embed . description . match ( / ( \S * ) w a s u s e d / ) ) {
536
+ // console command was used
537
+ // we therefore check if the user has the "Moderator" role in-game
538
+ try {
539
+ const playername =
540
+ embed . fields . find ( ( field ) => field . name === "By" ) ?. value ??
541
+ "this is not a valid factorio name" ;
542
+ const user = await Users . findOne ( { factorioName : playername } ) ;
543
+ const discordUser = await this . client . guilds . cache
544
+ . get ( this . client . consts . guildid )
545
+ . members . fetch ( user . id ) ;
546
+ // if the discord user has the moderator role, we don't ping
547
+ if ( discordUser . roles . cache . get ( this . client . config . moderatorroleid ) ) {
548
+ shouldPing = false ;
549
+ }
550
+ } catch { }
551
+ }
533
552
const channel = this . client . channels . cache . get ( data . server . discordid ) ;
534
553
channel . isText ( ) &&
535
554
channel . send ( {
536
- embeds : [ new MessageEmbed ( embed ) ] ,
537
- content : `<@&${ config . moderatorroleid } >` ,
555
+ embeds : [ embed ] ,
556
+ content : shouldPing ? `<@&${ config . moderatorroleid } >` : "Command used" ,
538
557
} ) ;
539
558
const modchannel = this . client . channels . cache . get (
540
559
this . client . config . moderatorchannel
0 commit comments