Esempio n. 1
0
 async def do_work():
     await ctx.channel.trigger_typing()
     sender = ctx.message.author
     message_logger("COMMAND",
                    ".myscores command requested by " + sender.display_name)
     if ctx.message.content == ".myscores":
         codes = friend_codes()
         codes.load()
         code = codes.get_code(ctx.author.id)
         if code == None:
             message_logger("COMMAND",
                            "Help message sent, error with arguments")
             for channel in ctx.guild.channels:
                 if str(channel) == "audica-friend-codes":
                     m = await ctx.send(
                         content=
                         "Friend code not found. To link your friend code post it in "
                         + channel.mention + ".")
                     client.loop.create_task(
                         cooldown_reaction(m, myscores_command_cooldown))
         else:
             request = api.post_request(api.global_songs, [code])
             pages = []
             page = []
             all_songs = []
             count = 0
             ammount = 0
             total_score = 0
             for i in request["leaderboard"]:
                 if i["data"] != []:
                     if i["leaderboard_name"] != "all_time_leaders":
                         if i["leaderboard_name"] != "all_time_totals":
                             ammount = ammount + 1
             for p in request["leaderboard"]:
                 if p["leaderboard_name"] != "all_time_leaders":
                     if p["leaderboard_name"] != "all_time_totals":
                         if p["data"] != []:
                             page.append(p)
                             count = count + 1
                             print(count)
                             total_score = total_score + p["data"][0][
                                 "score"]
                             if count == 20 or count == 40 or count == ammount:
                                 pages.append(page)
                                 page = []
             for page in pages:
                 for data in page:
                     all_songs.append(data)
             m = None
             for page in pages:
                 m = await ctx.send(embed=make_myscores_embed(
                     page, sender, api, all_songs, total_score))
                 await asyncio.sleep(0.1)
             client.loop.create_task(
                 cooldown_reaction(m, myscores_command_cooldown))
Esempio n. 2
0
 async def do_work():
     await ctx.channel.trigger_typing()
     sender = ctx.message.author
     message_logger("COMMAND",
                    ".compare command requested by " + sender.display_name)
     users = user_list()
     codes = friend_codes()
     users.load()
     codes.load()
     user = codes.get_code(sender.id)
     if user == None:
         message_logger("COMMAND",
                        "Help message sent, error with arguments")
         for channel in ctx.guild.channels:
             if str(channel) == "audica-friend-codes":
                 m = await ctx.send(
                     content=
                     "Friend code not found. To link your friend code post it in "
                     + channel.mention + ".")
     else:
         try:
             request = api.post_request(api.global_songs, [user])
             pages = []
             page = []
             all_songs = []
             count = 0
             ammount = 0
             for i in request["leaderboard"]:
                 if i["data"] != []:
                     ammount = ammount + 1
             for p in request["leaderboard"]:
                 if p["data"] != []:
                     page.append(p)
                     count = count + 1
                     if count == 20 or count == 40 or count == ammount:
                         pages.append(page)
                         page = []
             m = None
             for page in pages:
                 #print(page)
                 m = await ctx.send(
                     embed=make_compare_mps_embed(page, user, sender, api))
         except Exception as e:
             print(e)
             m = await ctx.send(content="Unexpected error with the command."
                                )
     client.loop.create_task(cooldown_reaction(m, compare_command_cooldown))
Esempio n. 3
0
async def add_friend_code(m):
    codes = friend_codes()
    codes.load()
    friend_code = m.content.split(" ")[1].replace(">", "")
    user_id = m.author.id
    found = False
    identical = False
    for code in codes.friend_codes["friend_codes"]:
        if code["discord_id"] == user_id:
            found = True
            if code["friend_code"] == friend_code:
                identical = True
    if identical == False:
        if found == True:
            codes.delete(friend_code, user_id)
        codes.add(friend_code, user_id)
        codes.save()
        return True
    return False
Esempio n. 4
0
def make_leaderboards_embed(scores,
                            sender,
                            song,
                            difficulty,
                            top20=False,
                            Global=False,
                            ost=[],
                            api=None,
                            custom=False):
    max_score = 0
    ranks_string = ""
    users_string = ""
    all_scores_string = ""
    platform_id = ""
    sum_of_timestamps = 0
    ammount_of_timestamps = 0
    user_request = False
    mappers1 = []
    mappers2 = []
    f = open("mapper_icon1.txt", "r")
    for line in f:
        mappers1.append(line.replace("\n", ""))
    f.close()
    f = open("mapper_icon2.txt", "r")
    for line in f:
        mappers2.append(line.replace("\n", ""))
    f.close()
    if Global == False:
        try:
            if difficulty == "all" or difficulty == "expert":
                max_score = calculate_stars(song, "expert", 0)[1]
            elif difficulty == "advanced":
                max_score = calculate_stars(song, "advanced", 0)[1]
            elif difficulty == "moderate":
                max_score = calculate_stars(song, "moderate", 0)[1]
            elif difficulty == "beginner":
                max_score = calculate_stars(song, "beginner", 0)[1]
        except Exception as e:
            #print(e)
            for custom in api.customs:
                if song.lower() in custom[0].lower():
                    song = custom[0]
            if difficulty == "all":
                try:
                    max_score = calculate_stars(song, "expert", 0,
                                                custom=True)[1]
                except:
                    try:
                        max_score = calculate_stars(song,
                                                    "advanced",
                                                    0,
                                                    custom=True)[1]
                    except:
                        try:
                            max_score = calculate_stars(song,
                                                        "moderate",
                                                        0,
                                                        custom=True)[1]
                        except:
                            try:
                                max_score = calculate_stars(song,
                                                            "beginner",
                                                            0,
                                                            custom=True)[1]
                            except:
                                max_score = 0
            elif difficulty == "expert":
                max_score = calculate_stars(song, "expert", 0, custom=True)[1]
            elif difficulty == "advanced":
                max_score = calculate_stars(song, "advanced", 0,
                                            custom=True)[1]
            elif difficulty == "moderate":
                max_score = calculate_stars(song, "moderate", 0,
                                            custom=True)[1]
            elif difficulty == "beginner":
                max_score = calculate_stars(song, "beginner", 0,
                                            custom=True)[1]
    else:
        for song in ost:
            max_score = max_score + calculate_stars(song, "expert", 0)[1]
    codes = friend_codes()
    codes.load()
    for item in scores:
        if Global == False:
            try:
                stars = calculate_stars(song, item["difficulty"],
                                        int(item["score"]))
            except:
                stars = calculate_stars(song,
                                        item["difficulty"],
                                        int(item["score"]),
                                        custom=True)
            if item["difficulty"] == "expert":
                if stars[0] == 6:
                    stars_emoji = gs_emoji
                    stars[0] = 5
                else:
                    stars_emoji = expert_emoji
            elif item["difficulty"] == "advanced":
                stars_emoji = advanced_emoji
            elif item["difficulty"] == "moderate":
                stars_emoji = standard_emoji
            elif item["difficulty"] == "beginner":
                stars_emoji = beginner_emoji
        code = codes.get_code(sender.id)
        if code != None:
            platform_id = code
        if platform_id != "":
            if item["platform_id"] == platform_id:
                ranks_string = ranks_string + "**"
                users_string = users_string + "**"
                all_scores_string = all_scores_string + "**"
        elif item["user"] == sender.display_name:
            ranks_string = ranks_string + "**"
            users_string = users_string + "**"
            all_scores_string = all_scores_string + "**"
        if Global == False:
            stars_string = "`" + str(stars[0]) + "x`" + stars_emoji + " "
        if item["platform"] == "steam":
            emoji = steam_logo_2_emoji
        elif item["platform"] == "oculus":
            emoji = oculus_logo_emoji
        elif item["platform"] == "viveport":
            emoji = viveport_logo_emoji
        elif item["platform"] == "psn":
            emoji = psvr_logo_emoji
        if len(str(item["rank"])) == 1:
            ranks_string = ranks_string + emoji + "`0" + str(
                item["rank"]) + "`"
        else:
            ranks_string = ranks_string + emoji + "`" + str(item["rank"]) + "`"
        if item["developer"] == True:
            ranks_string = ranks_string + " " + hmx_logo_emoji
        if item["platform_id"] in mappers1:
            ranks_string = ranks_string + " " + mapper1_emoji
        elif item["platform_id"] in mappers2:
            ranks_string = ranks_string + " " + mapper2_emoji
        if len(item["user"]) > max_user_characters:
            user = "******" + item["user"][0:max_user_characters] + "...`"
        else:
            user = "******" + item["user"] + "`"
        if Global == False:
            if item["full_combo"] == True:
                if item["user"] == sender.display_name:
                    user = fc_glow_emoji + " " + user
                else:
                    user = fc_emoji + " " + user
            elif item["percent"] == 100.0:
                user = hundread_emoji + " " + user
            else:
                user = blank_emoji + " " + user
        else:
            user = blank_emoji + " " + user
        ranks_string = ranks_string + "\n"
        users_string = users_string + user + "\n"
        if Global == False:
            all_scores_string = all_scores_string + stars_string + locale.format_string(
                "%d", int(item["score"]), grouping=True) + "\n"
        else:
            all_scores_string = all_scores_string + blank_emoji + "`" + locale.format_string(
                "%d", int(item["score"]), grouping=True) + "`\n"

        if platform_id != "":
            if item["platform_id"] == platform_id:
                ranks_string = ranks_string + "**"
                users_string = users_string + "**"
                all_scores_string = all_scores_string + "**"
        elif item["user"] == sender.display_name:
            ranks_string = ranks_string + "**"
            users_string = users_string + "**"
            all_scores_string = all_scores_string + "**"
        try:
            song_names.append(item["song"])
            user_request = True
        except:
            user_request = False
        if top20 == False and Global == False:
            sum_of_timestamps = sum_of_timestamps + item["timestamp"]
            ammount_of_timestamps = ammount_of_timestamps + 1
    if user_request == False:
        if Global == True:
            song = "global"
        desc = "Request for \"" + song + "\"\nMax possible score: " + locale.format_string(
            "%d", int(max_score), grouping=True)
    else:
        desc = "Request for \"" + song + "\""
    if top20 == False:
        timestamps_average = sum_of_timestamps / ammount_of_timestamps
        utc_timestamp_average = datetime.datetime.fromtimestamp(
            timestamps_average + 10800)
        embed = discord.Embed(title=audica_logo_emoji + " Audica Leaderboards",
                              description=desc,
                              timestamp=utc_timestamp_average)
        embed.set_footer(text="Average update time")
    else:
        embed = discord.Embed(title=audica_logo_emoji + " Audica Leaderboards",
                              description=desc)
    embed.set_author(name=sender.display_name, icon_url=sender.avatar_url)
    if Global == False:
        embed.add_field(name="Rank", value=ranks_string, inline=True)
        embed.add_field(name="User", value=users_string, inline=True)
        embed.add_field(name="Score", value=all_scores_string, inline=True)
    else:
        embed.add_field(name="Rank " + blank_emoji,
                        value=ranks_string,
                        inline=True)
        embed.add_field(name=blank_emoji + " User",
                        value=users_string,
                        inline=True)
        embed.add_field(name=blank_emoji + " Score",
                        value=all_scores_string,
                        inline=True)
    return embed
Esempio n. 5
0
 async def do_work():
     await ctx.channel.trigger_typing()
     sender = ctx.message.author
     message_logger("COMMAND",
                    ".compare command requested by " + sender.display_name)
     users = user_list()
     codes = friend_codes()
     users.load()
     codes.load()
     user1 = codes.get_code(sender.id)
     user2 = None
     if user1 == None:
         message_logger("COMMAND",
                        "Help message sent, error with arguments")
         for channel in ctx.guild.channels:
             if str(channel) == "audica-friend-codes":
                 m = await ctx.send(
                     content=
                     "Friend code not found. To link your friend code post it in "
                     + channel.mention + ".")
     else:
         if "<audica_friend_code" in args[0]:
             if " " in args[0]:
                 user2 = args[0].replace("<audica_friend_code ",
                                         "").replace(">", "")
             else:
                 user2 = args[1].replace(">", "")
         elif "steam" in args[0] or "viveport" in args[
                 0] or "oculus" in args[0]:
             user2 = args[0]
         else:
             for user in users.users["users"]:
                 if args[0] == user["name"]:
                     user2 = user["platform_id"]
                     break
             if user2 == None:
                 for user in users.users["users"]:
                     if args[0].lower() == user["name"].lower():
                         user2 = user["platform_id"]
                         break
             if user2 == None:
                 for user in users.users["users"]:
                     if args[0] in user["name"]:
                         user2 = user["platform_id"]
                         break
             if user2 == None:
                 for user in users.users["users"]:
                     if args[0].lower() in user["name"].lower():
                         user2 = user["platform_id"]
                         break
         if user2 == None:
             m = await ctx.send(
                 content=
                 "User to compare with not found. This command needs either a part or the totality of the in-game name, the friend code or the platform id of the player to compare with."
             )
         else:
             try:
                 request = api.post_request(api.global_songs,
                                            [user1, user2])
                 pages = []
                 page = []
                 all_songs = []
                 count = 0
                 ammount = 0
                 for i in request["leaderboard"]:
                     if i["data"] != []:
                         ammount = ammount + 1
                 for p in request["leaderboard"]:
                     if p["data"] != []:
                         page.append(p)
                         count = count + 1
                         if count == 20 or count == 40 or count == ammount:
                             pages.append(page)
                             page = []
                 m = None
                 for page in pages:
                     #print(page)
                     m = await ctx.send(embed=make_compare_embed(
                         page, user1, user2, users.get_name(user1),
                         users.get_name(user2), sender, api))
             except:
                 m = await ctx.send(
                     content="Unexpected error with the command.")
     client.loop.create_task(cooldown_reaction(m, compare_command_cooldown))