implement very basic functionality of role add/rm
Compile the repository / compile (pull_request) Failing after 16s Details
Run unit tests / test (pull_request) Successful in 14s Details

This commit is contained in:
kenobi 2023-11-20 00:27:23 +01:00
parent 016bb243cc
commit 8f320cee5c
1 changed files with 14 additions and 11 deletions

View File

@ -1,5 +1,6 @@
import { Role, User } from "discord.js"; import { Guild, Role, User } from "discord.js";
import { ExtendedClient } from "../structures/client"; import { ExtendedClient } from "../structures/client";
import { GuildMember } from "discord.js";
export default class RoleController { export default class RoleController {
@ -7,19 +8,21 @@ export default class RoleController {
private getMediaRoleForGuild(guildId: string): Role { private getMediaRoleForGuild(guildId: string): Role {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
public addRoleToUser(user: User, role: Role, guildId: string, requestId: string) { public async addRoleToUser(member: GuildMember, role: Role, guildId: string, requestId: string) {
throw new Error("Method not implemented."); return await member.roles.add(role)
} }
private removeRoleFromUser(user: User, roleToAdd: any, guildId: string, requestId: string) { private async removeRoleFromUser(member: GuildMember, role: any, guildId: string, requestId: string) {
throw new Error("Method not implemented."); return await member.roles.remove(role)
} }
public addMediaRoleToUser(user: User, guildId: string, requestId: string) { public async addMediaRoleToUser(user: User, guild: Guild, requestId: string) {
const roleToAdd: Role = this.getMediaRoleForGuild(guildId) const roleToAdd: Role = this.getMediaRoleForGuild(guild.id)
return this.addRoleToUser(user, roleToAdd, guildId, requestId) const guildMember = await guild.members.fetch(user)
return this.addRoleToUser(guildMember, roleToAdd, guild.id, requestId)
} }
public removeMediaRoleFromUser(user: User, guildId: string, requestId: string) { public async removeMediaRoleFromUser(user: User, guild: Guild, requestId: string) {
const roleToRemove: Role = this.getMediaRoleForGuild(guildId) const roleToRemove: Role = this.getMediaRoleForGuild(guild.id)
return this.removeRoleFromUser(user, roleToRemove, guildId, requestId) const guildMember = await guild.members.fetch(user)
return this.removeRoleFromUser(guildMember, roleToRemove, guild.id, requestId)
} }
} }