Wednesday, July 15, 2026 3:59:30 AM
> command_configuration.rb
# frozen_string_literal: true

module ESM
  class CommandConfiguration < ApplicationRecord
    # =============================================================================
    # INITIALIZE
    # =============================================================================

    # =============================================================================
    # DATA STRUCTURE
    # =============================================================================

    attribute :community_id, :integer
    attribute :command_name, :string
    attribute :enabled, :boolean, default: true
    attribute :notify_when_disabled, :boolean, default: true
    attribute :cooldown_quantity, :integer, default: 2
    attribute :cooldown_type, :string, default: "seconds"
    attribute :allowed_in_text_channels, :boolean, default: true
    attribute :allowlist_enabled, :boolean, default: false
    attribute :allowlisted_role_ids, :json, default: []
    attribute :created_at, :datetime
    attribute :updated_at, :datetime
    attribute :deleted_at, :datetime

    # =============================================================================
    # ASSOCIATIONS
    # =============================================================================

    belongs_to :community

    # =============================================================================
    # VALIDATIONS
    # =============================================================================

    # =============================================================================
    # CALLBACKS
    # =============================================================================

    # =============================================================================
    # SCOPES
    # =============================================================================

    # =============================================================================
    # CLASS METHODS
    # =============================================================================

    # =============================================================================
    # INSTANCE METHODS
    # =============================================================================

    def allowlisted_roles
      @allowlisted_roles ||= lambda do
        allowlisted_role_ids.filter_map do |id|
          role = community.roles.find { |r| r.id == id }
          next if role.nil?

          role
        end
      end.call
    end

    def command_class
      ESM::Command[command_name]
    end
  end
end
All opinions represented herein are my own
- © 2024 - 2026 itsthedevman
- build 43aa0d7