import pickle


def get_challenges_for_user_id(database, user_id, ctf_channel_id):
    """
    Fetch a list of all challenges a user is working on for a given CTF.
    Return a list of matching Challenge objects.
    """

    ctfs = pickle.load(open(database, "rb"))
    ctf = ctfs[ctf_channel_id]

    challenges = []
    for challenge in ctf.challenges:
        if user_id in challenge.players:
            challenges.append(challenge)

    return challenges