Module: Vox::HTTP::Routes::User

Defined in:
lib/vox/http/routes/user.rb

Overview

Mixin for user routes.

Instance Method Summary collapse

Instance Method Details

#create_dm(recipient_id) ⇒ Hash<Symbol, Object>

Create a new DM channel with a user.

Parameters:

  • recipient_id (String, Integer)

    The ID of the recipient to open a DM with.

Returns:

View On Discord's Docs:



83
84
85
# File 'lib/vox/http/routes/user.rb', line 83

def create_dm(recipient_id)
  request(Route.new(:POST, '/users/@me/channels'), json: { recipient_id: recipient_id })
end

#create_group_dm(access_tokens, nicks: :undef) ⇒ Object

Note:

This endpoint was intended for a now deprecated SDK. DMs created with this endpoint are not visible in the Discord client.

Note:

This endpoint is limited to 10 active group DMs.

Create a new DM with multiple users.

Parameters:

  • access_tokens (Array<String, Integer>)

    Access tokens of users that have granted your app the ‘gdm.join` scope.

  • nicks (Hash<(String, Integer), String>) (defaults to: :undef)

    A hash mapping user IDs to their nicknames.

View On Discord's Docs:

Required OAuth2 Scope:

  • gdm.join



96
97
98
99
# File 'lib/vox/http/routes/user.rb', line 96

def create_group_dm(access_tokens, nicks: :undef)
  json = filter_undef({ access_tokens: access_tokens, nicks: nicks })
  request(Route.new(:POST, '/users/@me/channels'), json: json)
end

#get_current_userHash<Symbol, Object>

Get information about the current user.

Returns:

View On Discord's Docs:

Required OAuth2 Scope:

  • identify



20
21
22
# File 'lib/vox/http/routes/user.rb', line 20

def get_current_user
  request(Route.new(:GET, '/users/@me'))
end

#get_current_user_guilds(before: :undef, after: :undef, limit: :undef) ⇒ Array<Hash<Symbol, Object>>

List the guilds that the current user is in.

Parameters:

  • before (String, Integer) (defaults to: :undef)

    Get guilds before this ID.

  • after (String, Integer) (defaults to: :undef)

    Get guilds after this ID.

  • limit (String, Integer) (defaults to: :undef)

    Maximum number of guilds to return.

Returns:

View On Discord's Docs:

Required OAuth2 Scope:

  • guilds



57
58
59
60
# File 'lib/vox/http/routes/user.rb', line 57

def get_current_user_guilds(before: :undef, after: :undef, limit: :undef)
  params = filter_undef({ before: before, after: after, limit: limit })
  request(Route.new(:GET, '/users/@me/guilds'), query: params)
end

#get_user(user_id) ⇒ Hash<Symbol, Object] The [user](https://discord.com/developers/docs/resources/user#user-object) object for the target user.

Get information about a user by ID.

Returns:

View On Discord's Docs:



28
29
30
# File 'lib/vox/http/routes/user.rb', line 28

def get_user(user_id)
  request(Route.new(:GET, '/users/%{user_id}', user_id: user_id))
end

#get_user_connectionsArray<Hash<Symbol, Object>>

Get a list of connection objects for the current user.

Returns:

View On Discord's Docs:

Required OAuth2 Scope:

  • connections



106
107
108
# File 'lib/vox/http/routes/user.rb', line 106

def get_user_connections
  request(Route.new(:GET, '/users/@me/connections'))
end

#get_user_dmsArray<Hash<Symbol, Object>>

Get a list of the current user’s DM channels.

Returns:

View On Discord's Docs:



74
75
76
# File 'lib/vox/http/routes/user.rb', line 74

def get_user_dms
  request(Route.new(:GET, '/users/@me/channels'))
end

#leave_guild(guild_id) ⇒ nil

Leave a guild.

Parameters:

  • guild_id (String, Integer)

    The ID of the guild to leave.

Returns:

  • (nil)

    Returns nil on success.

View On Discord's Docs:



66
67
68
# File 'lib/vox/http/routes/user.rb', line 66

def leave_guild(guild_id)
  request(Route.new(:DELETE, '/users/@me/guilds/%{guild_id}', guild_id: guild_id))
end

#modify_current_user(username: :undef, avatar: :undef) ⇒ Hash<Symbol, Object>

Modify the current user.

Parameters:

  • username (String) (defaults to: :undef)
  • avatar (UploadIO) (defaults to: :undef)

Returns:

View On Discord's Docs:



38
39
40
41
42
43
44
45
46
47
# File 'lib/vox/http/routes/user.rb', line 38

def modify_current_user(username: :undef, avatar: :undef)
  avatar = if avatar != :undef && !avatar.nil?
             image_data = avatar.io.read
             "data:#{avatar.content_type};base64,#{Base64.encode64(image_data)}"
           else
             :undef
           end
  json = filter_undef({ username: username, avatar: avatar })
  request(Route.new(:PATCH, '/users/@me'), json: json)
end