Exemplo n.º 1
0
async def play(message: discord.Message, song: Annotate.CleanContent):
    """ Play a song. The given song could either be a URL or keywords
    to lookup videos in youtube. """
    assert_connected(message.author)
    state = voice_states[message.server]

    # Check that the member hasn't already requested enough songs
    songs_queued = sum(1 for s in state.queue if s.requester == message.author)
    assert songs_queued < max_songs_queued, "**You have queued enough songs for now.**"

    # Strip any embed characters, spaces or code symbols.
    song = song.strip("< >`")

    try:
        player = await state.voice.create_ytdl_player(
            song, ytdl_options=youtube_dl_options, after=state.play_next)
    except:
        await client.say(message, "**Could not add this song to the queue.**")
        print_exc()
        return

    # Make sure the song isn't too long
    if player.duration:
        assert player.duration < max_song_length, "**The requested song is too long.**"

    player.volume = state.volume
    song = Song(player=player,
                requester=message.author,
                channel=message.channel)
    await client.send_message(song.channel, "Queued: " + format_song(song))
    state.queue.append(song)

    # Start the song when there are none
    if not state.is_playing():
        state.play_next()
Exemplo n.º 2
0
async def play(message: discord.Message, song: Annotate.CleanContent):
    """ Play a song. The given song could either be a URL or keywords
    to lookup videos in youtube. """
    assert_connected(message.author)
    state = voice_states[message.server]

    # Check that the member hasn't already requested enough songs
    songs_queued = sum(1 for s in state.queue if s.requester == message.author)
    assert songs_queued < max_songs_queued, "**You have queued enough songs for now.**"

    # Strip any embed characters, spaces or code symbols.
    song = song.strip("< >`")

    try:
        player = await state.voice.create_ytdl_player(song, ytdl_options=youtube_dl_options, after=state.play_next)
    except:
        await client.say(message, "**Could not add this song to the queue.**")
        print_exc()
        return

    # Make sure the song isn't too long
    if player.duration:
        assert player.duration < max_song_length, "**The requested song is too long.**"

    player.volume = state.volume
    song = Song(player=player, requester=message.author, channel=message.channel)
    await client.send_message(song.channel, "Queued: " + format_song(song))
    state.queue.append(song)

    # Start the song when there are none
    if not state.is_playing():
        state.play_next()
Exemplo n.º 3
0
async def synonym(message: discord.Message, phrase: Annotate.CleanContent):
    phrase = phrase.lower()

    if phrase not in synonyms:
        matches = get_close_matches(phrase, synonyms.keys(), n=5, cutoff=0.6)
        await client.say(
            message, "Found no synonym for {}. Did you mean {}".format(
                phrase, ", ".join("`" + match + "`" for match in matches)))
        return

    await client.say(message,
                     ", ".join(s.strip(" \n") for s in synonyms[phrase]))
Exemplo n.º 4
0
async def new(message: discord.Message, plugin: plugin_in_req, content: Annotate.CleanContent):
    """ Add a new feature request to a plugin.
    See `{pre}plugin` for a list of plugins. """
    req_list = feature_reqs.data[plugin]
    content = content.replace("\n", " ")

    assert content not in req_list, "This feature has already been requested!"

    # Add the feature request if an identical request does not exist
    feature_reqs.data[plugin].append(content)
    feature_reqs.save()
    await client.say(message, "Feature saved as `{0}` id **#{1}**.".format(plugin, len(req_list)))
Exemplo n.º 5
0
async def play(message: discord.Message, song: Annotate.CleanContent):
    """ Play a song. The given song could either be a URL or keywords
    to lookup videos in youtube. """
    assert_connected(message.author)
    state = voice_states[message.server]

    # Check that the member hasn't already requested enough songs
    songs_queued = sum(1 for s in state.queue if s.requester == message.author)
    assert songs_queued < max_songs_queued, "**You have queued enough songs for now.**"

    # Strip any embed characters, spaces or code symbols.
    song = song.strip("< >`")

    try:
        player = await state.voice.create_ytdl_player(
            song,
            ytdl_options=youtube_dl_options,
            after=state.play_next,
            before_options=ffmpeg_before_options)
    except:
        await client.say(message, "**Could not add this song to the queue.**")
        print_exc()
        return

    # Make sure the song isn't too long
    if player.duration:
        assert player.duration < max_song_length, "**The requested song is too long.**"

    url_match = utils.http_url_pattern.match(song)
    if url_match and player.title == url_match.group("sub"):
        # Try retrieving the filename as this is probably a file
        headers = await utils.retrieve_headers(song)
        if "Content-Disposition" in headers:
            name_match = disposition_pattern.search(
                headers["Content-Disposition"])
            if name_match:
                player.title = "".join(
                    name_match.group("name").split(".")[:-1])

    player.volume = state.volume
    song = Song(player=player,
                requester=message.author,
                channel=message.channel)
    await client.send_message(song.channel, "Queued: " + format_song(song))
    state.queue.append(song)

    # Start the song when there are none
    if not state.is_playing():
        state.play_next()
Exemplo n.º 6
0
async def new(message: discord.Message, plugin: plugin_in_req,
              content: Annotate.CleanContent):
    """ Add a new feature request to a plugin.
    See `{pre}plugin` for a list of plugins. """
    req_list = feature_reqs.data[plugin]
    content = content.replace("\n", " ")

    assert content not in req_list, "This feature has already been requested!"

    # Add the feature request if an identical request does not exist
    feature_reqs.data[plugin].append(content)
    feature_reqs.save()
    await client.say(
        message,
        "Feature saved as `{0}` id **#{1}**.".format(plugin, len(req_list)))
Exemplo n.º 7
0
async def getTagged(message: discord.Message, text: Annotate.CleanContent):
    global tagName
    retv = ""
    listv = []
    i = 0
    for item in tagName:
        if text.lower() == item[1].lower():
            listv.append(item[0])
    for item in listv:
        retv += item
        if i + 1 is not len(listv):
            retv += ", "
        i += 1
    if retv is "":
        return
    await client.say(message, "Tagged " + text + ": " + retv)
Exemplo n.º 8
0
async def prank(message: discord.Message, phrase: Annotate.CleanContent="IT'S A"):
    """ Prank! """
    phrase = phrase.upper()

    # Initialize the image and font
    image_text = Image.new("RGBA", image_base.size, (255, 255, 255, 0))
    image_font = ImageFont.truetype(prank_path + "American Captain.ttf", 50)
    image_context = ImageDraw.Draw(image_text)

    # Set width and height and scale down when necessary
    width, height = image_context.textsize(phrase, image_font)
    font_size = 50

    if width > image_width:
        scaled_font = None

        while width > image_width:
            scaled_font = ImageFont.truetype(prank_path + "American Captain.ttf", font_size)
            width, height = image_context.textsize(phrase, scaled_font)
            font_size -= 1

        image_font = scaled_font

    # Set x and y coordinates for centered text
    x = (image_width - width) / 2
    y = (image_height - height / 2) - image_height / 1.3

    # Draw border
    shadow_offset = font_size // 25
    image_context.text((x - shadow_offset, y), phrase, font=image_font, fill=(0, 0, 0, 255))
    image_context.text((x + shadow_offset, y), phrase, font=image_font, fill=(0, 0, 0, 255))
    image_context.text((x, y - shadow_offset), phrase, font=image_font, fill=(0, 0, 0, 255))
    image_context.text((x, y + shadow_offset), phrase, font=image_font, fill=(0, 0, 0, 255))

    # Draw text
    image_context.text((x, y), phrase, font=image_font, fill=(255, 255, 255, 255))

    # Combine the base image with the font image
    image = Image.alpha_composite(image_base, image_text)

    # Upload the image
    buffer = BytesIO()
    image.save(buffer, "PNG")
    buffer.seek(0)
    await client.send_file(message.channel, buffer, filename="pranked.png")
Exemplo n.º 9
0
async def gif(message: discord.Message, text: Annotate.CleanContent):
    """ Gives a **huge** version of emojies AS A GIF. """
    images, total_width, height = await convert_to_images(text)

    # Get optional duration
    duration = 0.15

    duration_arg = text.split(" ")[-1]
    if re.match(r"[0-9.]+", duration_arg):
        duration = float(duration_arg) / 10

    frames = []
    for image in images:
        frame_bytes = utils.convert_image_object(image, format="PNG")
        frames.append(imageio.imread(frame_bytes))

    # Make a gif
    image_bytes = imageio.mimwrite(imageio.RETURN_BYTES,
                                   frames,
                                   format="GIF",
                                   duration=duration)
    await client.send_file(message.channel,
                           BytesIO(image_bytes),
                           filename="emojies.gif")
Exemplo n.º 10
0
async def remTag(message: discord.Message, text: Annotate.CleanContent):
    result = delfromDB(text.split(' ', 1)[0], text.split(' ', 1)[1])
    if result is 0:
        await client.say(message, "Tag removed.")
        return
    await client.say(message, "Tag doesn't exist.")