@@ -522,19 +522,38 @@ class serverHandler {
522522 .deleteOne(toDelete);
523523 }
524524 }
525- async discordHandler(data) {
525+ async discordHandler(data: OutputData ) {
526526 if (data.server.dev) return; // ignore dev server
527527 if (data.server.hidden) return; // return if server is hidden
528528 const message = data.line.replace(
529529 "${serverName}",
530530 `<#${data.server.discordid}>`
531531 );
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*) was used/)) {
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+ }
533552 const channel = this.client.channels.cache.get(data.server.discordid);
534553 channel.isText() &&
535554 channel.send({
536- embeds: [new MessageEmbed( embed) ],
537- content: `<@&${config.moderatorroleid}>`,
555+ embeds: [embed],
556+ content: shouldPing ? `<@&${config.moderatorroleid}>` : "Command used" ,
538557 });
539558 const modchannel = this.client.channels.cache.get(
540559 this.client.config.moderatorchannel
0 commit comments