Skip to content

Commit

Permalink
Merge branch 'release/1.2.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Frenkii committed Jun 27, 2023
2 parents a1a2587 + dabe460 commit 461072c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "discord-bot",
"version": "1.2.5",
"version": "1.2.6",
"scripts": {
"run": "tsc && node ./dist/src/index.js",
"commands:update": "rimraf ./dist && tsc && node ./dist/scripts/registerCommands.js",
Expand Down
46 changes: 26 additions & 20 deletions src/configs/staffingRequestConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,121 +6,127 @@
"airport": "EDDF",
"trafficThreshold": 10,
"coveringPositions": ["EDDF_.*TWR", "EDDF_.*GND", "EDDF_.*APP"],
"mentionRoles": []
"mentionRoles": ["EDDF"]
},
{
"airport": "EDDM",
"trafficThreshold": 10,
"coveringPositions": ["EDDM_.*TWR", "EDDM_.*GND", "EDDM_.*APP"],
"mentionRoles": []
"mentionRoles": ["EDDM"]
},
{
"airport": "EDDL",
"trafficThreshold": 8,
"coveringPositions": ["EDDL_.*TWR", "EDDL_.*GND", "EDDL_.*APP"],
"mentionRoles": []
"mentionRoles": ["EDDL"]
},
{
"airport": "EDDK",
"trafficThreshold": 8,
"coveringPositions": ["EDDK_.*TWR", "EDDK_.*GND", "EDDK_.*APP"],
"mentionRoles": []
"mentionRoles": ["EDDK"]
},
{
"airport": "EDDB",
"trafficThreshold": 10,
"coveringPositions": ["EDDB_.*TWR", "EDDB_.*GND", "EDDB_.*APP"],
"mentionRoles": []
"mentionRoles": ["EDDB"]
},
{
"airport": "EDDS",
"trafficThreshold": 6,
"coveringPositions": ["EDDS_.*TWR", "EDDS_.*GND", "EDDS_.*APP"],
"mentionRoles": []
"mentionRoles": ["EDDS"]
},
{
"airport": "EDDH",
"trafficThreshold": 10,
"coveringPositions": ["EDDH_.*TWR", "EDDH_.*GND", "EDDH_.*APP"],
"mentionRoles": []
"mentionRoles": ["EDDH"]
},
{
"airport": "EDDN",
"trafficThreshold": 6,
"coveringPositions": ["EDDN_.*TWR", "EDDN_.*GND", "EDDN_.*APP"],
"mentionRoles": ["EDDN"]
},
{
"airport": "EDLW",
"trafficThreshold": 3,
"coveringPositions": ["EDLW_.*TWR", "EDLW_.*GND", "EDLW_.*APP"],
"mentionRoles": []
"mentionRoles": ["Minor EDGG"]
},
{
"airport": "EDLP",
"trafficThreshold": 3,
"coveringPositions": ["EDLP_.*TWR", "EDLP_.*GND", "EDLP_.*APP"],
"mentionRoles": []
"mentionRoles": ["Minor EDGG"]
},
{
"airport": "EDDG",
"trafficThreshold": 3,
"coveringPositions": ["EDDG_.*TWR", "EDDG_.*GND", "EDDG_.*APP"],
"mentionRoles": []
"mentionRoles": ["Minor EDGG"]
},
{
"airport": "EDFH",
"trafficThreshold": 3,
"coveringPositions": ["EDFH_.*TWR", "EDFH_.*GND", "EDFH_.*APP"],
"mentionRoles": []
"mentionRoles": ["Minor EDGG"]
},
{
"airport": "EDDR",
"trafficThreshold": 3,
"coveringPositions": ["EDDR_.*TWR", "EDDR_.*GND", "EDDR_.*APP"],
"mentionRoles": []
"mentionRoles": ["Minor EDGG"]
},
{
"airport": "EDFM",
"trafficThreshold": 3,
"coveringPositions": ["EDFM_.*TWR", "EDFM_.*GND", "EDFM_.*APP"],
"mentionRoles": []
"mentionRoles": ["Minor EDGG"]
},
{
"airport": "EDVK",
"trafficThreshold": 3,
"coveringPositions": ["EDVK_.*TWR", "EDVK_.*GND"],
"mentionRoles": []
"mentionRoles": ["Minor EDWW"]
},
{
"airport": "EDHL",
"trafficThreshold": 3,
"coveringPositions": ["EDHL_.*TWR", "EDHL_.*GND"],
"mentionRoles": []
"mentionRoles": ["Minor EDWW"]
},
{
"airport": "EDVE",
"trafficThreshold": 3,
"coveringPositions": ["EDVE_.*TWR", "EDVE_.*GND"],
"mentionRoles": []
"mentionRoles": ["Minor EDWW"]
},
{
"airport": "EDJA",
"trafficThreshold": 3,
"coveringPositions": ["EDJA_.*TWR", "EDJA_.*GND"],
"mentionRoles": []
"mentionRoles": ["Minor EDMM"]
},
{
"airport": "EDMO",
"trafficThreshold": 3,
"coveringPositions": ["EDMO_.*TWR", "EDMO_.*GND"],
"mentionRoles": []
"mentionRoles": ["Minor EDMM"]
},
{
"airport": "EDMA",
"trafficThreshold": 3,
"coveringPositions": ["EDMA_.*TWR", "EDMA_.*GND"],
"mentionRoles": []
"mentionRoles": ["Minor EDMM"]
},
{
"airport": "EDQM",
"trafficThreshold": 3,
"coveringPositions": ["EDQM_.*TWR", "EDQM_.*GND"],
"mentionRoles": []
"mentionRoles": ["Minor EDMM"]
}
]
}
4 changes: 2 additions & 2 deletions src/jobs/staffingRequest/staffingRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Config } from '../../core/config';
import dataFeedService from '../../services/dataFeed.service';
import { sendBotMessageInChannel } from '../../utils/sendBotMessageInChannel';
import { sendBotMessageInChannel } from '../../utils/sendBotStaffingRequest';
import { StaffingConfig, getPilotCountAround } from './util';

async function checkStaffingAlerts(config: StaffingConfig, alertCooldown: Record<string, number>): Promise<void> {
Expand Down Expand Up @@ -41,7 +41,7 @@ async function checkStaffingAlerts(config: StaffingConfig, alertCooldown: Record
// send the alert and update the cooldown data
console.debug(`Sending alert for ${alert.airport}`);

await sendBotMessageInChannel(`${alert.airport} is looking for controllers!`, `${count} pilot(s) waiting for your ATC service. 📡`, Config.STAFFING_REQUEST_CHANNEL_ID);
await sendBotMessageInChannel(`${alert.airport} is looking for controllers!`, `${count} pilot(s) waiting for your ATC service. 📡`, alert.mentionRoles );

alertCooldown[alert.airport] = new Date().getTime() + (config.alert_cooldown * 1000 * 60);
}
Expand Down
25 changes: 0 additions & 25 deletions src/utils/sendBotMessageInChannel.ts

This file was deleted.

32 changes: 32 additions & 0 deletions src/utils/sendBotStaffingRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Channel, Role, TextBasedChannel, TextChannel, roleMention } from 'discord.js';
import { DiscordBotClient } from '../core/client';
import { warningEmbed } from '../embeds/default/warningEmbed';
import { Config } from '../core/config';

export async function sendBotMessageInChannel(title: string, message: string, mentionRoles?: string[]) {
try {
const channel: Channel | undefined = await DiscordBotClient.channels.cache.get(Config.STAFFING_REQUEST_CHANNEL_ID);
if (channel == null) {
console.error('Failed to resolve CHANNEL! Failed to send message: ', message);
return;
}

const rolesToMention: string[] = [];
if (mentionRoles) {
for (const mentionRole of mentionRoles) {
let discordRole: Role | undefined = (<TextChannel>channel).guild.roles.cache.find(role => role.name === mentionRole);
if (discordRole) {
rolesToMention.push('<@&' + discordRole.id + '>');
}
}
}

const _warningEmbed = warningEmbed(title, null, message);

await (<TextBasedChannel>channel).send({
content: `${rolesToMention.join(' ')}`,
embeds: [_warningEmbed],
flags: [4096],
});
} catch (error) {}
}

0 comments on commit 461072c

Please sign in to comment.