class Discorb::Presence::Activity

Represents an activity of a user.

Attributes

activity_types[R]

@!visibility private

application_id[R]

@return [Discorb::Snowflake] The application id of the activity.

assets[R]

@return [Discorb::Presence::Activity::Asset] The assets of the activity. @return [nil] If the activity has no assets.

buttons[R]

@return [Array<Discorb::Presence::Activity::Button>] The buttons of the activity. @return [nil] If the activity has no buttons.

created_at[R]

@return [Time] The time the activity was created.

details[R]

@return [String] The details of the activity.

emoji[R]

@return [Discorb::Emoji] The emoji of the activity.

flags[R]

@return [Discorb::Presence::Activity::Flag] The flags of the activity.

instance[R]

@return [Discorb::StageInstance] The instance of the activity. @return [nil] If the activity is not a stage activity.

name[R]

@return [String] The name of the activity.

party[R]

@return [Discorb::Presence::Activity::Party] The party of the activity. @return [nil] If the activity is not a party activity.

started_at[R]

@return [Time] The time the activity was created.

state[R]

@return [String] The state of party.

timestamps[R]

@return [Discorb::Presence::Activity::Timestamps] The timestamps of the activity.

type[R]

@return [:game, :streaming, :listening, :watching, :custom, :competing] The type of the activity.

url[R]

@return [String] The url of the activity.

Public Class Methods

new(data) click to toggle source

@!visibility private

# File lib/discorb/presence.rb, line 93
def initialize(data)
  @name = data[:name]
  @type = self.class.activity_types[data[:type]]
  @url = data[:url]
  @created_at = Time.at(data[:created_at])
  @timestamps = data[:timestamps] && Timestamps.new(data[:timestamps])
  @application_id = data[:application_id] && Snowflake.new(data[:application_id])
  @details = data[:details]
  @state = data[:state]
  @emoji = if data[:emoji]
      data[:emoji][:id].nil? ? UnicodeEmoji.new(data[:emoji][:name]) : PartialEmoji.new(data[:emoji])
    end
  @party = data[:party] && Party.new(data[:party])
  @assets = data[:assets] && Asset.new(data[:assets])
  @instance = data[:instance]
  @buttons = data[:buttons] && data[:buttons].map { |b| Button.new(b) }
  @flags = data[:flags] && Flag.new(data[:flags])
end

Public Instance Methods

to_s() click to toggle source

Convert the activity to a string.

@return [String] The string representation of the activity.

# File lib/discorb/presence.rb, line 117
def to_s
  case @type
  when :game
    "Playing #{@name}"
  when :streaming
    "Streaming #{@details}"
  when :listening
    "Listening to #{@name}"
  when :watching
    "Watching #{@name}"
  when :custom
    "#{@emoji} #{@state}"
  when :competing
    "Competing in #{@name}"
  end
end