-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathosu.js
78 lines (70 loc) · 2.8 KB
/
osu.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
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
async function fetchData(type) {
try {
const url = "http://127.0.0.1:24050/json/v2"
const response = await fetch(url)
if (!response.ok) {
throw new Error('tosu not found, ', response.status);
}
const data = await response.json();
const beatmap = await data.beatmap;
const play = await data.play;
const state = await data.state;
const profile = await data.profile;
switch (type) {
case ("mode"):
return beatmap.mode.number ? profile.mode.number : beatmap.mode.number;
break;
case ("map"):
let modeName;
const modsName = play.mods.name ? ` +${play.mods.name}` : "";
const id = beatmap.id ? `osu.ppy.sh/b/${beatmap.id}` : "(private map)";
const modeNumber = beatmap.mode.number ? beatmap.mode.number : profile.mode.number;
switch (modeNumber) {
case 0:
modeName = "";
break;
case 1:
modeName = " <osu!taiko>";
break;
case 2:
modeName = " <osu!catch>";
break;
case 3:
modeName = " <osu!mania>";
break;
};
const mapFormatted = `${beatmap.artist} - ${beatmap.title} [${beatmap.version}] (${beatmap.mapper})${modeName}${modsName} | ${id}`;
return mapFormatted;
case ("mods"):
return play.mods.number;
break;
case ("pp"):
if (document.getElementById("btmc").checked) {
return (state.number == 2 || state.number == 7) ? ` ${play.pp.current.toFixed(0)}pp /` : "";
} else {
return (state.number == 2 || state.number == 7) ? ` ${play.pp.current.toFixed(2)}pp /` : "";
}
};
} catch (error) {
console.error('it brokey but differently: ', error);
disconnectBot();
};
};
async function calculatePp(acc) {
try {
const response = await fetch(`http://127.0.0.1:24050/api/calculate/pp?mode=${await fetchData("mode")}&acc=${acc}&mods=${await fetchData("mods")}`)
if (!response.ok) {
throw new Error('tosu not found, ', response.status);
}
const data = await response.json();
if (document.getElementById("btmc").checked) {
ppAmount = await data.pp.toFixed(0);
} else {
ppAmount = await data.pp.toFixed(2);
}
return ppAmount;
} catch (error) {
console.error('it brokey but differently: ', error);
disconnectBot();
};
};