announcements #18

Merged
kenobi merged 13 commits from feat/announce into master 2023-06-15 22:05:20 +02:00
Showing only changes of commit a5eab2f7be - Show all commits

View File

@ -130,7 +130,7 @@ export class ExtendedClient extends Client {
const textChannel: TextChannel = this.getAnnouncementChannelForGuild(guild.id)
this.announcementRoleHandlerTask.set(guild.id, schedule("*/10 * * * * *", async () => {
const requestId = uuid()
const messages = (await textChannel.messages.fetchPinned()).filter(message => message.cleanContent.includes("[announcement]"))
const messages = (await textChannel.messages.fetchPinned()).filter(message => message.cleanContent.includes("[initial]"))
if (messages.size > 1) {
logger.error("More than one pinned announcement Messages found. Unable to know which one people react to. Please fix!", { guildId: guild.id, requestId })
@ -138,9 +138,11 @@ export class ExtendedClient extends Client {
logger.error("Could not find any pinned announcement messages. Unable to manage roles!", { guildId: guild.id, requestId })
kenobi marked this conversation as resolved
Review

Unable to continue, should result in a return.

Unable to continue, should result in a return.
}
const message = messages.at(0)!
const message = await messages.at(0)!.fetch()
kenobi marked this conversation as resolved Outdated
const message = await messages.at(0)?.fetch()
if (!message) {
  logger.error(`No pinned message found`,{requestId,guildId})
  return
}
``` const message = await messages.at(0)?.fetch() if (!message) { logger.error(`No pinned message found`,{requestId,guildId}) return } ```
//logger.debug(`Message: ${JSON.stringify(message, null, 2)}`, { guildId: guild.id, requestId })
const reactions = await message.reactions.resolve("🎫")
const reactions = message.reactions.resolve("🎫")
//logger.debug(`reactions: ${JSON.stringify(reactions, null, 2)}`, { guildId: guild.id, requestId })
if (reactions) {
manageAnnouncementRoles(message.guild, reactions, requestId)
} else {
@ -149,6 +151,7 @@ export class ExtendedClient extends Client {
}))
}
}
public stopAnnouncementRoleBackgroundTask(guild: string | Guild, requestId: string) {
kenobi marked this conversation as resolved Outdated

Would it be possible to just use string as type for guild so we don't have to check multiple times if we have a guild object?

Would it be possible to just use string as type for `guild` so we don't have to check multiple times if we have a guild object?
const guildId: string = guild instanceof Guild ? guild.id : guild
const task: ScheduledTask | undefined = guild instanceof Guild ? this.announcementRoleHandlerTask.get(guild.id) : this.announcementRoleHandlerTask.get(guild)