feat/40-reroll-on-disinterest #54

Merged
kenobi merged 73 commits from feat/40-reroll-on-disinterest into master 2023-11-19 20:24:36 +01:00
Showing only changes of commit 331ff89060 - Show all commits

View File

@ -23,7 +23,7 @@ export class ExtendedClient extends Client {
private pollCloseBackgroundTasks: Collection<string, ScheduledTask> = new Collection()
public constructor(jf: JellyfinHandler) {
const intents: IntentsBitField = new IntentsBitField()
intents.add(IntentsBitField.Flags.GuildMembers, IntentsBitField.Flags.MessageContent, IntentsBitField.Flags.Guilds, IntentsBitField.Flags.DirectMessages, IntentsBitField.Flags.GuildScheduledEvents, IntentsBitField.Flags.GuildVoiceStates)
intents.add(IntentsBitField.Flags.GuildMembers, IntentsBitField.Flags.MessageContent, IntentsBitField.Flags.Guilds, IntentsBitField.Flags.DirectMessages, IntentsBitField.Flags.GuildScheduledEvents, IntentsBitField.Flags.GuildMessageReactions, IntentsBitField.Flags.GuildVoiceStates)
const options: ClientOptions = { intents }
super(options)
this.jellyfin = jf
@ -75,6 +75,7 @@ export class ExtendedClient extends Client {
this.registerCommands(slashCommands, guilds)
this.cacheUsers(guilds)
await this.cacheAnnouncementServer(guilds)
this.fetchAnnouncementChannelMessage(this.announcementChannels)
this.startAnnouncementRoleBackgroundTask(guilds)
this.startPollCloseBackgroundTasks()
})
@ -82,6 +83,11 @@ export class ExtendedClient extends Client {
logger.info(`Error refreshing slash commands: ${error}`)
}
}
private async fetchAnnouncementChannelMessage(channels: Collection<string, TextChannel>): Promise<void> {
channels.each(async ch => {
ch.messages.fetch()
kenobi marked this conversation as resolved Outdated

why is this necessary?

why is this necessary?

It's complicated. I put in some JSDoc comments:

	/**
		* Fetches all messages from the provided channel collection.
		* This is necessary for announcementChannels, because 'old' messages don't receive
		* messageReactionAdd Events, only messages that were sent while the bot is online are tracked
		* automatically.
		* To prevent the need for a dedicated 'Collector' implementation which would listen on specific
		* it's easiest to just fetch all messages from the backlog, which automatically makes the bot track them
		* again.
		* @param {Collection<string, TextChannel>} channels - All channels which should be fecthed for reactionTracking	
		*/

It's complicated. I put in some JSDoc comments: ```ts /** * Fetches all messages from the provided channel collection. * This is necessary for announcementChannels, because 'old' messages don't receive * messageReactionAdd Events, only messages that were sent while the bot is online are tracked * automatically. * To prevent the need for a dedicated 'Collector' implementation which would listen on specific * it's easiest to just fetch all messages from the backlog, which automatically makes the bot track them * again. * @param {Collection<string, TextChannel>} channels - All channels which should be fecthed for reactionTracking */ ```

Figured something like that. Thanks for the comment

Figured something like that. Thanks for the comment
})
}
private async cacheAnnouncementServer(guilds: Collection<Snowflake, Guild>) {
for (const guild of guilds.values()) {
const channels: TextChannel[] = <TextChannel[]>(await guild.channels.fetch())