-
Notifications
You must be signed in to change notification settings - Fork 5
/
util.ts
109 lines (98 loc) · 2.53 KB
/
util.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
import { profile } from "./models/profile";
import { Profile } from "../sdvx@asphyxia/models/profile";
export function IDToCode(id: number) {
const padded = _.padStart(id.toString(), 8);
return `${padded.slice(0, 4)}-${padded.slice(4)}`;
}
export function base64decode(s: string) {
const base64list =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
let t = "",
p = -8,
a = 0,
c: number,
d: number;
for (let i = 0; i < s.length; i++) {
if ((c = base64list.indexOf(s.charAt(i))) < 0) continue;
a = (a << 6) | (c & 63);
if ((p += 6) >= 0) {
d = (a >> p) & 255;
if (c != 64) t += String.fromCharCode(d);
a &= 63;
p -= 8;
}
}
return t;
}
export function GetVersion(info: EamuseInfo) {
return parseInt(info.module.substr(4, 2));
}
export async function IIDXidTorefid(iidxid: number) {
const profile = await DB.FindOne<profile>(null, {
collection: "profile",
iidxid: iidxid,
});
return profile.refid;
}
export function ClidToRank(clid: number) {
let style: number, rank: number;
if (clid >= 5) {
style = 1;
rank = clid - 5;
} else {
style = 0;
rank = clid;
}
return {
style: style,
rank: rank,
};
}
export function AppendSettingConverter(
sf: boolean,
cf: boolean,
df: boolean,
af: boolean,
hp: boolean,
dg: boolean,
ch: boolean,
hi: boolean
) {
const result =
Number(sf) * 1 +
Number(cf) * 2 +
Number(df) * 4 +
Number(af) * 8 +
Number(hp) * 256 +
Number(dg) * 512 +
Number(ch) * 1024 +
Number(hi) * 4196;
return result;
}
export function DateToName(now: number, score_time: number) {
const msPerMinute = 60 * 1000;
const msPerHour = msPerMinute * 60;
const msPerDay = msPerHour * 24;
const msPerMonth = msPerDay * 30;
const msPerYear = msPerDay * 365;
const elapsed = now - score_time;
if (elapsed < msPerMinute) {
return "-" + Math.round(elapsed / 1000) + "s";
} else if (elapsed < msPerHour) {
return "-" + Math.round(elapsed / msPerMinute) + "m";
} else if (elapsed < msPerDay) {
return "-" + Math.round(elapsed / msPerHour) + "h";
} else if (elapsed < msPerMonth) {
return "-" + Math.round(elapsed / msPerDay) + "d";
} else if (elapsed < msPerYear) {
return "-" + Math.round(elapsed / msPerMonth) + "mo";
} else {
return "-" + Math.round(elapsed / msPerYear) + "yr";
}
}
export async function refidToName(refid: string) {
const profile = await DB.FindOne<profile>(refid, {
collection: "profile",
});
return profile.name;
}