Class: Discordrb::Events::PlayingEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/discordrb/events/presence.rb

Overview

Event raised when a user starts or stops playing a game

Instance Attribute Summary collapse

Attributes inherited from Event

#bot

Instance Method Summary collapse

Constructor Details

#initialize(data, bot) ⇒ PlayingEvent

Returns a new instance of PlayingEvent.



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/discordrb/events/presence.rb', line 80

def initialize(data, bot)
  @bot = bot

  @server = bot.server(data['guild_id'].to_i)
  @user = bot.user(data['user']['id'].to_i)
  @game = data['game'] ? data['game']['name'] : nil
  @type = data['game'] ? data['game']['type'].to_i : nil
  # Handle optional 'game' fields safely
  @url = data['game'] && data['game']['url'] ? data['game']['url'] : nil
  @details = data['game'] && data['game']['details'] ? data['game']['details'] : nil
end

Instance Attribute Details

#detailsString (readonly)

Returns what the player is currently doing (ex. game being streamed).

Returns:

  • (String)

    what the player is currently doing (ex. game being streamed)



75
76
77
# File 'lib/discordrb/events/presence.rb', line 75

def details
  @details
end

#gameString (readonly)

Returns the new game the user is playing.

Returns:

  • (String)

    the new game the user is playing.



69
70
71
# File 'lib/discordrb/events/presence.rb', line 69

def game
  @game
end

#serverServer (readonly)

Returns the server on which the presence update happened.

Returns:

  • (Server)

    the server on which the presence update happened.



63
64
65
# File 'lib/discordrb/events/presence.rb', line 63

def server
  @server
end

#typeInteger (readonly)

Returns the type of play. 0 = game, 1 = Twitch.

Returns:

  • (Integer)

    the type of play. 0 = game, 1 = Twitch



78
79
80
# File 'lib/discordrb/events/presence.rb', line 78

def type
  @type
end

#urlString (readonly)

Returns the URL to the stream.

Returns:

  • (String)

    the URL to the stream



72
73
74
# File 'lib/discordrb/events/presence.rb', line 72

def url
  @url
end

#userUser (readonly)

Returns the user whose status got updated.

Returns:

  • (User)

    the user whose status got updated.



66
67
68
# File 'lib/discordrb/events/presence.rb', line 66

def user
  @user
end