This repository was archived by the owner on Jul 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,26 @@ export default clas
8000
s UserStore extends Map<string, User> {
24
24
for ( const [ k , v ] of entries ) this . set ( k , v )
25
25
}
26
26
27
+ /**
28
+ * Store and get a user by their username.
29
+ * @param data The data obtained from the API
30
+ * @param username The user's username.
31
+ */
32
+ store (
33
+ data : any ,
34
+ username : string = data . username ,
35
+ Type : typeof User | typeof ClientUser = User
36
+ ) : User {
37
+ let existing = this . get ( username )
38
+ if ( existing ) {
39
+ existing . _apply ( data )
40
+ } else {
41
+ existing = new Type ( this . client , data )
42
+ this . set ( username , existing )
43
+ }
44
+ return existing
45
+ }
46
+
27
47
/**
28
48
* Fetch a user by their username, and store them in the cache.
29
49
* @param username The user's username
@@ -57,8 +77,7 @@ export default class UserStore extends Map<string, User> {
57
77
UserConstructor = ClientUser
58
78
}
59
79
60
- const user = new UserConstructor ( this . client , data )
61
- this . set ( username , user )
80
+ const user = this . store ( data , data . username , UserConstructor )
62
81
return user
63
82
}
64
83
}
You can’t perform that action at this time.
0 commit comments