Skip to content

Commit

Permalink
Merge pull request #87 from ungdev/fix/discord
Browse files Browse the repository at this point in the history
fix: correct discord channels
  • Loading branch information
ThomasLachaux committed Oct 7, 2021
2 parents 1b3ed79 + c862775 commit 86e93b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ model Tournament {
discordRoleId String?
discordRespoRoleId String?
discordCategoryId String?
discordTextCategoryId String?
discordVocalCategoryId String?
@@map("tournaments")
}
Expand Down
20 changes: 17 additions & 3 deletions src/utils/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DiscordChannelPermissionType,
DiscordChannelType,
DiscordRole,
Snowflake,
} from '../controllers/discord/discordApi';
import database from '../services/database';
import { Team, Tournament } from '../types';
Expand All @@ -18,13 +19,14 @@ const createDiscordTeamChannel = async (
channelType: DiscordChannelType,
tournamentId: TournamentId,
teamRole: DiscordRole,
parentId: Snowflake,
) => {
const tournament = await fetchTournament(tournamentId);

return createDiscordChannel({
name: channelName,
type: channelType,
parent_id: tournament.discordCategoryId,
parent_id: parentId,
permission_overwrites: [
{
// The discord server id corresponds to @everyone role id
Expand Down Expand Up @@ -63,8 +65,20 @@ export const setupDiscordTeam = async (team: Team, tournament: Tournament) => {
logger.debug(`Create discord channels for ${team.name}`);
// Create the channels and update in the database the role.
await Promise.all([
createDiscordTeamChannel(team.name, DiscordChannelType.GUILD_TEXT, tournament.id, role),
createDiscordTeamChannel(team.name, DiscordChannelType.GUILD_VOICE, tournament.id, role),
createDiscordTeamChannel(
team.name,
DiscordChannelType.GUILD_TEXT,
tournament.id,
role,
tournament.discordTextCategoryId,
),
createDiscordTeamChannel(
team.name,
DiscordChannelType.GUILD_VOICE,
tournament.id,
role,
tournament.discordVocalCategoryId,
),
database.team.update({ data: { discordRoleId: role.id }, where: { id: team.id } }),
]);
}
Expand Down

0 comments on commit 86e93b1

Please sign in to comment.