4 Commits

Author SHA1 Message Date
a60fc2db7e remove unnecessary maybe type union
All checks were successful
Compile the repository / compile (pull_request) Successful in 17s
Run unit tests / test (pull_request) Successful in 15s
2023-11-25 20:35:15 +01:00
a50ac1716f make return value for role non optional, instead throws on error
All checks were successful
Compile the repository / compile (pull_request) Successful in 22s
Run unit tests / test (pull_request) Successful in 19s
2023-11-25 20:05:37 +01:00
ef39c6315d fix interface name and import
All checks were successful
Compile the repository / compile (pull_request) Successful in 19s
Run unit tests / test (pull_request) Successful in 18s
2023-11-25 19:51:02 +01:00
1f372b0aac fix naming for reaction 2023-11-25 19:50:54 +01:00
4 changed files with 15 additions and 12 deletions

View File

@ -34,20 +34,23 @@ export default class RoleController {
return this.removeRoleFromUser(guildMember, roleToRemove, guild.id, requestId)
}
public async getAnnouncementRoleForGuild(guild: Guild, requestId: string): Promise<Maybe<Role>> {
public async getAnnouncementRoleForGuild(guild: Guild, requestId: string): Promise<Role> {
const mediaRole = this.getAnnounceRoleIdForGuild(guild.id)
return guild.roles.fetch()
const announcement_role = await guild.roles.fetch()
.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 }) })
.catch(error => {
logger.error(`Could not find announcement_role with id ${config.bot.announcement_role}. Error: ${error}`, { requestId, guildId: guild.id })
throw error
})
if (!announcement_role) throw new Error(`Could not find announcement_role with id ${config.bot.announcement_role}.`)
return announcement_role
}
public async assignAnnouncementRolesFromReactions(guild: Guild, reaction: MessageReaction, requestId: string) {
public async assignAnnouncementRolesFromReaction(guild: Guild, reaction: MessageReaction, requestId: string) {
const guildId = guild.id
logger.info("Managing roles", { guildId, requestId })
const announcementRole = await this.getAnnouncementRoleForGuild(guild, requestId)
if (!announcementRole)
throw new Error(`No announcementRole found in guild ${guildId}`)
const usersWhoWantRole: User[] = (await reaction.users.fetch()).filter(user => !user.bot).map(user => user)

View File

@ -5,7 +5,7 @@ import { getMembersWithRoleFromGuild } from "./roleFilter"
import { config } from "../configuration"
import { VoteMessage, isVoteEndedMessage, isVoteMessage } from "./messageIdentifiers"
import { createDateStringFromEvent } from "./dateHelper"
import { Maybe, voteMessageInputInformation as prepareVoteMessageInput } from "../interfaces"
import { Maybe, prepareVoteMessageInput } from "../interfaces"
import format from "date-fns/format"
import toDate from "date-fns/toDate"
import differenceInDays from "date-fns/differenceInDays"

View File

@ -1,7 +1,7 @@
import { Collection } from "@discordjs/collection"
import { GuildScheduledEvent, Role, TextChannel } from "discord.js"
export type Maybe<T> = T | undefined | null | void
export type Maybe<T> = T | undefined | null
export interface Player {
name: string
}
@ -39,7 +39,7 @@ export interface JellyfinConfig {
collectionUser: string
}
export type PermissionLevel = "VIEWER" | "ADMIN" | "TEMPORARY"
export interface voteMessageInputInformation {
export interface prepareVoteMessageInput {
movies: string[],
startDate: Date,
event: GuildScheduledEvent,

View File

@ -173,10 +173,10 @@ export class ExtendedClient extends Client {
}
//logger.debug(`Message: ${JSON.stringify(message, null, 2)}`, { guildId: guild.id, requestId })
const reactions = message.reactions.resolve("🎫")
const ticketReaction = message.reactions.resolve("🎫")
//logger.debug(`reactions: ${JSON.stringify(reactions, null, 2)}`, { guildId: guild.id, requestId })
if (reactions) {
this.roleController.assignAnnouncementRolesFromReactions(message.guild, reactions, requestId)
if (ticketReaction) {
this.roleController.assignAnnouncementRolesFromReaction(message.guild, ticketReaction, requestId)
} else {
logger.error("Did not get reactions! Aborting!", { guildId: guild.id, requestId })
}