Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Competing to activity types #21

Merged
merged 2 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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