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 class UserStore extends Map<string, User> {
2424 for ( const [ k , v ] of entries ) this . set ( k , v )
2525 }
2626
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+
2747 /**
2848 * Fetch a user by their username, and store them in the cache.
2949 * @param username The user's username
@@ -57,8 +77,7 @@ export default class UserStore extends Map<string, User> {
5777 UserConstructor = ClientUser
5878 }
5979
60- const user = new UserConstructor ( this . client , data )
61- this . set ( username , user )
80+ const user = this . store ( data , data . username , UserConstructor )
6281 return user
6382 }
6483}
You can’t perform that action at this time.
0 commit comments