Skip to content

Commit

Permalink
Add Competing to activity types (#21)
Browse files Browse the repository at this point in the history
Add Competing to activity types
  • Loading branch information
kaine119 committed Jan 16, 2021
1 parent fa27676 commit d572a3e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/discordrb/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,8 @@ def parse_mention(mention, server = nil)
# @param url [String, nil] The Twitch URL to display as a stream. nil for no stream.
# @param since [Integer] When this status was set.
# @param afk [true, false] Whether the bot is AFK.
# @param activity_type [Integer] The type of activity status to display. Can be 0 (Playing), 1 (Streaming), 2 (Listening), 3 (Watching)
# @param activity_type [Integer] The type of activity status to display.
# Can be 0 (Playing), 1 (Streaming), 2 (Listening), 3 (Watching), or 5 (Competing).
# @see Gateway#send_status_update
def update_status(status, activity, url, since = 0, afk = false, activity_type = 0)
gateway_check
Expand Down Expand Up @@ -558,6 +559,14 @@ def stream(name, url)
name
end

# Sets the currently competing status to the specified name.
# @param name [String] The name of the game to be competing in.
# @return [String] The game that is being competed in now.
def competing=(name)
gateway_check
update_status(@status, name, nil, nil, nil, 5)
end

# Sets status to online.
def online
gateway_check
Expand Down
9 changes: 8 additions & 1 deletion lib/discordrb/data/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Activity
# @return [String] the activity's name
attr_reader :name

# @return [Integer, nil] activity type. Can be {GAME}, {STREAMING}, {LISTENING}, {CUSTOM}
# @return [Integer, nil] activity type. Can be {GAME}, {STREAMING}, {LISTENING}, {CUSTOM}, or {COMPETING}
attr_reader :type

# @return [String, nil] stream URL, when the activity type is {STREAMING}
Expand Down Expand Up @@ -67,6 +67,8 @@ class Activity
WATCHING = 3
# Type indicating the activity is a custom status
CUSTOM = 4
# Type indicating the activity is for a competitive game
COMPETING = 5

# @!visibility private
def initialize(data, bot)
Expand Down Expand Up @@ -260,5 +262,10 @@ def watching
def custom_status
@activities.select { |act| act.type == Activity::CUSTOM }
end

# @return [Array<Activity>] all activities of type {Activity::COMPETING}
def competing
@activities.select { |act| act.type == Activity::COMPETING }
end
end
end

0 comments on commit d572a3e

Please sign in to comment.