This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_export.js
49 lines (45 loc) · 1.74 KB
/
user_export.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
48
49
const fs = require('fs');
const Teemo = require('teemojs');
const teemo = new Teemo(`${fs.readFileSync(`${process.env.HOME}/.corki/riot_key`)}`.trim());
const lolAcctsToGet = [];
fs.readdirSync(`${process.env.HOME}/.corki/users`).forEach(discUid => {
let json;
try {
json = fs.readFileSync(`${process.env.HOME}/.corki/users/${discUid}/lol.json`).toString();
} catch(e) {
console.error('no lol.json for user id ' + discUid );
return;
}
let o;
try {
o = JSON.parse(json);
} catch (e) {
console.error('invalid json for user id ' + discUid + ': "' + json + '"');
process.exit(1);
}
o.accounts.forEach(a => { a.discordUserId = discUid; });
lolAcctsToGet.push(...o.accounts);
});
const regions = ['BR1','EUN1','EUW1','JP1','KR','LA1','LA2','OC1','PH2','RU','SG2','TH2','TR1','TW2','VN2'];
console.log('fetching data for %d lol accounts', lolAcctsToGet.length,'...');
Promise.all(lolAcctsToGet.map(async a => {
const r = await teemo.get(a.server, 'summoner.getByPUUID', a.puuid);
const rn = await teemo.get(a.server, 'summoner.getBySummonerName', r.name);
if (rn.puuid === r.puuid)
return [a.discordUserId, a.server, r.name];
console.log('region change');
// They changed regions
for (const s of regions) {
if (s == a.server)
continue;
const rn = await teemo.get(s, 'summoner.getBySummonerName', r.name);
if (rn.puuid === r.puuid)
return [a.discordUserId, s, r.name];
}
console.log("couldn't find account:", a);
return null; // account must be deleted or sth...
})).then(l => {
l = l.filter(Boolean);
console.log(l);
fs.writeFileSync('lol_accounts_list.json', JSON.stringify(l));
});