Skip to content

Commit b93d4e7

Browse files
authored
feat: add match map pause notifications for admins and tournament org… (#101)
Co-authored-by: Flegma <Flegma@users.noreply.github.com>
1 parent 13e7784 commit b93d4e7

15 files changed

Lines changed: 1946 additions & 1446 deletions

File tree

hasura/enums/notification-types.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ INSERT INTO e_notification_types ("value", "description") VALUES
44
('GameNodeStatus', 'GameNodeStatus'),
55
('NameChangeRequest', 'NameChangeRequest'),
66
('DedicatedServerStatus', 'DedicatedServerStatus'),
7-
('DedicatedServerRconStatus', 'DedicatedServerRconStatus')
7+
('DedicatedServerRconStatus', 'DedicatedServerRconStatus'),
8+
('MatchStatusChange', 'Match Status Change Notification')
89
ON CONFLICT("value") DO UPDATE
910
SET "description" = EXCLUDED."description";

hasura/metadata/databases/default/tables/public_tournaments.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ insert_permissions:
109109
organizer_steam_id: x-hasura-user-id
110110
columns:
111111
- description
112+
- discord_notifications_enabled
112113
- match_options_id
113114
- name
114115
- start
@@ -143,6 +144,7 @@ insert_permissions:
143144
organizer_steam_id: x-hasura-user-id
144145
columns:
145146
- description
147+
- discord_notifications_enabled
146148
- match_options_id
147149
- name
148150
- start
@@ -176,6 +178,7 @@ insert_permissions:
176178
organizer_steam_id: x-hasura-user-id
177179
columns:
178180
- description
181+
- discord_notifications_enabled
179182
- match_options_id
180183
- name
181184
- start
@@ -211,6 +214,7 @@ insert_permissions:
211214
organizer_steam_id: x-hasura-user-id
212215
columns:
213216
- description
217+
- discord_notifications_enabled
214218
- match_options_id
215219
- name
216220
- start
@@ -242,6 +246,7 @@ insert_permissions:
242246
organizer_steam_id: x-hasura-user-id
243247
columns:
244248
- description
249+
- discord_notifications_enabled
245250
- match_options_id
246251
- name
247252
- start
@@ -274,6 +279,7 @@ insert_permissions:
274279
organizer_steam_id: x-hasura-user-id
275280
columns:
276281
- description
282+
- discord_notifications_enabled
277283
- match_options_id
278284
- name
279285
- start
@@ -284,6 +290,7 @@ select_permissions:
284290
columns:
285291
- created_at
286292
- description
293+
- discord_notifications_enabled
287294
- id
288295
- match_options_id
289296
- name
@@ -310,6 +317,7 @@ select_permissions:
310317
columns:
311318
- created_at
312319
- description
320+
- discord_notifications_enabled
313321
- id
314322
- match_options_id
315323
- name
@@ -339,6 +347,7 @@ update_permissions:
339347
permission:
340348
columns:
341349
- description
350+
- discord_notifications_enabled
342351
- name
343352
- start
344353
- status
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Remove per-tournament Discord override column
2+
ALTER TABLE "public"."tournaments"
3+
DROP COLUMN IF EXISTS "discord_notifications_enabled";
4+
5+
-- Remove MatchStatusChange from notification types
6+
DELETE FROM e_notification_types WHERE "value" = 'MatchStatusChange';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Add MatchStatusChange to notification types
2+
INSERT INTO e_notification_types ("value", "description") VALUES
3+
('MatchStatusChange', 'Match Status Change Notification')
4+
ON CONFLICT("value") DO UPDATE SET "description" = EXCLUDED."description";
5+
6+
-- Add per-tournament Discord override column
7+
ALTER TABLE "public"."tournaments"
8+
ADD COLUMN IF NOT EXISTS "discord_notifications_enabled" boolean DEFAULT NULL;

src/game-server-node/jobs/CheckServerPluginVersions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { GameServerQueues } from "../enums/GameServerQueues";
33
import { HasuraService } from "../../hasura/hasura.service";
44
import { UseQueue } from "../../utilities/QueueProcessors";
55
import { NotificationsService } from "../../notifications/notifications.service";
6+
import { DISCORD_COLORS } from "../../notifications/utilities/constants";
67

78
@UseQueue("GameServerNode", GameServerQueues.PluginVersion)
89
export class CheckServerPluginVersions extends WorkerHost {
@@ -101,6 +102,6 @@ export class CheckServerPluginVersions extends WorkerHost {
101102
message: `${servers_aggregate.aggregate.count} servers has out of date plugins.`,
102103
title: "Plugin Out of Date",
103104
role: "administrator",
104-
});
105+
}, undefined, DISCORD_COLORS.RED);
105106
}
106107
}

src/game-server-node/jobs/MarkDedicatedServerOffline.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Job } from "bullmq";
44
import { HasuraService } from "../../hasura/hasura.service";
55
import { UseQueue } from "../../utilities/QueueProcessors";
66
import { NotificationsService } from "../../notifications/notifications.service";
7+
import { DISCORD_COLORS } from "../../notifications/utilities/constants";
78

89
@UseQueue("GameServerNode", GameServerQueues.NodeOffline)
910
export class MarkDedicatedServerOffline extends WorkerHost {
@@ -44,6 +45,6 @@ export class MarkDedicatedServerOffline extends WorkerHost {
4445
title: "Dedicated Server Offline",
4546
role: "administrator",
4647
entity_id: job.data.serverId,
47-
});
48+
}, undefined, DISCORD_COLORS.RED);
4849
}
4950
}

src/game-server-node/jobs/MarkGameServerNodeOffline.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Job } from "bullmq";
44
import { HasuraService } from "../../hasura/hasura.service";
55
import { UseQueue } from "../../utilities/QueueProcessors";
66
import { NotificationsService } from "../../notifications/notifications.service";
7+
import { DISCORD_COLORS } from "../../notifications/utilities/constants";
78

89
@UseQueue("GameServerNode", GameServerQueues.NodeOffline)
910
export class MarkGameServerNodeOffline extends WorkerHost {
@@ -39,6 +40,6 @@ export class MarkGameServerNodeOffline extends WorkerHost {
3940
title: "Game Server Node Offline",
4041
role: "administrator",
4142
entity_id: job.data.node,
42-
});
43+
}, undefined, DISCORD_COLORS.RED);
4344
}
4445
}

src/game-server-node/jobs/MarkGameServerNodeOnline.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { GameServerQueues } from "../enums/GameServerQueues";
33
import { Job } from "bullmq";
44
import { UseQueue } from "../../utilities/QueueProcessors";
55
import { NotificationsService } from "../../notifications/notifications.service";
6+
import { DISCORD_COLORS } from "../../notifications/utilities/constants";
67

78
@UseQueue("GameServerNode", GameServerQueues.NodeOffline)
89
export class MarkGameServerNodeOnline extends WorkerHost {
@@ -36,6 +37,6 @@ export class MarkGameServerNodeOnline extends WorkerHost {
3637
title: "Game Server Node Online",
3738
role: "administrator",
3839
entity_id: job.data.node,
39-
});
40+
}, undefined, DISCORD_COLORS.GREEN);
4041
}
4142
}

src/matches/events/MatchMapStatusEvent.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
import MatchEventProcessor from "./abstracts/MatchEventProcessor";
22
import { e_match_map_status_enum } from "../../../generated";
3+
import { HasuraService } from "../../hasura/hasura.service";
4+
import { MatchAssistantService } from "../match-assistant/match-assistant.service";
5+
import { Logger } from "@nestjs/common";
6+
import { ChatService } from "../../chat/chat.service";
7+
import { NotificationsService } from "../../notifications/notifications.service";
38

49
export default class MatchMapStatusEvent extends MatchEventProcessor<{
510
status: e_match_map_status_enum;
611
winning_lineup_id?: string;
712
}> {
13+
constructor(
14+
logger: Logger,
15+
hasura: HasuraService,
16+
matchAssistant: MatchAssistantService,
17+
chat: ChatService,
18+
private readonly notifications: NotificationsService,
19+
) {
20+
super(logger, hasura, matchAssistant, chat);
21+
}
22+
823
public async process() {
924
const { matches_by_pk: match } = await this.hasura.query({
1025
matches_by_pk: {
@@ -41,6 +56,10 @@ export default class MatchMapStatusEvent extends MatchEventProcessor<{
4156
},
4257
});
4358

59+
if (this.data.status === "Paused") {
60+
void this.notifications.sendMatchMapPauseNotification(this.matchId);
61+
}
62+
4463
if (isFinished) {
4564
if (update_match_maps_by_pk.match.current_match_map_id !== null) {
4665
await this.matchAssistant.sendServerMatchId(this.matchId);

src/matches/matches.controller.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { DiscordBotOverviewService } from "../discord-bot/discord-bot-overview/d
1010
import { DiscordBotMessagingService } from "../discord-bot/discord-bot-messaging/discord-bot-messaging.service";
1111
import { DiscordBotVoiceChannelsService } from "../discord-bot/discord-bot-voice-channels/discord-bot-voice-channels.service";
1212
import {
13+
e_match_status_enum,
1314
match_map_veto_picks_set_input,
1415
matches_set_input,
1516
servers_set_input,
@@ -20,6 +21,7 @@ import { ConfigService } from "@nestjs/config";
2021
import { AppConfig } from "src/configs/types/AppConfig";
2122
import { PostgresService } from "src/postgres/postgres.service";
2223
import { NotificationsService } from "../notifications/notifications.service";
24+
import { DISCORD_COLORS } from "../notifications/utilities/constants";
2325
import { MatchmakeService } from "src/matchmaking/matchmake.service";
2426
import { InjectQueue } from "@nestjs/bullmq";
2527
import { Queue } from "bullmq";
@@ -307,6 +309,18 @@ export class MatchesController {
307309

308310
const status = data.new.status;
309311

312+
if (
313+
data.op === "UPDATE" &&
314+
data.old.status !== data.new.status &&
315+
data.new.status
316+
) {
317+
void this.notifications.sendMatchStatusNotification(
318+
matchId,
319+
data.new.status as e_match_status_enum,
320+
data.old.status as e_match_status_enum,
321+
);
322+
}
323+
310324
if (data.op === "DELETE") {
311325
await this.chatService.removeLobby(ChatLobbyType.Match, matchId);
312326
}
@@ -682,7 +696,7 @@ export class MatchesController {
682696
title: "Match Assistanced Required",
683697
role: "match_organizer",
684698
entity_id: data.match_id,
685-
});
699+
}, undefined, DISCORD_COLORS.RED);
686700

687701
return {
688702
success: true,

0 commit comments

Comments
 (0)