WIP: feat/20-reactions-for-roles #59
@ -8,8 +8,10 @@ import { Maybe } from "../interfaces";
|
||||
export default class RoleController {
|
||||
|
||||
constructor(private client: ExtendedClient) { }
|
||||
private getMediaRoleForGuild(guildId: string): Role {
|
||||
throw new Error("Method not implemented.");
|
||||
private getAnnounceRoleIdForGuild(guildId: string): string {
|
||||
const role = config.bot.announcement_role
|
||||
if (!role) throw new Error(`No announcementRole defined for guild ${guildId}`)
|
||||
return role
|
||||
}
|
||||
public async addRoleToUser(member: GuildMember, role: Role, guildId: string, requestId: string) {
|
||||
logger.info(`Adding Role ${role.id} to user ${member.id}|${member.user.username}`, { requestId, guildId })
|
||||
@ -21,20 +23,22 @@ export default class RoleController {
|
||||
}
|
||||
|
||||
public async addMediaRoleToUser(user: User, guild: Guild, requestId: string) {
|
||||
const roleToAdd: Role = this.getMediaRoleForGuild(guild.id)
|
||||
const roleToAdd = await this.getAnnouncementRoleForGuild(guild, requestId)
|
||||
if (!roleToAdd) throw new Error(`No announcementRole found to add to user`)
|
||||
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 roleToRemove = await this.getAnnouncementRoleForGuild(guild, requestId)
|
||||
if (!roleToRemove) throw new Error(`No announcementRole found to remove from user`)
|
||||
const guildMember = await guild.members.fetch(user)
|
||||
return this.removeRoleFromUser(guildMember, roleToRemove, guild.id, requestId)
|
||||
}
|
||||
|
||||
public async getAnnouncementRoleForGuild(guild: Guild, requestId: string): Promise<Maybe<Role>> {
|
||||
const mediaRole = this.getMediaRoleForGuild(guild.id)
|
||||
const mediaRole = this.getAnnounceRoleIdForGuild(guild.id)
|
||||
return guild.roles.fetch()
|
||||
.then(fetchedRoles => fetchedRoles.find(role => role.id === mediaRole.id))
|
||||
.then(fetchedRoles => fetchedRoles.find(role => role.id === mediaRole))
|
||||
.catch(error => { logger.error(`Could not find announcement_role with id ${config.bot.announcement_role}. Error: ${error}`, { requestId, guildId: guild.id }) })
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
method called reactions but parameter is singular
1f372b0aac