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

chore: V4.0 fully remove user account methods #286

Open
wants to merge 2 commits into
base: 4.0-staging
Choose a base branch
from
Open
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
53 changes: 1 addition & 52 deletions lib/discordrb/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# List of methods representing endpoints in Discord's API
module Discordrb::API
# The base URL of the Discord REST API.
APIBASE = 'https://discord.com/api/v8'
APIBASE = 'https://discord.com/api/v9'

# The URL of Discord's CDN
CDN_URL = 'https://cdn.discordapp.com'
Expand Down Expand Up @@ -222,30 +222,6 @@ def achievement_icon_url(application_id, achievement_id, icon_hash, format = 'we
"#{cdn_url}/app-assets/#{application_id}/achievements/#{achievement_id}/icons/#{icon_hash}.#{format}"
end

# Login to the server
def login(email, password)
request(
:auth_login,
nil,
:post,
"#{api_base}/auth/login",
email: email,
password: password
)
end

# Logout from the server
def logout(token)
request(
:auth_logout,
nil,
:post,
"#{api_base}/auth/logout",
nil,
Authorization: token
)
end

# Create an OAuth application
def create_oauth_application(token, name, redirect_uris)
request(
Expand Down Expand Up @@ -283,20 +259,6 @@ def oauth_application(token)
)
end

# Acknowledge that a message has been received
# The last acknowledged message will be sent in the ready packet,
# so this is an easy way to catch up on messages
def acknowledge_message(token, channel_id, message_id)
request(
:channels_cid_messages_mid_ack,
nil, # This endpoint is unavailable for bot accounts and thus isn't subject to its rate limit requirements.
:post,
"#{api_base}/channels/#{channel_id}/messages/#{message_id}/ack",
nil,
Authorization: token
)
end

# Get the gateway to be used
def gateway(token)
request(
Expand All @@ -320,19 +282,6 @@ def gateway_bot(token)
)
end

# Validate a token (this request will fail if the token is invalid)
def validate_token(token)
request(
:auth_login,
nil,
:post,
"#{api_base}/auth/login",
{}.to_json,
Authorization: token,
content_type: :json
)
end

# Get a list of available voice regions
def voice_regions(token)
request(
Expand Down
15 changes: 2 additions & 13 deletions lib/discordrb/bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ class Bot
# you're trying to log in as a bot.
# @param client_id [Integer] If you're logging in as a bot, the bot's client ID. This is optional, and may be fetched
# from the API by calling {Bot#bot_application} (see {Application}).
# @param type [Symbol] This parameter lets you manually overwrite the account type. This needs to be set when
# logging in as a user, otherwise discordrb will treat you as a bot account. Valid values are `:user` and `:bot`.
# @param name [String] Your bot's name. This will be sent to Discord with any API requests, who will use this to
# trace the source of excessive API requests; it's recommended to set this to something if you make bots that many
# people will host on their servers separately.
Expand All @@ -110,7 +108,7 @@ class Bot
def initialize(
log_mode: :normal,
token: nil, client_id: nil,
type: nil, name: '', fancy_log: false, suppress_ready: false, parse_self: false,
name: '', fancy_log: false, suppress_ready: false, parse_self: false,
shard_id: nil, num_shards: nil, redact_token: true, ignore_bots: false,
compress_mode: :large, intents: :all
)
Expand All @@ -121,7 +119,6 @@ def initialize(

@client_id = client_id

@type = type || :bot
@name = name

@shard_key = num_shards ? [shard_id, num_shards] : nil
Expand All @@ -144,7 +141,7 @@ def initialize(
calculate_intents(intents)
end

@token = process_token(@type, token)
@token = "Bot #{token.delete_prefix('Bot ')}"
@gateway = Gateway.new(self, @token, @shard_key, @compress_mode, @intents)

init_cache
Expand Down Expand Up @@ -1106,14 +1103,6 @@ def remove_user_ban(data); end
## ## ## ## ## ## ## ###
######## ####### ###### #### ## ##

def process_token(type, token)
# Remove the "Bot " prefix if it exists
token = token[4..] if token.start_with? 'Bot '

token = "Bot #{token}" unless type == :user
token
end

def handle_dispatch(type, data)
# Check whether there are still unavailable servers and there have been more than 10 seconds since READY
if @unavailable_servers&.positive? && (Time.now - @unavailable_timeout_time) > 10 && !((@intents || 0) & INTENTS[:servers]).zero?
Expand Down
1 change: 0 additions & 1 deletion lib/discordrb/commands/command_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def initialize(**attributes)
log_mode: attributes[:log_mode],
token: attributes[:token],
client_id: attributes[:client_id],
type: attributes[:type],
name: attributes[:name],
fancy_log: attributes[:fancy_log],
suppress_ready: attributes[:suppress_ready],
Expand Down
26 changes: 0 additions & 26 deletions lib/discordrb/data/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,6 @@ def update_data(new_data)
@avatar_id = new_data[:avatar_id] || @avatar_id
end

# Sets the user status setting to Online.
# @note Only usable on User accounts.
def online
update_profile_status_setting('online')
end

# Sets the user status setting to Idle.
# @note Only usable on User accounts.
def idle
update_profile_status_setting('idle')
end

# Sets the user status setting to Do Not Disturb.
# @note Only usable on User accounts.
def dnd
update_profile_status_setting('dnd')
end

alias_method(:busy, :dnd)

# Sets the user status setting to Invisible.
# @note Only usable on User accounts.
def invisible
update_profile_status_setting('invisible')
end

# The inspect method is overwritten to give more useful output
def inspect
"<Profile user=#{super}>"
Expand Down
2 changes: 1 addition & 1 deletion lib/discordrb/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Errors
class InvalidAuthenticationError < RuntimeError
# Default message for this exception
def message
'User login failed due to an invalid email or password!'
'Authentication failed due to an invalid token!'
end
end

Expand Down
4 changes: 0 additions & 4 deletions lib/discordrb/gateway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ module Opcodes
# to behave correctly)
VOICE_STATE = 4

# **Sent**: This opcode is used to ping a voice server, whatever that means. The functionality of this opcode isn't
# known well but non-user clients should never send it.
VOICE_PING = 5

# **Sent**: This is the other of two possible ways to initiate a gateway session (other than {IDENTIFY}). Rather
# than starting an entirely new session, it resumes an existing session by replaying all events from a given
# sequence number. It should be used to recover from a connection error or anything like that when the session is
Expand Down