{"size": 1319, "ext": "js", "max_stars_repo_path": "src/buttons/unwatch.js", "max_stars_repo_name": "Andrews54757/MCObserver-discord", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/buttons/unwatch.js", "max_issues_repo_name": "Andrews54757/MCObserver-discord", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/buttons/unwatch.js", "max_forks_repo_name": "Andrews54757/MCObserver-discord", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.3111111111, "max_line_length": 119, "alphanum_fraction": 0.6550416983}
const { MessageActionRow, MessageButton } = require('discord.js')
const Utils = require('../util/Utils')

module.exports = class UnwatchButton {
  static getName () {
    return 'unwatch'
  }

  static replySilent (interaction, message) {
    interaction.reply({ content: message, ephemeral: true })
  }

  static execute (interaction, bot, name) {
    if (!Utils.hasEditPerms(interaction, bot)) {
      this.replySilent(interaction, 'You do not have permission to use this button!')
      return
    }

    const guildId = interaction.guildId
    const guildHolder = bot.getGuildHolder(guildId)

    const trackedServer = guildHolder.getServer(name)
    if (!trackedServer) {
      this.replySilent(interaction, `Server '${name}' doesn't exist!`)
      return
    }

    if (!trackedServer.isWatchedBy(interaction.channelId)) {
      this.replySilent(interaction, `'${name}' is not being watched by this channel!`)
      return
    }

    trackedServer.unwatch(interaction.channelId)

    const row = new MessageActionRow()
      .addComponents(
        new MessageButton()
          .setCustomId(`watch|${name}`)
          .setLabel(`Watch '${name}'`)
          .setStyle('PRIMARY')
      )
    interaction.reply({ content: `<@${interaction.user.id}> Unwatched '${name}' for this channel`, components: [row] })
  }
}
