Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 9a2b995

Browse files
authored
Create Misc.js
1 parent f8b329e commit 9a2b995

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

src/classes/Misc.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
let headers = require('../utils/headers.js');
2+
let variables = require('../utils/variables.js');
3+
4+
class Misc {
5+
async userSearch(query, limit) {
6+
if (!global.cookies) {
7+
throw new Error('Not logged in.');
8+
} else {
9+
if (!query)
10+
throw new Error(
11+
'User Search needs a query to search. Please supply a query.'
12+
);
13+
if (!limit) limit = 10;
14+
15+
headers.Cookie = global.cookies;
16+
let info = await variables
17+
.fetch('https://repl.it/graphql', {
18+
method: 'POST',
19+
headers,
20+
body: JSON.stringify({
21+
query: `
22+
query UserSearch($query: String!, $limit: Int!) {
23+
usernameSearch(query: $query, limit: $limit) {
24+
${variables.userAttributes}
25+
}
26+
}`,
27+
variables: {
28+
query,
29+
limit
30+
}
31+
})
32+
})
33+
.then(res => res.json());
34+
35+
if (!info.data.usernameSearch) {
36+
throw new Error(`Cannot fetch users.`);
37+
} else {
38+
return info.data.usernameSearch;
39+
}
40+
}
41+
}
42+
}
43+
44+
module.exports = {
45+
Misc: Misc
46+
};

0 commit comments

Comments
 (0)