-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
57 lines (47 loc) · 1.59 KB
/
index.ts
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
50
51
52
53
54
55
56
57
import {getPlayers, getRole, getRoles, type GroupUser, type PlayerInfo, type Role} from "noblox.js";
import * as fs from "fs";
import * as repl from "repl";
const argv: Cli = require('yargs-parser')(process.argv.slice(2))
if (argv.minRole == undefined || argv.group == undefined || argv.timeout == undefined) {
throw Error("You must have all args min role, group, and timeout")
}
const groupId = argv.group
// @ts-ignore
function replacer(key, value) {
if(value instanceof Map) {
return {
dataType: 'Map',
value: Array.from(value.entries()),
};
} else {
return value;
}
}
async function main() {
let roles: Role[] = (await getRoles(groupId))
//Cut out the guest and auto added role
roles = roles.slice(1, roles.length - 1)
//Map of data points
let data: Map<number, GroupRole[]> = new Map();
async function getData() {
let groupRoles: GroupRole[] = []
for (let i = roles.length - argv.minRole; i >= 0; i--) {
let role = roles[i]
let players = await getPlayers(groupId, role.id)
groupRoles.push(new GroupRole(role.name, players, role.id))
}
data.set(Date.now(), groupRoles)
fs.writeFile("./data.json", JSON.stringify(data, replacer), {}, () => {})
}
await getData()
setTimeout(async () => await getData(), argv.timeout * 1000)
}
class GroupRole {
constructor(private name: string, private members: GroupUser[], private id: number) {}
}
interface Cli {
group: number,
timeout: number,
minRole: number
}
main().then(() => {})