@@ -168,6 +168,10 @@ class LocalUser {
168
168
document . getElementById ( "loading" ) . classList . remove ( "doneloading" )
169
169
document . getElementById ( "loading" ) . classList . add ( "loading" )
170
170
171
+ this . fetchingmembers = new Map ( )
172
+ this . noncemap = new Map ( )
173
+ this . noncebuild = new Map ( )
174
+
171
175
if ( ( ( event . code > 1000 && event . code < 1016 ) || wsCodesRetry . has ( event . code ) ) ) {
172
176
if ( connectionSucceed != 0 && Date . now ( ) > connectionSucceed + 20000 ) errorBackoff = 0
173
177
else errorBackoff = Math . min ( errorBackoff + 1 , 40 )
@@ -261,6 +265,9 @@ class LocalUser {
261
265
document . getElementById ( "servers" ) . insertBefore ( guildy . generateGuildIcon ( ) , document . getElementById ( "bottomseparator" ) )
262
266
break
263
267
}
268
+ case "GUILD_MEMBERS_CHUNK" :
269
+ this . gotChunk ( json . d )
270
+ break
264
271
}
265
272
} else if ( json . op == 1 ) this . ws . send ( JSON . stringify ( { op : 1 , d : this . lastSequence } ) )
266
273
else if ( json . op == 10 ) {
@@ -983,7 +990,7 @@ class LocalUser {
983
990
"" ,
984
991
"Reset token" ,
985
992
async ( ) => {
986
- if ( ! confirm ( "Are you sure you want to reset the bot token? Your bot will stop working until you update it." ) ) return
993
+ if ( ! confirm ( "Are you sure you want to reset the token? Your bot will stop working until you update it." ) ) return
987
994
988
995
const updateRes = await fetch ( instance . api + "/applications/" + appId + "/bot/reset" , {
989
996
method : "POST" ,
@@ -1013,10 +1020,8 @@ class LocalUser {
1013
1020
1014
1021
waitingmembers = new Map ( )
1015
1022
async resolvemember ( id , guildid ) {
1016
- console . warn ( "this function is currently non-functional, either due to a bug in the client or the server, it's currently unclear, use at your own risk" )
1017
- if ( ! this . waitingmembers . has ( guildid ) ) {
1018
- this . waitingmembers . set ( guildid , new Map ( ) )
1019
- }
1023
+ if ( ! this . waitingmembers . has ( guildid ) ) this . waitingmembers . set ( guildid , new Map ( ) )
1024
+
1020
1025
let res
1021
1026
const promise = new Promise ( r => {
1022
1027
res = r
@@ -1026,7 +1031,31 @@ class LocalUser {
1026
1031
return await promise
1027
1032
}
1028
1033
fetchingmembers = new Map ( )
1034
+ noncemap = new Map ( )
1035
+ noncebuild = new Map ( )
1036
+ async gotChunk ( chunk ) {
1037
+ chunk . members ??= [ ]
1038
+ const arr = this . noncebuild . get ( chunk . nonce )
1039
+ arr [ 0 ] = arr [ 0 ] . concat ( chunk . members )
1040
+ if ( chunk . not_found ) {
1041
+ arr [ 1 ] = chunk . not_found
1042
+ }
1043
+ arr [ 2 ] . push ( chunk . chunk_index )
1044
+ if ( arr [ 2 ] . length == chunk . chunk_count ) {
1045
+ this . noncebuild . delete ( chunk . nonce )
1046
+ const func = this . noncemap . get ( chunk . nonce )
1047
+ func ( [ arr [ 0 ] , arr [ 1 ] ] )
1048
+ this . noncemap . delete ( chunk . nonce )
1049
+ }
1050
+ }
1029
1051
async getmembers ( ) {
1052
+ let res
1053
+ const promise = new Promise ( r => {
1054
+ res = r
1055
+ } )
1056
+ setTimeout ( res , 10 )
1057
+ await promise //allow for more to be sent at once
1058
+
1030
1059
if ( this . ws ) {
1031
1060
this . waitingmembers . forEach ( async ( value , guildid ) => {
1032
1061
const keys = value . keys ( )
@@ -1035,27 +1064,51 @@ class LocalUser {
1035
1064
const build = [ ]
1036
1065
for ( const key of keys ) {
1037
1066
build . push ( key )
1067
+ if ( build . length == 100 ) break
1038
1068
}
1039
1069
1040
- let res
1041
- const promise = new Promise ( r => {
1042
- res = r
1070
+ if ( ! build . length ) {
1071
+ this . waitingmembers . delete ( guildid )
1072
+ return
1073
+ }
1074
+
1075
+ let res2
1076
+ const promise2 = new Promise ( r => {
1077
+ res2 = r
1043
1078
} )
1079
+
1080
+ const nonce = "" + Math . floor ( Math . random ( ) * 100000000000 )
1081
+ this . noncemap . set ( nonce , res2 )
1082
+ this . noncebuild . set ( nonce , [ [ ] , [ ] , [ ] ] )
1044
1083
this . ws . send ( JSON . stringify ( {
1045
1084
op : 8 ,
1046
1085
d : {
1047
1086
user_ids : build ,
1048
1087
guild_id : guildid ,
1049
1088
limit : 100 ,
1050
- nonce : "" + Math . floor ( Math . random ( ) * 100000000 )
1089
+ //presences: true,
1090
+ nonce
1051
1091
}
1052
1092
} ) )
1053
- this . fetchingmembers . set ( guildid , res )
1054
- const data = await promise
1093
+ this . fetchingmembers . set ( guildid , true )
1094
+ const prom = await promise2
1095
+
1096
+ const data = prom [ 0 ]
1055
1097
for ( const thing of data ) {
1056
1098
value . get ( thing . id ) ( thing )
1057
1099
value . delete ( thing . id )
1100
+ if ( value . has ( thing . id ) ) {
1101
+ value . get ( thing . id ) ( thing )
1102
+ value . delete ( thing . id )
1103
+ }
1104
+ }
1105
+ for ( const thing of prom [ 1 ] ) {
1106
+ if ( value . has ( thing ) ) {
1107
+ value . get ( thing ) ( )
1108
+ value . delete ( thing )
1109
+ }
1058
1110
}
1111
+ this . fetchingmembers . delete ( guildid )
1059
1112
this . getmembers ( )
1060
1113
} )
1061
1114
}
0 commit comments