Module: OnyxCord::Bot::Presence

Included in:
OnyxCord::Bot
Defined in:
lib/onyxcord/core/bot/presence.rb

Instance Method Summary collapse

Instance Method Details

#competing=(name) ⇒ String

Sets the currently competing status to the specified name.

Parameters:

  • name (String)

    The name of the game to be competing in.

Returns:

  • (String)

    The game that is being competed in now.



69
70
71
72
# File 'lib/onyxcord/core/bot/presence.rb', line 69

def competing=(name)
  gateway_check
  update_status(@status, name, nil, nil, nil, 5)
end

#dndObject

Sets the bot's status to DnD (red icon).



91
92
93
94
# File 'lib/onyxcord/core/bot/presence.rb', line 91

def dnd
  gateway_check
  update_status(:dnd, @activity, nil)
end

#game=(name) ⇒ String Also known as: playing=

Sets the currently playing game to the specified game.

Parameters:

  • name (String)

    The name of the game to be played.

Returns:

  • (String)

    The game that is being played now.



33
34
35
36
# File 'lib/onyxcord/core/bot/presence.rb', line 33

def game=(name)
  gateway_check
  update_status(@status, name, nil)
end

#idleObject Also known as: away

Sets status to idle.



83
84
85
86
# File 'lib/onyxcord/core/bot/presence.rb', line 83

def idle
  gateway_check
  update_status(:idle, @activity, nil)
end

#invisibleObject

Sets the bot's status to invisible (appears offline).



97
98
99
100
# File 'lib/onyxcord/core/bot/presence.rb', line 97

def invisible
  gateway_check
  update_status(:invisible, @activity, nil)
end

#listening=(name) ⇒ String

Sets the current listening status to the specified name.

Parameters:

  • name (String)

    The thing to be listened to.

Returns:

  • (String)

    The thing that is now being listened to.



43
44
45
46
# File 'lib/onyxcord/core/bot/presence.rb', line 43

def listening=(name)
  gateway_check
  update_status(@status, name, nil, nil, nil, 2)
end

#onlineObject Also known as: on

Sets status to online.



75
76
77
78
# File 'lib/onyxcord/core/bot/presence.rb', line 75

def online
  gateway_check
  update_status(:online, @activity, @streamurl)
end

#stream(name, url) ⇒ String

Sets the currently online stream to the specified name and Twitch URL.

Parameters:

  • name (String)

    The name of the stream to display.

  • url (String)

    The url of the current Twitch stream.

Returns:

  • (String)

    The stream name that is being displayed now.



60
61
62
63
64
# File 'lib/onyxcord/core/bot/presence.rb', line 60

def stream(name, url)
  gateway_check
  update_status(@status, name, url)
  name
end

#update_status(status, activity, url, since = 0, afk = false, activity_type = 0) ⇒ Object

Updates presence status.

Parameters:

  • status (String)

    The status the bot should show up as. Can be online, dnd, idle, or invisible

  • activity (String, nil)

    The name of the activity to be played/watched/listened to/stream name on the stream.

  • url (String, nil)

    The Twitch URL to display as a stream. nil for no stream.

  • since (Integer) (defaults to: 0)

    When this status was set.

  • afk (true, false) (defaults to: false)

    Whether the bot is AFK.

  • activity_type (Integer) (defaults to: 0)

    The type of activity status to display. Can be 0 (Playing), 1 (Streaming), 2 (Listening), 3 (Watching), or 5 (Competing).

See Also:

  • Gateway#send_status_update


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/onyxcord/core/bot/presence.rb', line 15

def update_status(status, activity, url, since = 0, afk = false, activity_type = 0)
  gateway_check

  @activity = activity
  @status = status
  @streamurl = url
  type = url ? 1 : activity_type

  activity_obj = activity || url ? { 'name' => activity, 'url' => url, 'type' => type } : nil
  @gateway.send_status_update(status, since, activity_obj, afk)

  # Update the status in the cache
  profile.update_presence('status' => status.to_s, 'activities' => [activity_obj].compact)
end

#watching=(name) ⇒ String

Sets the current watching status to the specified name.

Parameters:

  • name (String)

    The thing to be watched.

Returns:

  • (String)

    The thing that is now being watched.



51
52
53
54
# File 'lib/onyxcord/core/bot/presence.rb', line 51

def watching=(name)
  gateway_check
  update_status(@status, name, nil, nil, nil, 3)
end