@@ -6,7 +6,35 @@ class User {
66 this . username = username ;
77 }
88
9- async profileData ( ) {
9+ async userGraphQLDataAbridged ( ) {
10+ let user = this . username ;
11+ let info = await constants
12+ . fetch ( constants . graphql , {
13+ method : 'POST' ,
14+ headers,
15+ body : JSON . stringify ( {
16+ query : `
17+ query User($user: String!) {
18+ userByUsername(username: $user) {
19+ ${ constants . userAttributes }
20+ }
21+ }` ,
22+ variables : JSON . stringify ( {
23+ user : user
24+ } )
25+ } )
26+ } ) . then ( res => res . json ( ) ) ;
27+
28+ if ( info . errors ) throw new Error ( `Replit GraphQL Error(s): ${ JSON . stringify ( info . errors ) } ` )
29+
30+ if ( ! info . data . userByUsername ) {
31+ throw new Error ( `${ user } is not a user. Please query users on Replit.` ) ;
32+ } else {
33+ return info . data . userByUsername ;
34+ }
35+ }
36+
37+ async userGraphQLDataFull ( ) {
1038 let user = this . username ;
1139 let info = await constants
1240 . fetch ( constants . graphql , {
@@ -38,7 +66,23 @@ class User {
3866 }
3967 }
4068
41- async postDataAbridged ( after , count , order ) {
69+ async userRestfulData ( ) {
70+ let username = this . username ;
71+
72+ let info = await constants
73+ . fetch ( `${ constants . restful } /data/profiles/${ username } ` , {
74+ method : 'GET' ,
75+ headers
76+ } ) . then ( res => res . json ( ) ) ;
77+
78+ if ( ! info ) {
79+ throw new Error ( `${ username } is not a user. Please query users on Replit.` ) ;
80+ } else {
81+ return info ;
82+ }
83+ }
84+
85+ async postsDataAbridged ( after , count , order ) {
4286 if ( ! after ) after = '' ;
4387 if ( ! count ) count = 50 ;
4488 if ( ! order ) order = '' ;
@@ -98,7 +142,7 @@ class User {
98142 return output ;
99143 }
100144
101- async postDataFull ( after , count , order ) {
145+ async postsDataFull ( after , count , order ) {
102146 if ( ! after ) after = '' ;
103147 if ( ! count ) count = 50 ;
104148 if ( ! order ) order = '' ;
@@ -163,7 +207,7 @@ class User {
163207 return output ;
164208 }
165209
166- async commentDataAbridged ( after , count , order ) {
210+ async commentsDataAbridged ( after , count , order ) {
167211 if ( ! after ) after = '' ;
168212 if ( ! count ) count = 50 ;
169213 if ( ! order ) order = '' ;
@@ -222,7 +266,7 @@ class User {
222266 return output ;
223267 }
224268
225- async commentDataFull ( after , count , order ) {
269+ async commentsDataFull ( after , count , order ) {
226270 if ( ! after ) after = '' ;
227271 if ( ! count ) count = 50 ;
228272 if ( ! order ) order = '' ;
@@ -292,6 +336,47 @@ class User {
292336 await recurse ( after ) ;
293337 return output ;
294338 }
339+
340+ async userSearch ( query , limit ) {
341+ if ( ! global . cookies ) {
342+ throw new Error ( 'ReplAPI.it: Not logged in.' ) ;
343+ } else {
344+ if ( [ 'RayhanADev' ] . contains ( global . initVariables . username ) ) {
345+ if ( ! query )
346+ throw new Error (
347+ 'User Search needs a query to search. Please supply a query.'
348+ ) ;
349+ if ( ! limit ) limit = 10 ;
350+
351+ headers [ 'Set-Cookie' ] = global . cookies ;
352+ let info = await constants
353+ . fetch ( constants . graphql , {
354+ method : 'POST' ,
355+ headers,
356+ body : JSON . stringify ( {
357+ query : `
358+ query UserSearch($query: String!, $limit: Int!) {
359+ usernameSearch(query: $query, limit: $limit) {
360+ id,
361+ username
362+ }
363+ }` ,
364+ variables : JSON . stringify ( {
365+ query : query ,
366+ limit : limit
367+ } )
368+ } )
369+ } ) . then ( res => res . json ( ) ) ;
370+
371+ if ( info . errors ) throw new Error ( `Replit GraphQL Error(s): ${ JSON . stringify ( info . errors ) } ` ) ;
372+ else return info . data . usernameSearch ;
373+ } else {
374+ throw new Error (
375+ `${ global . initVariables . username } is not whitelisted. Please contact @RayhanADev in ReplTalk to talk about getting added to the whitelist.`
376+ ) ;
377+ }
378+ }
379+ }
295380}
296381
297382module . exports = {
0 commit comments