-
Notifications
You must be signed in to change notification settings - Fork 4
Relationships
This module (and its corresponding manager) helps you access the relationships your players have made on Discord, allowing you to:
- Access a user's relationships.
- Filter those relationships based on a given criteria.
- Build a user's friend list.
Discord.Status
Enum for the different user statuses.
0: OFFLINE
1: ONLINE
2: IDLE
3: DO_NOT_DISTURB
Discord.RelationshipType
Enum for the different types of relationships.
0: NONE
1: FRIEND
2: BLOCKED
3: PENDING_INCOMING
4: PENDING_OUTGOING
5: IMPLICIT
Discord.Presence
Extends Resource
.
Contains information about a user's presence.
status: Discord.Status
The user's current online status.
Default: Discord.Status.OFFLINE
activity: Discord.Activity
The user's current activity.
Default: new Discord.Activity
(Will appear as [empty]
in the editor due to current limitations.)
Discord.Relationship
Extends Resource
.
Contains information about a relationship with a user.
type: Discord.RelationshipType
What kind of relationship it is.
Default: Discord.RelationshipType.NONE
user: Discord.User
The user the relationship is for.
Default: new Discord.User
(Will appear as [empty]
in the editor due to current limitations.)
presence: Discord.Presence
The user's current presence.
Default: new Discord.Presence
(Will appear as [empty]
in the editor due to current limitations.)
Discord.RelationshipManager
Extends Object
.
Contains methods and events related to relationships.
filter(filter_target: Object, filter_method: String)
Sets the filter for any future relationship commands. Filter should return a boolean. Because signals cannot return a value, this method does not have a corresponding signal callback.
Should only be called after the refresh
signal is released.
Note that because of caching the filter cannot be set multiple times as far as I know, so you will want to set this to the broadest filter you are going to do then do any other filtering yourself.
-
filter_target: Object
- The filter target.filter_method: String
- The filter method's name.filter(relationship: Discord.Relationship) -> bool
var discord: Discord.Core
var relationships: Discord.RelationshipManager
func _ready() -> void:
# ...
yield(relationships, "refresh") # Wait for refresh
relationships.filter(self, "_filter")
func _filter(relationship: Discord.Relationship) -> bool:
return relationship.type == Discord.RelationshipType.FRIEND # Only return `true` if they are a friend.
get(user_id: int, [callback_target: Object, callback_method: String]) -> void
Get the relationship between the current user and a given user by id.
Has a corresponding signal get_callback
that can be used instead of the optional target & method args.
Should only be called after the refresh
signal is released.
-
user_id: int
- The ID of the user to fetch.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.get_callback(result: Discord.Result, relationship: Discord.Relationship)
var discord: Discord.Core
var relationships: Discord.RelationshipManager
func _ready() -> void:
# ...
yield(relationships, "refresh")
relationships.get(
425340416531890178,
self, "_get_callback"
)
func _get_callback(result: int, relationship: Discord.Relationship) -> void:
print(
"Your relationship with @",
relationship.user.username, "#", relationship.user.discriminator,
"is currently of type ", relationship.type, "."
)
get_at(index: int, [callback_target: Object, callback_method: String]) -> void
Get the relationship at a given index when iterating over a list of relationships.
Has a corresponding signal get_at_callback
that can be used instead of the optional target & method args.
Requires a filter to be set.
-
index: int
- The index in the list of relationships.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.get_at_callback(result: Discord.Result, relationship: Discord.Relationship)
var discord: Discord.Core
var relationships: Discord.RelationshipManager
func _ready() -> void:
# ...
yield(relationships, "refresh")
relationships.filter(self, "_filter")
relationships.get_at(0, self, "_get_at_callback")
func _filter(relationship: Discord.Relationship) -> bool:
return true
func _get_at_callback(result: int, relationship: Discord.Relationship) -> void:
print(
"Your relationship at index 0 is currently with @",
relationship.user.username, "#", relationship.user.discriminator,
"is currently of type ", relationship.type, "."
)
count([callback_target: Object, callback_method: String]) -> void
Get the number of relationships that match your filter.
Has a corresponding signal count_callback
that can be used instead of the optional target & method args.
Requires a filter to be set.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.count_callback(result: Discord.Result, count: int)
var discord: Discord.Core
var relationships: Discord.RelationshipManager
func _ready() -> void:
# ...
yield(relationships, "refresh")
relationships.filter(self, "_filter")
relationships.count()
var ret: Array = yield(relationships, "count_callback")
var result: int = ret[0]
var count: int = ret[1]
if result != Discord.Result.OK:
print("Failed to get relationships count: ", result)
return
for i in range(count):
relationships.get_at(i, self, "_get_at_callback")
func _filter(relationship: Discord.Relationship) -> bool:
return true
func _get_at_callback(result: int, relationship: Discord.Relationship) -> void:
print(
"@", relationship.user.username, "#", relationship.user.discriminator,
" - ", relationship.type
)
refresh()
Fires at initialization when Discord has cached a snapshot of the current status of all your relationships. Wait for this to fire before calling filter
within its callback.
var discord: Discord.Core
var relationships: Discord.RelationshipManager
func _ready() -> void:
# ...
yield(relationships, "refresh")
print("Relationships list cached!")
relationship_update(relationship: Discord.Relationship)
Fires when a relationship in the filtered list changes, like an updated presence or user attribute.
-
relationship: Discord.Relationship
- The relationship that changed.
var discord: Discord.Core
var relationships: Discord.RelationshipManager
func _ready() -> void:
# ...
relationships.connect(
"relationship_update",
self, "_on_relationship_update"
)
func _on_relationship_update(relationship: Discord.Relationship) -> void:
print(
"Relationship with @",
relationship.username, "#", relationship.discriminator,
" updated to type ", relationship.type, "."
)
get_callback(result: Discord.Result, relationship: Discord.Relationship)
Alternative to the object & method args of get
.
-
result: Discord.Result
- The result of the command. -
relationship: Discord.Relationship
- The relationship between you and the user.
get_at_callback(result: Discord.Result, relationship: Discord.Relationship)
Alternative to the object & method args of get_at
.
-
result: Discord.Result
- The result of the command. -
relationship: Discord.Relationship
- The relationship between you and the user.
count_callback(result: Discord.Result, count: int)
Alternative to the object & method args of count
.
-
result: Discord.Result
- The result of the command. -
count: int
- The number of relationships that match your filter.