class Discorb::Presence::Activity
Represents an activity of a user.
Attributes
@!visibility private
@return [Discorb::Snowflake] The application id of the activity.
@return [Discorb::Presence::Activity::Asset] The assets of the activity. @return [nil] If the activity has no assets.
@return [Time] The time the activity was created.
@return [String] The details of the activity.
@return [Discorb::Emoji] The emoji of the activity.
@return [Discorb::Presence::Activity::Flag] The flags of the activity.
@return [Discorb::StageInstance] The instance of the activity. @return [nil] If the activity is not a stage activity.
@return [String] The name of the activity.
@return [Discorb::Presence::Activity::Party] The party of the activity. @return [nil] If the activity is not a party activity.
@return [Time] The time the activity was created.
@return [String] The state of party.
@return [Discorb::Presence::Activity::Timestamps] The timestamps of the activity.
@return [:game, :streaming, :listening, :watching, :custom, :competing] The type of the activity.
@return [String] The url of the activity.
Public Class Methods
@!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
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