Пример #1
0
async def play_queue(message):
    """
    replace current queue with a specified custom queue from the guild_data.json file
    """
    guild_id = str(message.guild.id)
    guild_data = data.get_guild_data(guild_id)

    try:
        queue_to_play = " ".join(message.content.split(" ")[3:])
    except IndexError:
        await message.channel.send(embed=verbose.embeds.embed_warning_message(
            "You must specify a queue to play."))
        return

    if queue_to_play not in guild_data["saved_queues"]:
        await message.channel.send(embed=verbose.embeds.embed_warning_message(
            "That queue does not exist."))
        return

    guild_vc_data[guild_id]["guild_queue"] = [
        dict_to_song(song_dict)
        for song_dict in guild_data["saved_queues"][queue_to_play]
    ]

    try:
        guild_vc_data[guild_id]["voice_client"].stop()
    except AttributeError:
        await message.channel.send(embed=verbose.embeds.embed_response(
            "Queue set.",
            f"Type `{COMMAND_PREFIX} vc join` to start listening."))
        return

    await play_from_yt(message)
Пример #2
0
async def setup_flashcard_use(message):
    guild_id = str(message.guild.id)

    try:
        flashcard_set_to_use = message.content.split()[3]
    except IndexError:
        await message.channel.send(embed=verbose.embeds.embed_warning_message("You must specify a flashcard set to use."))
        return

    flashcard_sets = data.get_guild_data(guild_id)["flashcard_sets"]

    if flashcard_set_to_use not in flashcard_sets.keys():
        await message.channel.send(embed=verbose.embeds.embed_sorry_message("That flashcard set does not exist. Please check spelling and try again."))
        return

    if flashcard_data[guild_id]["flashcard_creation_in_progress"]:
        await active_flashcard_sets[guild_id]["message"].clear_reactions()

    active_flashcard_sets[guild_id] = {
        "name_of_set": flashcard_set_to_use,
        "active_set": flashcard_sets[flashcard_set_to_use],
        "message": await message.channel.send(embed=flashcard_embed(flashcard_set_to_use, flashcard_sets[flashcard_set_to_use], 0, "front")),
        "index": 0,
        "current_side": "front"
    }

    for emoji in emoji_list:
        await active_flashcard_sets[guild_id]["message"].add_reaction(emoji)
Пример #3
0
async def edit(guild_id, message, old_keyword, new_keyword):
    guild_data = data.get_guild_data(guild_id)
    guild_data["keywords"][new_keyword] = guild_data["keywords"].pop(
        old_keyword)
    await message.channel.send(embed=verbose.embeds.embed_successful_action("Keyword edited. "))

    data.set_guild_data(guild_id, guild_data)
Пример #4
0
async def send_queue_list(message):
    """
    send a list of saved queues in the user's guild
    """
    guild_id = str(message.guild.id)
    guild_data = data.get_guild_data(guild_id)

    desc = ""

    for queue_name in guild_data["saved_queues"]:
        raw_queue_duration = 0
        for song in guild_data['saved_queues'][queue_name]:
            raw_queue_duration += song["duration"]

        total_time_mins = raw_queue_duration // 60
        time_secs = raw_queue_duration % 60
        time_hours = total_time_mins // 60
        time_mins = total_time_mins % 60

        queue_duration = f"{time_hours}h {time_mins}m {time_secs}s" if time_hours != 0 else f"{time_mins}m {time_secs}s"

        desc += f"• `{queue_name}` - {len(guild_data['saved_queues'][queue_name])} songs | {queue_duration}\n"

    if desc == "":
        await message.channel.send(
            embed=verbose.embeds.embed_response_without_title(
                "You don't currently have any saved queues."))
    else:
        await message.channel.send(
            embed=verbose.embeds.embed_response("Saved queues:", desc))
Пример #5
0
async def remove_flashcard_set(message):
    if not message.author.guild_permissions.administrator:
        await message.channel.send(embed=verbose.embeds.embed_warning_message("Sorry, you must be an administrator in this server to use that command."))
        return

    guild_id = str(message.guild.id)

    name_of_flashcard_set_to_remove = message.content.split()[3]
    flashcard_sets = data.get_guild_data(guild_id)["flashcard_sets"]

    if name_of_flashcard_set_to_remove not in flashcard_sets.keys():
        await message.channel.send(embed=verbose.embeds.embed_sorry_message("That flashcard set does not exist. Please check spelling and try again."))
        return

    guild_data = data.get_guild_data(guild_id)
    guild_data["flashcard_sets"].pop(name_of_flashcard_set_to_remove)
    data.set_guild_data(guild_id, guild_data)

    await message.channel.send(embed=verbose.embeds.embed_successful_action(f"Flashcard set `{name_of_flashcard_set_to_remove}` deleted."))
Пример #6
0
async def remove(guild_id, message, message_removal):
    guild_data = data.get_guild_data(guild_id)
    try:
        guild_data["keywords"].pop(message_removal)
    except KeyError:
        await message.channel.send(embed=verbose.embeds.embed_warning_message("That keyword does not exist."))
    else:
        await message.channel.send(embed=verbose.embeds.embed_successful_action("Keyword removed. "))

    data.set_guild_data(guild_id, guild_data)
Пример #7
0
async def add(guild_id, message, keyword, value):
    guild_data = data.get_guild_data(guild_id)
    if value == "":
        await message.channel.send(embed=verbose.embeds.embed_warning_message("No value specified. "))
    else:
        if keyword in guild_data["keywords"]:
            guild_data["keywords"][keyword].append(value)
        else:
            guild_data["keywords"][keyword] = [value]
        await message.channel.send(embed=verbose.embeds.embed_successful_action("Keyword added. "))
    data.set_guild_data(guild_id, guild_data)
Пример #8
0
async def send_flashcard_set_list(message):
    guild_id = str(message.guild.id)

    flashcard_sets = data.get_guild_data(guild_id)["flashcard_sets"]
    total_desc = ""
    for flashcard_set in flashcard_sets:
        total_desc += f"`{flashcard_set}` - {len(flashcard_sets[flashcard_set])} terms\n"
    if total_desc == "":
        await message.channel.send(embed=verbose.embeds.embed_response_without_title("You do not have any saved flashcard sets."))
        return
    
    await message.channel.send(embed=verbose.embeds.embed_response("Saved flashcard sets:", total_desc))
Пример #9
0
async def edit_flashcard_set(message):
    guild_id = str(message.guild.id)

    name_of_flashcard_set_to_edit = message.content.split()[3]
    flashcard_sets = data.get_guild_data(guild_id)["flashcard_sets"]

    if name_of_flashcard_set_to_edit not in flashcard_sets.keys():
        await message.channel.send(embed=verbose.embeds.embed_sorry_message("That flashcard set does not exist. Please check spelling and try again."))
        return

    index_to_edit = int(message.content.split()[4]) - 1
    new_front, _, new_back = message.content.split('"')[1:4]
    edited_flashcard_set = flashcard_sets[name_of_flashcard_set_to_edit]
    flashcard_front_to_replace = list(flashcard_sets[name_of_flashcard_set_to_edit])[index_to_edit]

    edited_flashcard_set[new_front] = edited_flashcard_set.pop(flashcard_front_to_replace)
    edited_flashcard_set[new_front] = new_back

    guild_data = data.get_guild_data(guild_id)
    guild_data["flashcard_sets"][name_of_flashcard_set_to_edit] = edited_flashcard_set
    data.set_guild_data(guild_id, guild_data)

    message.channel.send(embed=verbose.embeds.embed_successful_action("Flashcard set edited."))
Пример #10
0
async def list_keywords(guild_id, message):
    guild_data = data.get_guild_data(guild_id)
    keywords_list = ""
    for keyword in guild_data["keywords"]:
        keyword_values_str = ""
        for value in guild_data['keywords'][keyword]:
            keyword_values_str += value + ", "
        keyword_values_str = keyword_values_str.strip(", ")
        keywords_list += f"• `{keyword} - {keyword_values_str}`\n"

    if keywords_list == "":
        await message.channel.send(embed=verbose.embeds.embed_response("No keywords set.", "Nothing to display."))
    else:
        await message.channel.send(embed=verbose.embeds.embed_response("Keywords:", f"{keywords_list}"))
Пример #11
0
async def end_flashcard_creation(message):
    guild_id = str(message.guild.id)

    if not flashcard_data[guild_id]["flashcard_creation_in_progress"]:
        await message.channel.send(embed=verbose.embeds.embed_warning_message("You cannot end creation if no creation has started."))

    if message.author != flashcard_data[guild_id]["user"]:
        await message.channel.send(embed=verbose.embeds.embed_sorry_message("Only the flashcard set creator can end creation."))
        return

    flashcard_set_name = flashcard_data[guild_id]["current_flashcard_set_name"]
    guild_data = data.get_guild_data(guild_id)
    guild_data["flashcard_sets"][flashcard_set_name] = flashcard_data[guild_id]["current_flashcard_set"].copy()
    data.set_guild_data(guild_id, guild_data)

    await message.channel.send(embed=verbose.embeds.embed_successful_action(f"Your flashcard set `{flashcard_set_name}` has been saved."))

    # reset guild flashcard data 
    flashcard_data[guild_id] = DEFAULT_GUILD_FLASHCARD_DATA.copy()
Пример #12
0
async def save_queue(message):
    """
    save current queue as a preset with a name of the user's choice
    """
    guild_id = str(message.guild.id)

    if len(guild_vc_data[guild_id]["guild_queue"]) < 1:
        await message.channel.send(embed=verbose.embeds.embed_sorry_message(
            "Your current queue is empty."))
        return

    queue_to_save = [
        song_to_dict(song) for song in guild_vc_data[guild_id]["guild_queue"]
    ]

    queue_name = " ".join(message.content.split(" ")[3:])
    guild_data = data.get_guild_data(guild_id)
    guild_data["saved_queues"][queue_name] = queue_to_save
    data.set_guild_data(guild_id, guild_data)

    await message.channel.send(embed=verbose.embeds.embed_successful_action(
        f"Saved current queue preset as `{queue_name}`"))
Пример #13
0
async def send_queue(message):
    """
    sends songs from a specified queue, or the current queue if no queue is specified
    """
    guild_id = str(message.guild.id)

    specific_queue_name = " ".join(message.content.split(" ")[3:])

    if len(specific_queue_name) > 0:  # if queue specified
        guild_data = data.get_guild_data(guild_id)

        if specific_queue_name not in guild_data["saved_queues"]:
            await message.channel.send(
                embed=verbose.embeds.embed_warning_message(
                    "That queue does not exist."))
            return

        # load the queue of dicts and parse into Songs
        queue_to_send = [
            dict_to_song(song_dict)
            for song_dict in guild_data["saved_queues"][specific_queue_name]
        ]

    else:
        specific_queue_name = None
        queue_to_send = guild_vc_data[guild_id]["guild_queue"]

    queue_message = QueueMessage(message,
                                 queue=queue_to_send,
                                 queue_name=specific_queue_name)

    await queue_message.send()

    if guild_vc_data[guild_id]["active_queue_message"] is not None:
        await guild_vc_data[guild_id]["active_queue_message"].clear_reactions()
    guild_vc_data[guild_id]["active_queue_message"] = queue_message
Пример #14
0
async def check_keywords(guild_id, message):
    guild_data = data.get_guild_data(guild_id)
    for keyword in guild_data["keywords"].keys():
        if message.content.__contains__(keyword):
            await message.channel.send(guild_data["keywords"][keyword][random.randint(0, len(guild_data["keywords"][keyword])-1)])
            return