Fix PR and linting issues
This commit is contained in:
		@@ -1,13 +1,13 @@
 | 
			
		||||
import { ApplicationCommandDataResolvable, Client, ClientOptions, Collection, GatewayIntentBits, Guild, IntentsBitField, Snowflake, TextChannel } from "discord.js";
 | 
			
		||||
import { CommandType } from "../types/commandTypes";
 | 
			
		||||
import fs from 'fs'
 | 
			
		||||
import { config } from "../configuration";
 | 
			
		||||
import { logger } from "../logger";
 | 
			
		||||
import { JellyfinHandler } from "../jellyfin/handler";
 | 
			
		||||
import { ApplicationCommandDataResolvable, Client, ClientOptions, Collection, Guild, IntentsBitField, Snowflake, TextChannel } from "discord.js";
 | 
			
		||||
import fs from 'fs';
 | 
			
		||||
import { ScheduledTask, schedule } from "node-cron";
 | 
			
		||||
import { v4 as uuid } from 'uuid';
 | 
			
		||||
import { manageAnnouncementRoles } from "../commands/announce";
 | 
			
		||||
import { v4 as uuid } from 'uuid'
 | 
			
		||||
import { task } from "../events/guildScheduledEventCreate";
 | 
			
		||||
import { config } from "../configuration";
 | 
			
		||||
import { Maybe } from "../interfaces";
 | 
			
		||||
import { JellyfinHandler } from "../jellyfin/handler";
 | 
			
		||||
import { logger } from "../logger";
 | 
			
		||||
import { CommandType } from "../types/commandTypes";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -82,8 +82,8 @@ export class ExtendedClient extends Client {
 | 
			
		||||
  private async cacheAnnouncementServer(guilds: Collection<Snowflake, Guild>) {
 | 
			
		||||
    for (const guild of guilds.values()) {
 | 
			
		||||
      const channels: TextChannel[] = <TextChannel[]>(await guild.channels.fetch())
 | 
			
		||||
        ?.filter(channel => channel!.id === config.bot.announcement_channel_id)
 | 
			
		||||
        .map((value, _) => value)
 | 
			
		||||
        ?.filter(channel => channel?.id === config.bot.announcement_channel_id)
 | 
			
		||||
        .map((value) => value)
 | 
			
		||||
 | 
			
		||||
      if (!channels || channels.length != 1) {
 | 
			
		||||
        logger.error(`Could not find announcement channel for guild ${guild.name} with guildId ${guild.id}. Found ${channels}`)
 | 
			
		||||
@@ -93,8 +93,8 @@ export class ExtendedClient extends Client {
 | 
			
		||||
      this.announcementChannels.set(guild.id, channels[0])
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  public getAnnouncementChannelForGuild(guildId: string): TextChannel {
 | 
			
		||||
    return this.announcementChannels.get(guildId)! //we set the channel by ourselves only if we find one, I think this is sage (mark my words)
 | 
			
		||||
  public getAnnouncementChannelForGuild(guildId: string): Maybe<TextChannel> {
 | 
			
		||||
    return this.announcementChannels.get(guildId)
 | 
			
		||||
  }
 | 
			
		||||
  public async cacheUsers(guilds: Collection<Snowflake, Guild>) {
 | 
			
		||||
    guilds.forEach((guild: Guild, id: Snowflake) => {
 | 
			
		||||
@@ -127,18 +127,28 @@ export class ExtendedClient extends Client {
 | 
			
		||||
  public async startAnnouncementRoleBackgroundTask(guilds: Collection<string, Guild>) {
 | 
			
		||||
    for (const guild of guilds.values()) {
 | 
			
		||||
      logger.info("Starting background task for announcement role", { guildId: guild.id })
 | 
			
		||||
      const textChannel: TextChannel = this.getAnnouncementChannelForGuild(guild.id)
 | 
			
		||||
      const textChannel: Maybe<TextChannel> = this.getAnnouncementChannelForGuild(guild.id)
 | 
			
		||||
      if(!textChannel) {
 | 
			
		||||
        logger.error("Could not find announcement channel. Aborting", { guildId: guild.id })
 | 
			
		||||
        return
 | 
			
		||||
    }
 | 
			
		||||
      this.announcementRoleHandlerTask.set(guild.id, schedule("*/10 * * * * *", async () => {
 | 
			
		||||
        const requestId = uuid()
 | 
			
		||||
        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 })
 | 
			
		||||
          return
 | 
			
		||||
        } else if (messages.size == 0) {
 | 
			
		||||
          logger.error("Could not find any pinned announcement messages. Unable to manage roles!", { guildId: guild.id, requestId })
 | 
			
		||||
          return
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const message = await messages.at(0)!.fetch()
 | 
			
		||||
        const message = await messages.at(0)?.fetch()
 | 
			
		||||
        if (!message) {
 | 
			
		||||
          logger.error(`No pinned message found`, { guildId: guild.id, requestId })
 | 
			
		||||
          return
 | 
			
		||||
        }
 | 
			
		||||
        //logger.debug(`Message: ${JSON.stringify(message, null, 2)}`, { guildId: guild.id, requestId })
 | 
			
		||||
 | 
			
		||||
        const reactions = message.reactions.resolve("🎫")
 | 
			
		||||
@@ -152,9 +162,8 @@ export class ExtendedClient extends Client {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public stopAnnouncementRoleBackgroundTask(guild: string | Guild, requestId: string) {
 | 
			
		||||
    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)
 | 
			
		||||
  public stopAnnouncementRoleBackgroundTask(guildId: string, requestId: string) {
 | 
			
		||||
    const task: Maybe<ScheduledTask> = this.announcementRoleHandlerTask.get(guildId)
 | 
			
		||||
    if (!task) {
 | 
			
		||||
      logger.error(`No task found for guildID ${guildId}.`, { guildId, requestId })
 | 
			
		||||
      return
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user