async def perf(self, ctx, *, args=None): """Shows information about pp of a certain map""" args = self.bot.osuHelpers.parseArgsV2(args=args, customArgs=["mods", "beatmap"]) mode = args["mode"] if args["beatmap"]: beatmap: osuClasses.Beatmap = await self.bot.osuHelpers.getBeatmapFromText( args["beatmap"]) else: beatmap: osuClasses.Beatmap = await self.bot.osuHelpers.getBeatmapFromHistory( ctx) if beatmap is None: await ctx.send("Failed to find any maps") return if self.bot.config.redis is True: redisIO.setValue(ctx.message.channel.id, beatmap.beatmap_id) redisIO.setValue(f'{ctx.message.channel.id}.mode', mode.id) mods: osuClasses.Mods = osuClasses.Mods(args["mods"]) perf = await self.bot.ppAPI.calculateBeatmap(beatmap.beatmap_id, mods, mode) result = OsuPerformanceEmbed(beatmap, perf, self.bot.config.color) await ctx.send(embed=result)
async def getbmap(self, beatmap_id: int = None, beatmapset_id: int = None, mode: osu.Mode = None, server: osu.Server = osu.Server.BANCHO, mods: osu.Mods = osu.Mods(0), limit: int = 1) -> osu.Beatmap: async with aiohttp.ClientSession() as cs: params = { 'k': self.__token, 'mods': int(mods), 'limit': limit, 'a': 1 } if mode: params['m'] = mode.id if beatmap_id is None: params['s'] = beatmapset_id else: params['b'] = beatmap_id try: async with cs.get(server.api_getbmap, params=params) as r: if (res := await r.json()) == []: raise ValueError("Response is empty.") else: return osu.Beatmap(res[0], server)
async def getbmap(self, beatmap_id: int = None, beatmapset_id: int = None, mode: osu.Mode = osu.Mode.STANDARD, server: osu.Server = osu.Server.BANCHO, mods: osu.Mods = osu.Mods(0), limit: int = 1) -> osu.Beatmap: # mods = __cleanMods(kwargs.pop('mods', 0), mode) async with aiohttp.ClientSession() as cs: params = { 'k': self.__token, 'm': mode.id, 'mods': int(mods), 'limit': limit, 'a': 1 } if beatmap_id is None: params['s'] = beatmapset_id else: params['b'] = beatmap_id async with cs.get(server.api_getbmap, params=params) as r: res = await r.json() if res == []: raise ValueError("Invalid query or API down.") else: return osu.Beatmap(res[0], server)
def __init__(self, json_response, server: osu.Server = osu.Server.BANCHO, mode: osu.Mode = osu.Mode.STANDARD): self.server = server self.mode = mode self.score: int = int(json_response["score"]) self.maxcombo: int = int(json_response["maxcombo"]) self.count50: int = int(json_response["count50"]) self.count100: int = int(json_response["count100"]) self.count300: int = int(json_response["count300"]) self.countmiss: int = int(json_response["countmiss"]) self.countkatu: int = int(json_response["countkatu"]) self.countgeki: int = int(json_response["countgeki"]) self.perfect: bool = bool(int(json_response["perfect"])) self.user_id: int = int(json_response["user_id"]) self.rank: osu.Rank = osu.Rank[json_response["rank"]] self.enabled_mods: osu.Mod = osu.Mods( int(json_response["enabled_mods"])) self.performance: osu.Performance = None self.date: datetime = datetime.strptime(json_response["date"], "%Y-%m-%d %H:%M:%S") self.pp = 0 if "pp" in json_response and json_response["pp"]: self.pp = float(json_response["pp"])
def __init__(self, json_response, server: osu.Server = osu.Server.BANCHO, mode: osu.Mode = osu.Mode.STANDARD): self.server = server self.mode = mode self.score: int = int(json_response["score"]) try: self.maxcombo: int = int(json_response["maxcombo"]) except KeyError: #Relax Server Formatting self.maxcombo: int = int(json_response["max_combo"]) try: self.count50: int = int(json_response["count50"]) except KeyError: self.count50: int = int(json_response["count_50"]) try: self.count100: int = int(json_response["count100"]) except KeyError: self.count100: int = int(json_response["count_100"]) try: self.count300: int = int(json_response["count300"]) except KeyError: self.count300: int = int(json_response["count_300"]) try: self.countmiss: int = int(json_response["countmiss"]) except KeyError: self.countmiss: int = int(json_response["count_miss"]) try: self.countkatu: int = int(json_response["countkatu"]) except KeyError: self.countkatu: int = int(json_response["count_katu"]) try: self.countgeki: int = int(json_response["countgeki"]) except KeyError: self.countgeki: int = int(json_response["count_geki"]) try: self.perfect: bool = bool(int(json_response["perfect"])) except KeyError: self.perfect: bool = bool(int(json_response["full_combo"])) if self.server is osu.Server.AKATSUKIRX: self.perfect = True try: self.user_id: int = int(json_response["user_id"]) except KeyError: self.user_id: int = int(json_response["id"]) self.rank: osu.Rank = osu.Rank[json_response["rank"]] try: self.enabled_mods: osu.Mod = osu.Mods( int(json_response["enabled_mods"])) except KeyError: self.enabled_mods: osu.Mod = osu.Mods(int(json_response["mods"])) self.performance: osu.Performance = None try: self.pp: float = float(json_response["pp"] or 0) except Exception: self.pp = 0 try: self.date: datetime = datetime.strptime(json_response["date"], "%Y-%m-%d %H:%M:%S") except KeyError: cleanedDate = json_response['time'].split('+', 1)[0] self.date: datetime = datetime.strptime(cleanedDate, "%Y-%m-%dT%H:%M:%S")