Skip to content

Commit

Permalink
Fixed & Added
Browse files Browse the repository at this point in the history
## Update List

- Fixed Star rating show wrong like 6.58 but is show 6.00
- Fixed Vote require show point something like 1.5 when have 3 players in lobby
- Fixed Queue message when map finish is show wrong
- Add Warning when break a rule and change to new host

## Next Update

- AFK Kick (will add be in vote cmd)
- Host Kick (mean auto kick trolling people)
  • Loading branch information
Adivise committed May 6, 2023
1 parent f7ad023 commit 733181c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 43 deletions.
47 changes: 30 additions & 17 deletions servers/AutoHost.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ let lobby;
let queue = [];
let host = 0;
let vote = [];
let warning = 0;

client.connect().then(async () => {
console.log(`[INFO] Bot is online!`);
console.log(`[INFO] Bot ${ipc.username} is online!`);
console.log(`[TIP] You can use *CRTL + C* to close the lobby!`);
console.log(`[WARN] Don't try exit with click out, the lobby will not close fully`);
console.log(`[WARN] When you do, you need to join back to the lobby and type !mp close and chat`);

const channel = await client.createLobby("Setting up lobby...");
lobby = channel.lobby;
Expand All @@ -42,7 +46,7 @@ client.connect().then(async () => {

await checkRules(beatmap);

channel.sendMessage(`*Details* | [https://osu.ppy.sh/beatmapsets/${beatmap[0].beatmapset_id}#/${beatmap[0].beatmap_id} ${beatmap[0].artist} - ${beatmap[0].title}] | AR: ${beatmap[0].diff_approach} | CS: ${beatmap[0].diff_size} | OD: ${beatmap[0].diff_overall} | HP: ${beatmap[0].diff_drain} | Star Rating: ${parseInt(beatmap[0].difficultyrating).toFixed(2)} ★ | Bpm: ${beatmap[0].bpm} | Length: ${convertSeconds(beatmap[0].total_length)}`);
channel.sendMessage(`*Details* | [https://osu.ppy.sh/beatmapsets/${beatmap[0].beatmapset_id}#/${beatmap[0].beatmap_id} ${beatmap[0].artist} - ${beatmap[0].title}] | AR: ${beatmap[0].diff_approach} | CS: ${beatmap[0].diff_size} | OD: ${beatmap[0].diff_overall} | HP: ${beatmap[0].diff_drain} | Star Rating: ${Number(beatmap[0].difficultyrating).toFixed(2)} ★ | Bpm: ${beatmap[0].bpm} | Length: ${convertSeconds(beatmap[0].total_length)}`);
channel.sendMessage(`*Mirror* | [https://beatconnect.io/b/${beatmap[0].beatmapset_id} BeatConnect] | [https://dl.sayobot.cn/beatmaps/download/novideo/${beatmap[0].beatmapset_id} Sayobot] | [https://api.chimu.moe/v1/download/${beatmap[0].beatmapset_id}?n=1 Chimu]`);

});
Expand Down Expand Up @@ -83,10 +87,10 @@ client.connect().then(async () => {
if (vote.includes(message.user.id)) return channel.sendMessage("You already voted!");
vote.push(message.user.id);

channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to skip! - (${vote.length}/${queue.length / 2})`);
channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to skip host! - (${vote.length}/${Math.ceil(queue.length / 2)})`);

if (vote.length >= queue.length / 2) {
lobby.channel.sendMessage("Skip Vote Passed!");
if (vote.length >= Math.ceil(queue.length / 2)) {
lobby.channel.sendMessage("Host are skipped!");
// remove vote
vote = [];
// host to next player
Expand Down Expand Up @@ -114,9 +118,7 @@ client.connect().then(async () => {

channel.sendMessage(`*Rules* | Star Rating: ${Rotator.min_star}* - ${Rotator.max_star}* | Length: ${convertSeconds(Rotator.min_length)} - ${convertSeconds(Rotator.max_length)} | Mode: ${mode} | Mods: ${Rotator.mods.join(", ")} | FreeMod: ${Rotator.freemod ? "Allowed" : "Not Allowed"}`);
} else if (command === "info") {
channel.sendMessage(`*Info* | Powered by [https://github.com/ThePooN/bancho.js Bancho.js] | Developer by [https://osu.ppy.sh/users/21216709 Suntury] | Source Code: [https://github.com/Adivise/SpaceHost SpaceHost]`);
} else if (command === "help") {
channel.sendMessage(`*Commands* | [https://github.com/Adivise/SpaceHost#-auto-host-mode Commands]`);
channel.sendMessage(`*Info* | Powered by [https://github.com/ThePooN/bancho.js Bancho.js] | Developer by [https://osu.ppy.sh/users/21216709 Suntury] | Source Code: [https://github.com/Adivise/SpaceHost SpaceHost] | [https://github.com/Adivise/SpaceHost#-features--commands Commands]`);
}
});

Expand Down Expand Up @@ -172,8 +174,10 @@ client.connect().then(async () => {
const strArray = [];
for (let i = 0; i < queue.length; i++) {
const user = await client.getUserById(queue[i]);
strArray.push(`${i + 1}. [https://osu.ppy.sh/users/${user.id} ${user.username}]`);
strArray.push(`[https://osu.ppy.sh/users/${user.id} ${user.username}]`);
}
const firstElement = strArray.shift(); // Remove the first element from strArray and store it
strArray.push(firstElement); // Add the first element to the end of strArray
channel.sendMessage(`Host Queue: ${strArray.join(", ")}`);

// update settings
Expand All @@ -185,15 +189,15 @@ client.connect().then(async () => {
});

lobby.on("allPlayersReady", async () => {
if (queue.length === 1) return;
if (queue.length === 1) return; // remove this if your need 1 player can start
channel.sendMessage("!mp start");
});

lobby.on("host", async (obj) => {
// event host update
if (obj === null) return;
if (queue.includes(obj.user.id)) {
console.log("Host Updated!");
console.log("[DEBUG] Host Updated!");
// set host
host = obj.user.id;
// shift host to last element
Expand All @@ -203,6 +207,7 @@ client.connect().then(async () => {
// get host to first element
queue.unshift(queue.splice(queue.indexOf(obj.user.id), 1)[0]);
}
warning = 0;
});

});
Expand Down Expand Up @@ -248,16 +253,24 @@ async function getMods() {

async function checkRules(beatmap) {
if (beatmap.length == 0) return getRules("Beatmap not found!");
if (beatmap[0].mode != Rotator.mode) return getRules("Beatmap mode is not standard!");
if (beatmap[0].difficultyrating > Rotator.max_star) return getRules("Beatmap star rating is too high!");
if (beatmap[0].difficultyrating < Rotator.min_star) return getRules("Beatmap star rating is too low!");
if (beatmap[0].total_length > Rotator.max_length) return getRules("Beatmap length is too long!");
if (beatmap[0].total_length < Rotator.min_length) return getRules("Beatmap length is too short!");
if (beatmap[0].mode != Rotator.mode) return getRules("Beatmap mode is not *Standard*");
if (beatmap[0].difficultyrating > Rotator.max_star) return getRules("Beatmap *Star Rating* is too high");
if (beatmap[0].difficultyrating < Rotator.min_star) return getRules("Beatmap *Star Rating* is too low");
if (beatmap[0].total_length > Rotator.max_length) return getRules("Beatmap *Length* is too long");
if (beatmap[0].total_length < Rotator.min_length) return getRules("Beatmap *Length* is too short");
}

async function getRules(reason) {
lobby.channel.sendMessage(`[https://osu.ppy.sh/users/${lobby.getHost().user.id} ${lobby.getHost().user.username}] | *Warning* ${reason}`);
warning++

lobby.channel.sendMessage(`[https://osu.ppy.sh/users/${lobby.getHost().user.id} ${lobby.getHost().user.username}] | *Warning* ${reason} (${warning}/3)`);
lobby.channel.sendMessage(`*Rules* | Star Rating: ${Rotator.min_star}* - ${Rotator.max_star}* | Length: ${convertSeconds(Rotator.min_length)} - ${convertSeconds(Rotator.max_length)} | Mode: Standard | Mods: ${Rotator.mods.join(", ")} | FreeMod: ${Rotator.freemod ? "Allowed" : "Not Allowed"}`);

if (warning === 3) {
// skip the host get redeacted
lobby.setHost("#" + queue[1]);
warning = 0;
}

getBeatmap();
}
27 changes: 14 additions & 13 deletions servers/AutoMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ let abort = []; // abort list
let stop = []; // stop list

client.connect().then(async () => {
console.log(`[INFO] Bot is online!`);
console.log(`[INFO] Bot ${ipc.username} is online!`);
console.log(`[TIP] You can use *CRTL + C* to close the lobby!`);
console.log(`[WARN] Don't try exit with click out, the lobby will not close fully`);
console.log(`[WARN] When you do, you need to join back to the lobby and type !mp close and chat`);

const channel = await client.createLobby("Setting up lobby...");
lobby = channel.lobby;
Expand All @@ -46,7 +49,7 @@ client.connect().then(async () => {
if (beatmap.length == 0) return await getBeatmap();
if (beatmap[0].mode != AutoMap.mode) return await getBeatmap();

channel.sendMessage(`*Details* | [https://osu.ppy.sh/beatmapsets/${beatmap[0].beatmapset_id}#/${beatmap[0].beatmap_id} ${beatmap[0].artist} - ${beatmap[0].title}] | AR: ${beatmap[0].diff_approach} | CS: ${beatmap[0].diff_size} | OD: ${beatmap[0].diff_overall} | HP: ${beatmap[0].diff_drain} | Star Rating: ${parseInt(beatmap[0].difficultyrating).toFixed(2)} ★ | Bpm: ${beatmap[0].bpm} | Length: ${convertSeconds(beatmap[0].total_length)}`);
channel.sendMessage(`*Details* | [https://osu.ppy.sh/beatmapsets/${beatmap[0].beatmapset_id}#/${beatmap[0].beatmap_id} ${beatmap[0].artist} - ${beatmap[0].title}] | AR: ${beatmap[0].diff_approach} | CS: ${beatmap[0].diff_size} | OD: ${beatmap[0].diff_overall} | HP: ${beatmap[0].diff_drain} | Star Rating: ${Number(beatmap[0].difficultyrating).toFixed(2)} ★ | Bpm: ${beatmap[0].bpm} | Length: ${convertSeconds(beatmap[0].total_length)}`);
channel.sendMessage(`*Mirror* | [https://beatconnect.io/b/${beatmap[0].beatmapset_id} BeatConnect] | [https://dl.sayobot.cn/beatmaps/download/novideo/${beatmap[0].beatmapset_id} Sayobot] | [https://api.chimu.moe/v1/download/${beatmap[0].beatmapset_id}?n=1 Chimu]`);

});
Expand All @@ -68,8 +71,8 @@ client.connect().then(async () => {
if (start.includes(message.user.id)) return channel.sendMessage("You already voted to start the game!");
start.push(message.user.id);

channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to start the game! - (${start.length}/${queue.length / 2})`);
if (start.length >= queue.length / 2) {
channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to start the game! - (${start.length}/${Math.ceil(queue.length / 2)})`);
if (start.length >= Math.ceil(queue.length / 2)) {
start = [];

channel.sendMessage("!mp start");
Expand All @@ -80,8 +83,8 @@ client.connect().then(async () => {
if (stop.includes(message.user.id)) return channel.sendMessage("You already voted to abort timer!");
stop.push(message.user.id);

channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to abort timer! - (${stop.length}/${queue.length / 2})`);
if (stop.length >= queue.length / 2) {
channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to abort timer! - (${stop.length}/${Math.ceil(queue.length / 2)})`);
if (stop.length >= Math.ceil(queue.length / 2)) {
stop = [];

channel.sendMessage("!mp aborttimer");
Expand All @@ -92,8 +95,8 @@ client.connect().then(async () => {
if (abort.includes(message.user.id)) return channel.sendMessage("You already voted to abort the game!");
abort.push(message.user.id);

channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to abort the game! - (${abort.length}/${queue.length / 2})`);
if (abort.length >= queue.length / 2) {
channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to abort the game! - (${abort.length}/${Math.ceil(queue.length / 2)})`);
if (abort.length >= Math.ceil(queue.length / 2)) {
abort = [];

channel.sendMessage("!mp abort");
Expand All @@ -104,8 +107,8 @@ client.connect().then(async () => {
if (skip.includes(message.user.id)) return channel.sendMessage("You already voted to skip the beatmap!");
skip.push(message.user.id);

channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to skip beatmap! - (${skip.length}/${queue.length / 2})`);
if (skip.length >= queue.length / 2) {
channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to skip beatmap! - (${skip.length}/${Math.ceil(queue.length / 2)})`);
if (skip.length >= Math.ceil(queue.length / 2)) {
skip = [];
await getBeatmap();
}
Expand All @@ -123,9 +126,7 @@ client.connect().then(async () => {

channel.sendMessage(`*Rules* | Star Rating: ${AutoMap.min_star}* - ${AutoMap.max_star}* | Mode: ${mode} | Mods: ${AutoMap.mods.join(", ")} | FreeMod: ${AutoMap.freemod ? "Allowed" : "Not Allowed"}`);
} else if (command === "info") {
channel.sendMessage(`*Info* | Powered by [https://github.com/ThePooN/bancho.js Bancho.js] | Developer by [https://osu.ppy.sh/users/21216709 Suntury] | Source Code: [https://github.com/Adivise/SpaceHost SpaceHost]`);
} else if (command === "help") {
channel.sendMessage(`*Commands* | [https://github.com/Adivise/SpaceHost#-auto-map-mode Commands]`);
channel.sendMessage(`*Info* | Powered by [https://github.com/ThePooN/bancho.js Bancho.js] | Developer by [https://osu.ppy.sh/users/21216709 Suntury] | Source Code: [https://github.com/Adivise/SpaceHost SpaceHost] | [https://github.com/Adivise/SpaceHost#-features--commands Commands]`);
}
});

Expand Down
27 changes: 14 additions & 13 deletions servers/AutoTeam.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ let red = [];
let blue = [];

client.connect().then(async () => {
console.log(`[INFO] Bot is online!`);
console.log(`[INFO] Bot ${ipc.username} is online!`);
console.log(`[TIP] You can use *CRTL + C* to close the lobby!`);
console.log(`[WARN] Don't try exit with click out, the lobby will not close fully`);
console.log(`[WARN] When you do, you need to join back to the lobby and type !mp close and chat`);

const channel = await client.createLobby("Setting up lobby...");
lobby = channel.lobby;
Expand All @@ -49,7 +52,7 @@ client.connect().then(async () => {
if (beatmap.length == 0) return await getBeatmap();
if (beatmap[0].mode != AutoTeam.mode) return await getBeatmap();

channel.sendMessage(`*Details* | [https://osu.ppy.sh/beatmapsets/${beatmap[0].beatmapset_id}#/${beatmap[0].beatmap_id} ${beatmap[0].artist} - ${beatmap[0].title}] | AR: ${beatmap[0].diff_approach} | CS: ${beatmap[0].diff_size} | OD: ${beatmap[0].diff_overall} | HP: ${beatmap[0].diff_drain} | Star Rating: ${parseInt(beatmap[0].difficultyrating).toFixed(2)} ★ | Bpm: ${beatmap[0].bpm} | Length: ${convertSeconds(beatmap[0].total_length)}`);
channel.sendMessage(`*Details* | [https://osu.ppy.sh/beatmapsets/${beatmap[0].beatmapset_id}#/${beatmap[0].beatmap_id} ${beatmap[0].artist} - ${beatmap[0].title}] | AR: ${beatmap[0].diff_approach} | CS: ${beatmap[0].diff_size} | OD: ${beatmap[0].diff_overall} | HP: ${beatmap[0].diff_drain} | Star Rating: ${Number(beatmap[0].difficultyrating).toFixed(2)} ★ | Bpm: ${beatmap[0].bpm} | Length: ${convertSeconds(beatmap[0].total_length)}`);
channel.sendMessage(`*Mirror* | [https://beatconnect.io/b/${beatmap[0].beatmapset_id} BeatConnect] | [https://dl.sayobot.cn/beatmaps/download/novideo/${beatmap[0].beatmapset_id} Sayobot] | [https://api.chimu.moe/v1/download/${beatmap[0].beatmapset_id}?n=1 Chimu]`);

});
Expand All @@ -71,8 +74,8 @@ client.connect().then(async () => {
if (start.includes(message.user.id)) return channel.sendMessage("You already voted to start the game!");
start.push(message.user.id);

channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to start the game! - (${start.length}/${queue.length / 2})`);
if (start.length == queue.length / 2) {
channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to start the game! - (${start.length}/${Math.ceil(queue.length / 2)})`);
if (start.length == Math.ceil(queue.length / 2)) {
start = [];

channel.sendMessage("!mp start");
Expand All @@ -83,8 +86,8 @@ client.connect().then(async () => {
if (stop.includes(message.user.id)) return channel.sendMessage("You already voted to abort timer!");
stop.push(message.user.id);

channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to abort timer! - (${stop.length}/${queue.length / 2})`);
if (stop.length == queue.length / 2) {
channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to abort timer! - (${stop.length}/${Math.ceil(queue.length / 2)})`);
if (stop.length == Math.ceil(queue.length / 2)) {
stop = [];

channel.sendMessage("!mp aborttimer");
Expand All @@ -95,8 +98,8 @@ client.connect().then(async () => {
if (abort.includes(message.user.id)) return channel.sendMessage("You already voted to abort the game!");
abort.push(message.user.id);

channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to abort the game! - (${abort.length}/${queue.length / 2})`);
if (abort.length == queue.length / 2) {
channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to abort the game! - (${abort.length}/${Math.ceil(queue.length / 2)})`);
if (abort.length == Math.ceil(queue.length / 2)) {
abort = [];

channel.sendMessage("!mp abort");
Expand All @@ -107,8 +110,8 @@ client.connect().then(async () => {
if (skip.includes(message.user.id)) return channel.sendMessage("You already voted to skip the beatmap!");
skip.push(message.user.id);

channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to skip beatmap! - (${skip.length}/${queue.length / 2})`);
if (skip.length == queue.length / 2) {
channel.sendMessage(`[https://osu.ppy.sh/users/${message.user.id} ${message.user.username}] Voted to skip beatmap! - (${skip.length}/${Math.ceil(queue.length / 2)})`);
if (skip.length == Math.ceil(queue.length / 2)) {
skip = [];
await getBeatmap();
}
Expand All @@ -126,9 +129,7 @@ client.connect().then(async () => {

channel.sendMessage(`*Rules* | Star Rating: ${AutoTeam.min_star}* - ${AutoTeam.max_star}* | Mode: ${mode} | Mods: ${AutoTeam.mods.join(", ")} | FreeMod: ${AutoTeam.freemod ? "Allowed" : "Not Allowed"}`);
} else if (command === "info") {
channel.sendMessage(`*Info* | Powered by [https://github.com/ThePooN/bancho.js Bancho.js] | Developer by [https://osu.ppy.sh/users/21216709 Suntury] | Source Code: [https://github.com/Adivise/SpaceHost SpaceHost]`);
} else if (command === "help") {
channel.sendMessage(`*Commands* | [https://github.com/Adivise/SpaceHost#-auto-team-mode Commands]`);
channel.sendMessage(`*Info* | Powered by [https://github.com/ThePooN/bancho.js Bancho.js] | Developer by [https://osu.ppy.sh/users/21216709 Suntury] | Source Code: [https://github.com/Adivise/SpaceHost SpaceHost] | [https://github.com/Adivise/SpaceHost#-features--commands Commands]`);
}
});

Expand Down

0 comments on commit 733181c

Please sign in to comment.