示例#1
0
 async def do_work():
     await ctx.channel.trigger_typing()
     sender = ctx.message.author
     message_logger(
         "COMMAND",
         ".edit_leaderboard command requested by " + sender.display_name)
     filename = args[0] + ".audica"
     leaderboard_id = args[1]
     database = customs_database()
     database.load()
     song = database.get_song_with_filename(filename)
     song_filename = song["filename"].replace(".audica", "")
     if song == False:
         m = await ctx.send(
             content="Could not find the song_id in the database.")
     else:
         try:
             hash = leaderboard_id.replace(song_filename + "_", "")
         except:
             hash = leaderboard_id
         if len(hash) != 32:
             m = await ctx.send(content="Invalid leaderboard hash.")
         else:
             if len(leaderboard_id) == 32:
                 leaderboard_id = song_filename + "_" + hash
             database.edit_leaderboard_id(song_filename, leaderboard_id)
             database.save()
             m = await ctx.send(
                 content="Song with ID \"" + song_filename +
                 "\" was successfully edited with the leaderboard hash \"" +
                 hash + "\".")
     client.loop.create_task(cooldown_reaction(m,
                                               edit_leaderboard_cooldown))
示例#2
0
async def delete_song(ctx, *args):
    user_id = ctx.author.id
    sender = ctx.message.author
    database = customs_database()
    database.load()
    found = False
    message_logger("COMMAND",
                   ".delete_song command requested by " + sender.display_name)
    for song in database.song_list:
        if song["filename"] == args[0] or song["song_id"] == args[0]:
            found = True
            if user_id == song["uploader"] or await client.is_owner(ctx.author
                                                                    ):
                database.delete(song["song_id"])
                database.save()
                os.remove(audica_custom_songs_folder + os.sep +
                          song["filename"])
                await ctx.send(content="`" + song["song_id"] +
                               "` successfully deleted.")
                message_logger("COMMAND", song["song_id"] + "deleted.")
            else:
                await ctx.send(
                    content="You do not have permission to delete `" +
                    song["song_id"] + "`.")
                message_logger("COMMAND",
                               "Does not have permission to delete.")
            break
    if found == False:
        await ctx.send(
            content="Did not find a song with `" + args[0] +
            "` as either song_id or filename. Please specify the exact filename or song_id of the song to delete."
        )
        message_logger("COMMAND", "Song not found.")
示例#3
0
async def wipeleaderboardids(ctx):
    if await client.is_owner(ctx.message.author):
        database = customs_database()
        database.load()
        database.wipe_leaderboard_ids()
        database.save()
        await ctx.send(content="Wiped all leaderboard IDs for custom songs.")
示例#4
0
 def load_custom_songs(self):
     self.customs = []
     database = customs_database()
     database.load()
     for song in database.song_list:
         self.customs.append([
             song["filename"].replace(".audica", ""), song["leaderboard_id"]
         ])
示例#5
0
 async def do_work():
     await ctx.channel.trigger_typing()
     sender = ctx.message.author
     message_logger(
         "COMMAND", ".missing_leaderboards command requested by " +
         sender.display_name)
     database = customs_database()
     database.load()
     songs = []
     for song in database.song_list:
         if song["leaderboard_id"] == "":
             songs.append(song["filename"].replace(".audica", ""))
     message_string = "Filename of songs with missing leaderboard ID:\n\n"
     for song in songs:
         message_string = message_string + song + "\n"
     m = await ctx.send(content=message_string)
     client.loop.create_task(cooldown_reaction(m,
                                               edit_leaderboard_cooldown))
示例#6
0
async def process_custom_song(message):
    database = customs_database()
    database.load()
    for attachment in message.attachments:
        if str(attachment.url)[-7:] == ".audica":
            filename = str(attachment.url).split(os.sep)[-1]
            file_path = audica_custom_songs_folder + os.sep + filename
            try:
                found = False
                for song in database.song_list:
                    if song["filename"] == filename:
                        found = True
                if found == False:
                    if os.path.isfile(file_path) == False:
                        message_logger("CUSTOMS DATABASE",
                                       "Downloading " + filename + "...")
                        await attachment.save(file_path)
                        message_logger("CUSTOMS DATABASE",
                                       "Download finished!")
                        song = custom_song(file_path)
                        song.filename = filename
                        song.uploader = message.author.id
                        song.download_url = str(attachment.url)
                        song.upload_time = str(message.created_at)
                        m = message.content
                        if "\n" in m:
                            for line in m.split("\n"):
                                if "video:" in line.lower():
                                    song.video_url = line.split(
                                        "o:")[-1].replace(" ", "")
                                if song.desc_file.author == "" and "mapper:" in line.lower(
                                ):
                                    song.desc_file.author = line.split(
                                        ":")[-1].replace(" ", "")
                                if "leaderboard:" in line.lower():
                                    song.leaderboard_id = line.split(
                                        ":")[-1].replace(" ", "")
                        else:
                            if "video:" in m.lower():
                                song.video_url = m.split("o:")[-1].replace(
                                    " ", "")
                            if song.desc_file.author == "" and "mapper:" in m.lower(
                            ):
                                song.desc_file.author = m.split(
                                    ":")[-1].replace(" ", "")
                            if "leaderboard:" in m.lower():
                                song.leaderboard_id = m.split(":")[-1].replace(
                                    " ", "")
                        if database.add(song.get_song_data()) == False:
                            await message.author.send(
                                content="A file named \"" + filename +
                                "\" already exists in the database. The song was not added to the database."
                            )
                            os.remove(file_path)
                            await message.add_reaction(rejected_emoji)
                        database.save()
                        message_logger(
                            "CUSTOMS DATABASE",
                            "Added \"" + song.desc_file.artist + " - " +
                            song.desc_file.title + "\" authored by \"" +
                            song.desc_file.author + "\"")
                        await message.add_reaction(approved_emoji)
                    else:
                        await message.author.send(
                            content="A file named \"" + filename +
                            "\" already exists in the database. The song was not added to the database."
                        )
                        await message.add_reaction(rejected_emoji)
                else:
                    await message.author.send(
                        content="A file named \"" + filename +
                        "\" already exists in the database. The song was not added to the database."
                    )
                    await message.add_reaction(rejected_emoji)
            except Exception as e:
                os.remove(file_path)
                await message.author.send(
                    content="There was a problem processing the file \"" +
                    filename + "\".")
                await message.add_reaction(rejected_emoji)
                print(e)
        else:
            await message.author.send(
                content=
                "This channel is exclusively reserved to post audica files of finished songs."
            )
            await message.add_reaction(rejected_emoji)
示例#7
0
async def process_play_history_or_log(message):
    for attachment in message.attachments:
        id_list = []
        ids_edited = []
        ids_unknown = []
        if "play_history.json" in str(attachment.url):
            filename = str(attachment.url).split(os.sep)[-1]
            message_logger("CUSTOMS DATABASE",
                           "Downloading " + filename + "...")
            await attachment.save(filename)
            message_logger("CUSTOMS DATABASE", "Download finished!")
            f = open(filename, "r")
            fjson = json.load(f)
            f.close()
            os.remove(filename)
            for item in fjson["songs"]:
                id = item["songID"]
                newest_play = 0
                for history in item["history"]:
                    if history["date"] >= 637085800000000000:
                        if history["date"] > newest_play:
                            newest_play = history["date"]
                id_list.append([id, newest_play])
            id_list_copy = id_list
            new_id_list = []
            for item in id_list:
                newest_play = 0
                id = ""
                for i in id_list_copy:
                    if item[0][:-33] == i[0][:-33]:
                        t = int(str(i[1] - 621357696000000000)[:-7])
                        if t > newest_play:
                            newest_play = t
                            id = i[0]
                new_data = [id, newest_play]
                if new_data not in new_id_list:
                    if new_data[0][:-33] != "":
                        new_id_list.append(new_data)
            id_list = new_id_list
        elif "output_log.txt" in str(attachment.url):
            filename = str(attachment.url).split(os.sep)[-1]
            message_logger("CUSTOMS DATABASE",
                           "Downloading " + filename + "...")
            await attachment.save(filename)
            message_logger("CUSTOMS DATABASE", "Download finished!")
            lines = []
            f = open(filename, "r")
            for line in f:
                lines.append(line)
            f.close()
            os.remove(filename)
            for line in lines:
                if "Requesting leaderboard for " in line:
                    id = line.replace("Requesting leaderboard for ",
                                      "").replace("\n", "")
                    if id[:-33] != "":
                        id_found = False
                        for i in id_list:
                            if id == i[0]:
                                id_found = True
                                break
                        if id_found == False:
                            id_list.append([id, time.time()])
        if id_list != []:
            unknown_ids = []
            database = customs_database()
            database.load()
            unknown_database = unknown_leaderboard_ids()
            unknown_database.load()
            for id in id_list:
                song_found = False
                for song in database.song_list:
                    song_id = song["filename"].replace(".audica", "")
                    leaderboard_id = song["leaderboard_id"]
                    if song_id == id[0][:-33]:
                        song_found = True
                        if leaderboard_id == "":
                            database.edit_leaderboard_id(
                                song["song_id"], id[0])
                            ids_edited.append(id[0])
                        break
                if song_found == False:
                    id_found = False
                    for item in unknown_database.leaderboard_ids:
                        if item["leaderboard_id"] == id[0]:
                            id_found = True
                            break
                    if id_found == False:
                        unknown_database.add(id[0], id[1])
                        ids_unknown.append(id[0])
            database.save()
            unknown_database.save()
        message_string = ""
        if ids_edited != []:
            message_string = "Songs that needed an ID from the file provided:\n\n"
            for item in ids_edited:
                message_string = message_string + item + "\n"
            message_string = message_string + "\n"
        if ids_unknown != []:
            message_string = message_string + "IDs that are unknown (songs not in database) that were saved for future use:\n\n"
            for item in ids_unknown:
                message_string = message_string + item + "\n"
        if message_string != "":
            await message.channel.send(content=message_string)
        else:
            if "play_history.json" in str(attachment.url):
                await message.channel.send(
                    content="This file does not contain new IDs.")
            if "output_log.txt" in str(attachment.url):
                await message.channel.send(
                    content="This file does not contain new IDs.")