Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct discord channels #87

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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