Skip to content

Commit 8ad4b77

Browse files
authored
feature: add global organizer chat (#107)
1 parent 86694c5 commit 8ad4b77

4 files changed

Lines changed: 25 additions & 9 deletions

File tree

src/chat/chat.service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { RconService } from "../rcon/rcon.service";
77
import { FiveStackWebSocketClient } from "src/sockets/types/FiveStackWebSocketClient";
88
import { ChatLobbyType } from "./enums/ChatLobbyTypes";
99
import { e_player_roles_enum } from "generated/schema";
10-
10+
import { isRoleAbove } from "src/utilities/isRoleAbove";
1111
@Injectable()
1212
export class ChatService {
1313
private redis: Redis;
@@ -117,6 +117,13 @@ export class ChatService {
117117
if (tournaments.length === 0) {
118118
return;
119119
}
120+
break;
121+
case ChatLobbyType.Organizer:
122+
if (!isRoleAbove(client.user.role, "match_organizer")) {
123+
return;
124+
}
125+
126+
break;
120127

121128
break;
122129
default:

src/chat/enums/ChatLobbyTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export enum ChatLobbyType {
33
Team = "team",
44
MatchMaking = "matchmaking",
55
Tournament = "tournament",
6+
Organizer = "organizers",
67
}

src/notifications/notifications.service.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ export class NotificationsService {
226226
if (shouldNotifyDiscord) {
227227
const discordMessage = `Match status changed to **${readableStatus}**. [View Match](${matchUrl})`;
228228
const color = STATUS_COLORS[newStatus] ?? DISCORD_COLORS.GRAY;
229-
await this.sendDiscordMatchNotification(title, discordMessage, color, null);
229+
await this.sendDiscordMatchNotification(
230+
title,
231+
discordMessage,
232+
color,
233+
null,
234+
);
230235
}
231236
return;
232237
}
@@ -260,7 +265,8 @@ export class NotificationsService {
260265
entity_id: matchId,
261266
});
262267

263-
const notifyKey = `discord_notify_${newStatus}` as keyof typeof tournament;
268+
const notifyKey =
269+
`discord_notify_${newStatus}` as keyof typeof tournament;
264270
const shouldNotifyDiscord = await this.shouldSendDiscordNotification(
265271
tournament[notifyKey] as boolean | null | undefined,
266272
`discord_match_notify_${newStatus}`,
@@ -430,7 +436,9 @@ export class NotificationsService {
430436
}
431437

432438
private isValidDiscordWebhookUrl(url: string): boolean {
433-
return /^https:\/\/(discord\.com|discordapp\.com)\/api\/webhooks\/\d+\/.+$/.test(url);
439+
return /^https:\/\/(discord\.com|discordapp\.com)\/api\/webhooks\/\d+\/.+$/.test(
440+
url,
441+
);
434442
}
435443

436444
private formatRoleMentions(
@@ -449,7 +457,10 @@ export class NotificationsService {
449457
title: string,
450458
message: string,
451459
color: number,
452-
tournament?: Pick<tournaments, "discord_webhook" | "discord_role_id" | "discord_notifications_enabled"> | null,
460+
tournament?: Pick<
461+
tournaments,
462+
"discord_webhook" | "discord_role_id" | "discord_notifications_enabled"
463+
> | null,
453464
) {
454465
if (tournament?.discord_notifications_enabled === false) {
455466
return;

src/tournaments/tournaments.controller.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ export class TournamentsController {
1313
) {}
1414

1515
@HasuraAction()
16-
public async deleteTournament(data: {
17-
user: User;
18-
tournament_id: string;
19-
}) {
16+
public async deleteTournament(data: { user: User; tournament_id: string }) {
2017
const { tournament_id } = data;
2118
this.logger.log(`[${tournament_id}] deleting tournament`);
2219

0 commit comments

Comments
 (0)