From f9d6e794478626efeefa97de6e0a773805ce28fb Mon Sep 17 00:00:00 2001 From: russelg Date: Tue, 7 Jun 2016 01:10:32 +0800 Subject: [PATCH] .BANCHO. Add accuracy, beatmap link and rank to !last --- constants/fokabotCommands.py | 17 +++++++-- events/logoutEvent.py | 2 +- handlers/mainHandler.py | 2 +- helpers/generalFunctions.py | 67 ++++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 4 deletions(-) diff --git a/constants/fokabotCommands.py b/constants/fokabotCommands.py index 22aa153..08a5453 100644 --- a/constants/fokabotCommands.py +++ b/constants/fokabotCommands.py @@ -479,7 +479,8 @@ def tillerinoAcc(fro, chan, message): def tillerinoLast(fro, chan, message): try: - data = glob.db.fetch("""SELECT beatmaps.song_name as sn, scores.pp + data = glob.db.fetch("""SELECT beatmaps.song_name as sn, scores.*, + beatmaps.beatmap_id as bid FROM scores LEFT JOIN beatmaps ON beatmaps.beatmap_md5=scores.beatmap_md5 LEFT JOIN users ON users.id = scores.userid @@ -488,7 +489,19 @@ def tillerinoLast(fro, chan, message): LIMIT 1""", [fro]) if data == None: return False - return "{0:.2f}pp ({1} on {2})".format(data["pp"], fro, data["sn"]) + + rank = generalFunctions.getRank(data["play_mode"], data["mods"], data["accuracy"],\ + data["300_count"], data["100_count"], data["50_count"], data["misses_count"]) + + msg = "{0:.2f}pp".format(data["pp"]) + msg += " on " if chan == "FokaBot" else " | {0} on ".format(fro) + msg += "({0})[http://osu.ppy.sh/b/{1}]".format(data["sn"], data["bid"]) + + if data["mods"]: + msg += ' +' + generalFunctions.readableMods(data["mods"]) + msg += " ({0:.2f}%, {1})".format(data["accuracy"], rank.upper()) + + return msg except Exception as a: log.error(a) return False diff --git a/events/logoutEvent.py b/events/logoutEvent.py index 9de417b..ef71beb 100644 --- a/events/logoutEvent.py +++ b/events/logoutEvent.py @@ -37,4 +37,4 @@ def handle(userToken, _): glob.tokens.deleteToken(requestToken) # Console output - log.info("{} have been disconnected.".format(username)) + log.info("{} has been disconnected.".format(username)) diff --git a/handlers/mainHandler.py b/handlers/mainHandler.py index 632cfd7..4b03d7e 100644 --- a/handlers/mainHandler.py +++ b/handlers/mainHandler.py @@ -165,7 +165,7 @@ class handler(requestHelper.asyncRequestHandler): responseData = serverPackets.loginError() responseData += serverPackets.notification("Whoops! Something went wrong, please login again.") log.warning("Received packet from unknown token ({}).".format(requestTokenString)) - log.info("{} have been disconnected (invalid token)".format(requestTokenString)) + log.info("{} has been disconnected (invalid token)".format(requestTokenString)) finally: # Unlock token if userToken != None: diff --git a/helpers/generalFunctions.py b/helpers/generalFunctions.py index fec2f28..47e9383 100644 --- a/helpers/generalFunctions.py +++ b/helpers/generalFunctions.py @@ -53,6 +53,73 @@ def readableMods(__mods): return r +def getRank(gameMode, __mods, acc, c300, c100, c50, cmiss): + """ + Return a string with rank/grade for a given score. + Used mainly for "tillerino" + + gameMode -- mode (0 = osu!, 1 = Taiko, 2 = CtB, 3 = osu!mania) + __mods -- mods bitwise number + acc -- accuracy + c300 -- 300 hit count + c100 -- 100 hit count + c50 -- 50 hit count + cmiss -- miss count + return -- rank/grade string + """ + total = c300 + c100 + c50 + cmiss + hdfl = (__mods & mods.Hidden > 0) or (__mods & mods.Flashlight > 0) + + def ss(): + return "sshd" if hdfl else "ss" + + def s(): + return "shd" if hdfl else "s" + + if gameMode == 0: + # osu!std + if acc == 100: + return ss() + if c300 / total > 0.90 and c50 / total < 0.1 and cmiss == 0: + return s() + if (c300 / total > 0.80 and cmiss == 0) or (c300 / total > 0.90): + return "a" + if (c300 / total > 0.70 and cmiss == 0) or (c300 / total > 0.80): + return "b" + if c300 / total > 0.60: + return "c" + return "d" + elif gameMode == 1: + # taiko not implemented as of yet. + return "a" + elif gameMode == 2: + # CtB + if acc == 100: + return ss() + if acc >= 98.01 and acc <= 99.99: + return s() + if acc >= 94.01 and acc <= 98.00: + return "a" + if acc >= 90.01 and acc <= 94.00: + return "b" + if acc >= 98.01 and acc <= 90.00: + return "c" + return "d" + elif gameMode == 3: + # osu!mania + if acc == 100: + return ss() + if acc > 95: + return s() + if acc > 90: + return "a" + if acc > 80: + return "b" + if acc > 70: + return "c" + return "d" + + return "a" def strContains(s, w): return (' ' + w + ' ') in (' ' + s + ' ')