jellyfin-discord-bot/server/helper/role.controller.ts
kenobi 8f320cee5c
Some checks failed
Compile the repository / compile (pull_request) Failing after 16s
Run unit tests / test (pull_request) Successful in 14s
implement very basic functionality of role add/rm
2023-11-20 00:27:23 +01:00

29 lines
1.2 KiB
TypeScript

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