This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
137 lines (129 loc) · 4.61 KB
/
mod.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const systems = JSON.parse(Deno.readTextFileSync("./systems.json").replaceAll("\\u0000", ""))
const roles = JSON.parse(Deno.readTextFileSync("./roles.json").replaceAll("\\u0000", ""))
const output: {
schema: number,
systems: {
[id: string]: never
},
users: {
[id: string]: {
system: string
}
},
servers: {
[id: string]: {
role: string
}
}
} = {
"schema": 1,
"systems": {},
"users": {},
"servers": {}
}
const validIdRegex = /^[a-z]{5}$/
for (const j in systems) {
const system = systems[j]
let id = system.id;
if (!validIdRegex.test(id)) {
id = generateRandomId()
}
while (output.systems[id] != null) {
id = generateRandomId()
}
const obj = {
id,
accounts: [j],
name: system.name == "" ? null : system.name,
description: system.description == "" ? null : system.description,
tag: system.tag == "" ? null : system.tag,
avatarUrl: system.avatar_url == "" ? null : system.avatar_url,
timestamp: system.created == "" ? null : system.created,
autoType: system.auto_bool? "latch": null,
members: {},
serverProxy: system.server_proxy,
proxyTags: [],
switches: system.switches
}
for (const l in system.members) {
const member = system.members[l]
let memid = member.id
const oldid = memid
if (!validIdRegex.test(memid)) {
memid = generateRandomId()
}
//@ts-ignore aaaaaaaaaaaaaaaaaaaaaaaaaa
while (obj.members[memid] != null) {
memid = generateRandomId()
}
for (const sw of obj.switches)
for (let i = 0; i < sw.members.length; i++)
if (sw.members[i] == oldid) sw.members[i] = memid
let color = typeof member.color != "string" || member.color == "" ? null : member.color as string
let colornum: number = -1
if (color) {
if (color.startsWith("#")) {
color = color.substring(1)
}
if (color.startsWith("0x")) {
color = color.substring(2)
}
colornum = parseInt(color, 16)
if (colornum > 0xffffff) colornum = -1
}
//@ts-ignore technically doesn't exist in type
obj.members[memid] = {
id: memid,
name: typeof member.name != "string" || member.name == "" ? memid : member.name,
displayName: typeof member.dispaly_name != "string" || member.dispaly_name == "" ? null : member.displayName,
description: typeof member.description != "string" || member.description == "" ? null : member.description,
birthday: typeof member.birthday != "string" || member.birthday == "" ? null : member.birthday,
pronouns: typeof member.pronouns != "string" || member.pronouns == "" ? null : member.pronouns,
color: colornum,
avatarUrl: typeof member.avatar_url != "string" || member.avatar_url == "" ? null : member.avatar_url,
keepProxy: member.keep_proxy,
messageCount: member.message_count,
timestamp: typeof member.created != "string" || member.created == "" ? null : member.timestamp,
serverDisplayName: member.server_nick,
serverAvatarUrl: member.server_avatar,
serverProxy: member.server_proxy
}
for (const m in member.proxy_tags) {
const proxy = member.proxy_tags[m]
let prefix = false
let suffix = false
if (proxy.prefix && proxy.prefix != "") prefix = true
if (proxy.suffix && proxy.suffix != "") suffix = true
if (!prefix && !suffix) continue
obj.proxyTags.push(<never>proxy)
}
}
const newSwitches = []
for (let i = 0; i < obj.switches.length; i++) {
if (!obj.switches[i].timestamp || typeof obj.switches[i].timestamp != "string") continue
else if (!obj.switches[i] || typeof obj.switches != "object") continue
newSwitches.push(obj.switches[i])
}
obj.switches = newSwitches
console.log(obj)
output.systems[id] = <never>obj
output.users[j] = {
system: id
}
}
for (const p in roles) {
output.servers[p] = {
role: roles[p]
}
}
Deno.writeTextFileSync("./systems_output.json", JSON.stringify(output))
function generateRandomId(): string {
let out = ""
for (let i = 0; i < 5; i++) {
out += String.fromCharCode(random(0,26)+97)
}
return out
}
function random(min: number, max: number) {
return Math.random() * (max - min) + min
}