Beispiel #1
0
    async def compare(self, ctx, arg=None):
        '''
        Give the user scores on the lastest beatmap in the chat.

        Parameters:
            ctx (obj): context for the bot
            arg (int/str): username or id of the play to compare (can be blank if username was already set)

        Returns:
            embed : Contains every information for the score
        '''
        if arg == None:
            connection = sqlite3.connect('data/Users.db')
            cursor = connection.cursor()

            cursor.execute("SELECT osu_id FROM osuset WHERE discord_id=?",
                           (ctx.author.id, ))
            databaseSection = cursor.fetchone()
            if databaseSection != None:
                arg = databaseSection[0]
            else:
                await ctx.send(
                    "Enter your username or set your osu profile using the osuset command! : m!osuset {username}"
                )

        res = osuApiCall.get_scores(beatmap_id=self.beatmap_id, username=arg)
        score = res[0]

        res2 = osuApiCall.get_beatmaps(beatmap_id=self.beatmap_id)
        beatmap = res2[0]

        mapLink = "https://osu.ppy.sh/beatmapsets/" + str(
            beatmap.beatmapset_id) + "#osu/" + str(beatmap.beatmap_id)

        elementList = {}
        i = 0
        elementList["NaN_decorator:✦" + str(i)] = str(i + 1) + "."
        elementList["NaN_noDecoration_bracketLeft_" + str(i)] = beatmap.artist
        elementList["separator:-" + str(i)] = ""
        elementList["NaN_title" + str(i)] = beatmap.title
        elementList["separator:|" + str(i)] = ""
        elementList["NaN_beatmapVersion_bracketRight" +
                    str(i)] = beatmap.version
        elementList["link" + str(i)] = mapLink
        elementList["NaN_modsUsed_decorator:▸_" + str(i)] = res[i].enabled_mods
        elementList["NaN_pp_newline_decorator:▸" +
                    str(i)] = str(int(round(res[i].pp, 0))) + "pp"
        elementList["NaN_owncombo_decorator:▸" + str(i)] = res[i].maxcombo
        elementList["NaN_comboseparator:/" + str(i)]: ""
        elementList["NaN_mapcombo_" + str(i)] = beatmap.max_combo
        elementList["NaN_accuracy_decorator:▸_suffix:%" + str(i)] = round(
            score.accuracy(mode=osuapi.enums.OsuMode.osu) * 100, 2)
        elementList["NaN_count300_bracketLeft_decorator:▸" +
                    str(i)] = score.count300
        elementList["NaN_300/100parator:/" + str(i)]: ""
        elementList["NaN_count100" + str(i)] = score.count100
        elementList["NaN_100/50parator:/" + str(i)]: ""
        elementList["NaN_count50" + str(i)] = score.count50
        elementList["NaN_50/missparator:/" + str(i)]: ""
        elementList["NaN_countmiss+bracketRight" + str(i)] = score.countmiss
        elementList["newline_" + str(i)] = ""

        newEmbed = embedHandler(elementList, embedType=1, color=0xFF748C)

        newEmbed.setAuthor(name="Top osu plays for " + str(arg))
        newEmbed.setFooter(text="ill see")

        DaEmbed = newEmbed.getEmbed()
        await ctx.send(embed=DaEmbed)
Beispiel #2
0
    def userTop(self, arg, gamemode):
        if type(arg) == int:
            pass
        else:
            if arg.isdigit():
                arg = int(arg)

        if gamemode == "standard":
            res = osuApiCall.get_user_best(username=arg)
            user = osuApiCall.get_user(username=arg)[0]
            print("user : "******"taiko":
            res = osuApiCall.get_user_best(arg,
                                           mode=osuapi.enums.OsuMode.taiko)
        if gamemode == "ctb":
            res = osuApiCall.get_user_bestr(arg, mode=osuapi.enums.OsuMode.ctb)
        if gamemode == "mania":
            res = osuApiCall.get_user_best(arg,
                                           mode=osuapi.enums.OsuMode.mania)

        elementList = {}
        i = 0
        while i < 5:
            beatmap = osuApiCall.get_beatmaps(beatmap_id=res[i].beatmap_id)[0]
            score = osuApiCall.get_scores(username=arg,
                                          beatmap_id=res[i].beatmap_id)[0]
            mapLink = "https://osu.ppy.sh/beatmapsets/" + str(
                beatmap.beatmapset_id) + "#osu/" + str(beatmap.beatmap_id)

            elementList["NaN_decorator:✦" + str(i)] = str(i + 1) + "."
            elementList["NaN_noDecoration_bracketLeft_" +
                        str(i)] = beatmap.artist
            elementList["separator:-" + str(i)] = ""
            elementList["NaN_title" + str(i)] = beatmap.title
            elementList["separator:|" + str(i)] = ""
            elementList["NaN_beatmapVersion_bracketRight" +
                        str(i)] = beatmap.version
            elementList["link" + str(i)] = mapLink
            elementList["NaN_modsUsed_decorator:▸_" +
                        str(i)] = res[i].enabled_mods.shortname
            elementList["NaN_pp_newline_decorator:▸" +
                        str(i)] = str(int(round(res[i].pp, 0))) + "pp"
            elementList["NaN_owncombo_decorator:▸" + str(i)] = res[i].maxcombo
            elementList["NaN_comboseparator:/" + str(i)]: ""
            elementList["NaN_mapcombo_" + str(i)] = beatmap.max_combo
            elementList["NaN_accuracy_decorator:▸_suffix:%" + str(i)] = round(
                score.accuracy(mode=osuapi.enums.OsuMode.osu) * 100, 2)
            elementList["NaN_count300_bracketLeft_decorator:▸" +
                        str(i)] = score.count300
            elementList["NaN_300/100parator:/" + str(i)]: ""
            elementList["NaN_count100" + str(i)] = score.count100
            elementList["NaN_100/50parator:/" + str(i)]: ""
            elementList["NaN_count50" + str(i)] = score.count50
            elementList["NaN_50/missparator:/" + str(i)]: ""
            elementList["NaN_countmiss+bracketRight" +
                        str(i)] = score.countmiss
            elementList["newline_" + str(i)] = ""

            i = i + 1

        newEmbed = embedHandler(elementList, embedType=1, color=0xFF748C)

        newEmbed.setAuthor(name=str(user.username) + "'s " + gamemode +
                           " toplays",
                           url=user.url,
                           icon_url=user.profile_image)
        newEmbed.setFooter(text="yea")
        return newEmbed.getEmbed()
Beispiel #3
0
    def setBeatmapInformation(self, message, redownload=None):
        '''
        Set the beatmap_id and OppaiMapInfo as an class attribute.

        Parameters:
            message* (obj): The message with the associated information
                    *need to be a link

            redownloa : by default it set to None, so each map get download, if it's set to something
                        the mapset don't get redownloaded
        Return:
            Nothing, this function simply sets attributes
        '''

        # Detects if modes where added after the link
        space = message.find(" ")

        if space != -1:
            self.mods = message[space+1:]
            self.mods = self.mods.upper()
            space = 1
        else:
            self.mods = None
            space = 0

        # set beatmap_id as an attribute for the whole class
        index = message.rindex("/")

        if self.mods != None:
            self.beatmap_id = message[index+1:-len(self.mods)-space]
        else :
            self.beatmap_id = message[index+1:]

        res = osuApiCall.get_beatmaps(beatmap_id=self.beatmap_id)
        beatmap = res[0]

        resMapset= osuApiCall.get_beatmaps(beatmapset_id=beatmap.beatmapset_id)

        mapsetUnsorted = {}
        for v in resMapset:
            mapsetUnsorted[v]=v.difficultyrating

        self.mapset=list(dict(sorted(mapsetUnsorted.items(),key= lambda x:x[1])))

        # Before downloading the mapset we will remove the existing files and then we'll download the mapset
        if redownload == None:
            for file in os.listdir('C:/Users/DELL/Desktop/osu-mocha/map_cache/'):
                os.remove(os.path.join('C:/Users/DELL/Desktop/osu-mocha/map_cache/', file))

            url = 'https://nerina.pw/d/' + str(beatmap.beatmapset_id)
            wget.download(url, 'C:/Users/DELL/Desktop/osu-mocha/map_cache/' + str(beatmap.beatmapset_id) + ".osz")

        # osz are compressed files, we can basically open them with zip
        pathFile = ""
        with ZipFile('C:/Users/DELL/Desktop/osu-mocha/map_cache/' + str(beatmap.beatmapset_id) + '.osz', 'r') as zip:
            for filename in zip.namelist():
                if  filename.endswith('.osu') and filename.find(beatmap.version) != -1:
                    zip.extract(filename,'C:/Users/DELL/Desktop/osu-mocha/map_cache/')
                    pathFile = 'C:/Users/DELL/Desktop/osu-mocha/map_cache/' + filename

        self.oppaiMapInfo = oppadc.OsuMap(file_path=pathFile)
Beispiel #4
0
    def userRecent(self, arg, gamemode):
        def playedOn(dateInUTC):
            now = datetime.now()
            hours = now.hour + 4
            minutes = now.minute
            secondes = now.second
            print(hours, minutes, secondes)
            d = 24 - dateInUTC.hour

            print(hours + d)
            return "4"

        if type(arg) == int:
            pass
        else:
            if arg.isdigit():
                arg = int(arg)

        if gamemode == "standard":
            recent = osuApiCall.get_user_recent(username=arg)[0]
            user = osuApiCall.get_user(username=arg)[0]
            beatmap = osuApiCall.get_beatmaps(beatmap_id=recent.beatmap_id)[0]
            print("user : "******"taiko":
            res = osuApiCall.get_user_recent(arg,
                                             mode=osuapi.enums.OsuMode.taiko)
        if gamemode == "ctb":
            res = osuApiCall.get_user_recent(arg,
                                             mode=osuapi.enums.OsuMode.ctb)
        if gamemode == "mania":
            res = osuApiCall.get_user_recent(arg,
                                             mode=osuapi.enums.OsuMode.mania)

        mapLink = "https://osu.ppy.sh/beatmapsets/" + str(
            beatmap.beatmapset_id) + "#osu/" + str(beatmap.beatmap_id)

        cogMap = self.bot.get_cog("map")
        cogMap.setBeatmapInformation(mapLink)

        #need a separator without space between, meanwhile :
        combo = str(recent.maxcombo) + "/" + str(beatmap.max_combo)
        count = "[" + str(recent.count300) + "/" + str(
            recent.count100) + "/" + str(recent.count50) + "/" + str(
                recent.countmiss) + "]"

        print(len("M2U & Gentle Stick - Hades in the Heaven [Aquosity]"))

        elementList = {
            "NaN_decorator:✦":
            "",
            "NaN_noDecoration_bracketLeft":
            beatmap.artist,
            "separator:-":
            "",
            "NaN_title":
            beatmap.title,
            "NaN_beatmapVersion_bracketRight":
            "[" + str(beatmap.version) + "]",
            "link":
            mapLink,
            "NaN_modsUsed_decorator:▸":
            recent.enabled_mods,
            "NaN_rank_newline_decorator:▸":
            recent.rank,
            "NaN_score_decorator:▸":
            recent.score,
            "NaN_pp_decorator:▸":
            str(
                round(
                    cogMap.oppaiMapInfo.getPP(n300=recent.count300,
                                              n100=recent.count100,
                                              n50=recent.count50,
                                              misses=recent.countmiss,
                                              combo=recent.maxcombo).total_pp,
                    2)) + "pp",
            "NaN_combo_decorator:▸":
            combo,
            "NaN_accuracy_decorator:▸_suffix:%":
            round(recent.accuracy(mode=osuapi.enums.OsuMode.osu) * 100, 2),
            "NaN_count300m!_decorator:▸_box":
            count,
            "Played on ":
            playedOn(recent.date),
        }

        newEmbed = embedHandler(elementList, embedType=1, color=0xFF748C)

        newEmbed.setAuthor(name=str(user.username) + "'s " + gamemode +
                           " most recent play",
                           url=user.url,
                           icon_url=user.profile_image)
        newEmbed.setFooter(text="gg bg")
        newEmbed.setThumbnail(url=beatmap.cover_thumbnail)
        return newEmbed.getEmbed()
Beispiel #5
0
    def mapEmbed(self):
        '''
        Create the embed containg the beatmap informations.

        Returns:
             Embed, containing the beatmap informations.
        '''

        def diffEmote(starRating):
            '''
            Apply the correct difficulty emote depending on the star rating of the map.

            Parameters:
                starRating (float): Star rating of the current map

            Returns:
                emote (str): discord emote reprensting the difficulty of the map
            '''
            if starRating < 2:
                return "<:easy:837747972099014717>"
            elif starRating < 2.70:
                return "<:normal:837748258838544474>"
            elif starRating < 4.00:
                return "<:hard:837748285690871871>"
            elif starRating < 5.30:
                return "<:insane:837748311573397546>"
            elif starRating < 6.50:
                return "<:expert:837748338501353532>"
            elif starRating >= 6.5:
                return "<:expertplus:837748363797200927>"

        def lengthFormat(length):
            '''
            Convert the map length from seconds to minutes and seconds

            Parameters:
                length (int): Lenght of the map in seconds

            Returns:
                minute:seconds (str): Lenght displayed as minutes:seconds
            '''
            if self.mods != None:
                if self.mods.find("DT") != -1 or self.mods.find("NC") != -1:
                    length = length * 2/3
                elif self.mods.find("HT") != -1:
                    length = length * 4/3


            min = length //60
            sec = length - min*60
            sec = round(sec,0)

            # to avoid having .0
            if type(min) != int:
                if min.is_integer():
                    min = int(min)
            if type(sec) != int:
                if sec.is_integer():
                    sec = int(sec)

            if sec == 0:
                sec = "00"
            if sec < 10:
                sec = "0" + str(sec)

            return "{}:{}".format(min,sec)

        def statusOnDate(status,date):
            '''
            Output the status of the map alongside the date corresponding to that status.

            Parameters:
                status (obj): the status of the map
                date (obj): a date format

            Returns:
                status:date (str): status of the map alongside the date
            '''
            approvedStatus = {4:"Loved", 3:"Qualified", 2:"Approved", 1 : "Ranked", 0 : "Pending", -1 : "WIP", -2 :" Graveyard"}
            status = approvedStatus[status.value]

            return "{} on {}".format(status, date.date())

        def showMods(mods):
            '''
            Output the mods applied to the map. (it's to avoid displaying mods that dont exist)

            Parameters:
                mods (str/None): the mods used

            Returns:
                mods (string): the mods that will show on the embed.

            * Known issues, if multiple mods are combined and one have an error it still shows them
                ex: FLAE --> map will be calculated with FL but it still shows "AE"
            '''
            if type(mods) != str:
                return "NM"
            else:
                modsDisplay = ["NF", "EZ", "HD", "HR", "DT", "NC" "SD", "FL", "SO"]
                for v in modsDisplay:
                    if mods.find(v) != -1:
                        return "+" + mods
                else:
                    return "NM"

        res = osuApiCall.get_beatmaps(beatmap_id=self.beatmap_id)
        beatmap = res[0]

        mapLink= "https://osu.ppy.sh/beatmapsets/" + str(beatmap.beatmapset_id) + "#osu/" + str(beatmap.beatmap_id)

        # *this is needed, we can't set specifics mods for the getStats so I'm putting it here and the sr takes it with the mods applied.
        self.oppaiMapInfo.getPP(Mods=self.mods)

        elementList = {"NaN_artist_bracketLeft_decorator:✦":beatmap.artist,
        "separator:-":"",
        "NaN_title":beatmap.title,
        "NaN_by":"by",
        "NaN_mapper_bracketRight":beatmap.creator,
        "link":mapLink,
        "newline":"",
        "NaN_diffemote":diffEmote(beatmap.difficultyrating),
        "separator:-_1":"",
        "NaN_diffname":beatmap.version,
        "NaN_box":showMods(self.mods),
        "Difficulty":round(self.oppaiMapInfo.getStats().total,2),
        "Length_noNewline":lengthFormat(beatmap.total_length),
        "BPM":beatmap.bpm,
        "Max Combo_noNewline":beatmap.max_combo,
        "AR":round(self.oppaiMapInfo.getDifficulty().ar,2),
        "OD_noDecoration_noNewline":round(self.oppaiMapInfo.getDifficulty().od,2),
        "HP_noDecoration_noNewline":round(self.oppaiMapInfo.getDifficulty().hp,2),
        "CS_noDecoration_noNewline":round(self.oppaiMapInfo.getDifficulty().cs,2),
        "PP":" ",
        "95%_noNewline_noDecorator":str(round(self.oppaiMapInfo.getPP(Mods=self.mods, accuracy=95.00).total_pp,2)),
        "99%_noNewline_noDecorator":str(round(self.oppaiMapInfo.getPP(Mods=self.mods, accuracy=99.00).total_pp,2)),
        "100%_noNewline_noDecorator":str(round(self.oppaiMapInfo.getPP(Mods=self.mods, accuracy=100.00).total_pp,2))}

        newEmbed = embedHandler(elementList,embedType=1,color=0xFF748C)

        i = 0
        while i < len(self.mapset):
            if self.mapset[i].version == beatmap.version:
                break
            i = i + 1

        newEmbed.setAuthor(name= "Map information")
        newEmbed.setFooter(text=" {0} | {1} ♡ | {2}".format(statusOnDate(beatmap.approved,beatmap.approved_date),beatmap.favourite_count, "Map " + str(i+1) + " on " + str(len(self.mapset))))
        newEmbed.setImage(url=beatmap.cover_image)

        return newEmbed.getEmbed()