-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (34 loc) · 981 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//WARNING: MESSY CODE
var fetch = require('node-fetch');
var crypto = require('crypto-random-string');
goodNames = [];
setInterval(function() {
var str = crypto({ length: 3, characters : 'abcdefghijklmnopqrstuvwxyz1234567890_-'});
if (goodNames.includes(str)) {return;}
fetch('https://api.scratch.mit.edu/accounts/checkusername/' + str)
.then(res => res.json())
.then(json => {
if (json.msg == "valid username") {
console.log(json)
console.log(goodNames.length+1);
goodNames.push(json.username);
}
}
);
}, 0);
function randomItem(array) {
return array[Math.floor(Math.random() * array.length)];
}
function getUsername() {
return randomItem(goodNames);
}
const express = require('express');
const app = express();
app.use(express.static('public'));
app.get('/', function (req, res) {
res.sendFile('index.html');
})
app.get('/api/name', function (req, res) {
res.send(getUsername());
})
app.listen(3000);