Sha256: 7b95c33c36c22e20028e9d0ed9ba8a34122766528a02e43e53b428a5aef677c0

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Discorb
  #
  # Represents an activity for Gateway Command.
  #
  class Activity
    # @private
    # @return [{Symbol => Integer}] The mapping of activity types.
    TYPES = {
      playing: 0,
      streaming: 1,
      listening: 2,
      watching: 3,
      competing: 5
    }.freeze

    #
    # Initializes a new Activity.
    #
    # @param [String] name The name of the activity.
    # @param [:playing, :streaming, :listening, :watching, :competing] type The type of activity.
    # @param [String] url The URL of the activity.
    #
    def initialize(name, type = :playing, url = nil)
      @name = name
      @type = TYPES[type] or
        raise ArgumentError, "Invalid activity type: #{type}"
      @url = url
    end

    #
    # Converts the activity to a hash.
    #
    # @return [Hash] A hash representation of the activity.
    #
    def to_hash
      { name: @name, type: @type, url: @url }
    end

    def inspect
      "#<#{self.class} @type=#{@type}>"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
discorb-0.20.0 lib/discorb/gateway_requests.rb