From f85a23910fa2204fb33aac6dc368ff6ec19f3634 Mon Sep 17 00:00:00 2001 From: Adivise <61177761+Adivise@users.noreply.github.com> Date: Mon, 5 Dec 2022 13:40:23 +0700 Subject: [PATCH] Update `1.0.1` --- AutoHost.bat | 9 ++ AutoMap.bat | 9 ++ AutoTeam.bat | 9 ++ README.md | 4 +- package.json | 19 +++ servers/AutoHost.js | 251 +++++++++++++++++++++++++++++++++++ servers/AutoMap.js | 174 ++++++++++++++++++++++++ servers/AutoTeam.js | 223 +++++++++++++++++++++++++++++++ settings/config.json.example | 7 + settings/lobby.json | 43 ++++++ structures/ConvertTime.js | 66 +++++++++ 11 files changed, 812 insertions(+), 2 deletions(-) create mode 100644 AutoHost.bat create mode 100644 AutoMap.bat create mode 100644 AutoTeam.bat create mode 100644 package.json create mode 100644 servers/AutoHost.js create mode 100644 servers/AutoMap.js create mode 100644 servers/AutoTeam.js create mode 100644 settings/config.json.example create mode 100644 settings/lobby.json create mode 100644 structures/ConvertTime.js diff --git a/AutoHost.bat b/AutoHost.bat new file mode 100644 index 0000000..8483d51 --- /dev/null +++ b/AutoHost.bat @@ -0,0 +1,9 @@ +@echo off + +title Auto Host Rotate + +:StartBot + +node servers/AutoHost.js + +goto StartBot diff --git a/AutoMap.bat b/AutoMap.bat new file mode 100644 index 0000000..20c2245 --- /dev/null +++ b/AutoMap.bat @@ -0,0 +1,9 @@ +@echo off + +title Auto Map Select + +:StartBot + +node servers/AutoMap.js + +goto StartBot diff --git a/AutoTeam.bat b/AutoTeam.bat new file mode 100644 index 0000000..5f3c808 --- /dev/null +++ b/AutoTeam.bat @@ -0,0 +1,9 @@ +@echo off + +title Auto Team Versus + +:StartBot + +node servers/AutoTeam.js + +goto StartBot diff --git a/README.md b/README.md index 9252819..ee7a4f1 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ npm install ## 📄 Configuration -Copy or Rename in setttings/`config.json.example` to `config.json` and fill out the values: +Copy or Rename in `setttings/config.json.example` to `config.json` and fill out the values: ```.json { @@ -48,7 +48,7 @@ Copy or Rename in setttings/`config.json.example` to `config.json` and fill out } ``` -Lobby Configuration (Example): +Lobby Configuration in `settings/lobby.json` (Example): ```.json { diff --git a/package.json b/package.json new file mode 100644 index 0000000..dce8791 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "space-rotate", + "version": "1.0.1", + "description": "osu bot auto host rotate", + "main": "./servers/AutoHost.js", + "scripts": { + "rotate": "node ./servers/AutoHost.js", + "map": "node ./servers/AutoMap.js", + "versus": "node ./servers/AutoVersus.js" + }, + "dependencies": { + "bancho.js": "^0.11.0", + "dotenv": "^16.0.3", + "node-fetch": "^2.6.0", + "nodesu": "^0.7.3" + }, + "author": "Adivise", + "license": "ISC" +} diff --git a/servers/AutoHost.js b/servers/AutoHost.js new file mode 100644 index 0000000..adeba6c --- /dev/null +++ b/servers/AutoHost.js @@ -0,0 +1,251 @@ +const { BanchoClient } = require("bancho.js"); +const { Client } = require("nodesu"); +const { convertSeconds } = require("../structures/ConvertTime.js"); +const { Rotator } = require("../settings/lobby.json"); +const { ipc } = require("../settings/config.json"); +const fetch = require("node-fetch"); + +process.on('unhandledRejection', error => console.log(error)); +process.on('uncaughtException', error => console.log(error)); + +const client = new BanchoClient(ipc); + +let lobby; + +// Memory database console died = no more database +let queue = []; +let host = 0; +let vote = []; + +client.connect().then(async () => { + console.log(`[INFO] Bot is online!`); + + const channel = await client.createLobby("Setting up lobby..."); + lobby = channel.lobby; + + await Promise.all([ + lobby.setPassword(Rotator.password), + lobby.setMods(Rotator.mods, Rotator.freemod), + lobby.setName(Rotator.name), + lobby.invitePlayer(ipc.username), + lobby.setSettings(Rotator.team_mode, Rotator.win_condition, Rotator.size) + ]); + // setfreemods + console.log("Lobby Created! Name: " + lobby.name + ", password: " + Rotator.password); + console.log("Multiplayer link: https://osu.ppy.sh/mp/" + lobby.id); + + lobby.on("beatmapId", async (beatmapId) => { + if (beatmapId == null) return; + + const { beatmaps } = new Client(ipc.apiKey); + const beatmap = await beatmaps.getByBeatmapId(beatmapId); + + 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(`*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]`); + + }); + + lobby.channel.on("message", async (message) => { + const date = new Date(); + const time = date.toLocaleTimeString(); + + console.log(`[${time}] [DEBUG] ` + message.content); + + const prefix = "!" + if (!message.content.startsWith(prefix)) return; + const args = message.content.slice(prefix.length).trim().split(/ +/g); + const command = args.shift().toLowerCase(); + + if (command === "start") { + if (host !== message.user.id) return channel.sendMessage("You are not the host!"); + if (args[0]) { + channel.sendMessage(`!mp start ${args[0]}`); + } else { + channel.sendMessage(`!mp start`); + } + } else if (command === "stop") { + if (host !== message.user.id) return channel.sendMessage("You are not the host!"); + channel.sendMessage(`!mp aborttimer`); + } else if (command === "abort") { + if (host !== message.user.id) return channel.sendMessage("You are not the host!"); + channel.sendMessage(`!mp abort`); + } else if (command === "skip") { // next queue + if (host == message.user.id) { + if (queue.length == 1) return channel.sendMessage("No players to host!"); + // host to next player + lobby.setHost("#" + queue[1]); + // return + return; + } + + 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})`); + + if (vote.length >= queue.length / 2) { + lobby.channel.sendMessage("Skip Vote Passed!"); + // remove vote + vote = []; + // host to next player + lobby.setHost("#" + queue[1]); + } + } else if (command === "queue" || command === "q") { + 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}]`); + } + channel.sendMessage(`Host Queue: ${strArray.join(", ")}`); + } else if (command === "rule" || command === "rules") { + 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"}`); + } 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: Source Code: [https://github.com/Adivise/SpaceTime SpaceTime]`); + } else if (command === "help") { + channel.sendMessage(`*Commands* | !start