Skip to content

Commit

Permalink
feat: add datasektionen role on verify if year tag exists
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasvatn committed Sep 30, 2022
1 parent 17c5dd0 commit 491e640
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/shared/utils/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getHodisUser } from "./hodis";

export async function hasRole(user: User, roleName: string): Promise<boolean> {
const guildMember = await getGuildMember(user);
return !!guildMember.roles.cache.find(role => role.name === roleName);
return !!guildMember.roles.cache.find((role) => role.name === roleName);
}

/**
Expand All @@ -17,7 +17,7 @@ export async function hasRoleVerified(user: User): Promise<boolean> {

export async function setRole(user: User, roleName: string): Promise<void> {
const guild = await getGuild();
const role = guild.roles.cache.find(r => r.name === roleName);
const role = guild.roles.cache.find((r) => r.name === roleName);
if (!role) {
throw new Error(`Role ${roleName} does not exist on the Server!`);
}
Expand All @@ -44,11 +44,16 @@ export async function setN0llanRole(user: User, kthId: string): Promise<void> {
}
}

export async function setYearRole(user: User, kthId: string) : Promise<void> {
export async function setYearRole(user: User, kthId: string): Promise<void> {
const hodisUser = await getHodisUser(kthId);
const yearTag = hodisUser.tag.split(",").find(tag => tag.match(/^D\d{2}$/i))
const yearTag = hodisUser.tag
.split(",")
.find((tag) => tag.match(/^D\d{2}$/i));
if (yearTag) {
const yearTagWithDash = `${yearTag.slice(0, 1).toUpperCase()}-${yearTag.slice(1)}`
const yearTagWithDash = `${yearTag
.slice(0, 1)
.toUpperCase()}-${yearTag.slice(1)}`;
await setRole(user, yearTagWithDash);
await setRole(user, "Datasektionen");
}
}

0 comments on commit 491e640

Please sign in to comment.