async def draw_universal(ctx, path, command_end_index, origin, name):
    """Universal function which is called by draw command with the following arguments

       Args:
        - ctx: context that the command occured use this to access the message and other attributes
        - path: path to the drawing image (ie memes/lan/landrew.png)
        - command_end_index: index the end of the command (ie. for bdraw its 7 for '$' 'b' 'd' 'r' 'a' 'w' ' ')
        - origin: pixel origin imported from overlay.py
        - name: output file name
    """
    channel = ctx.channel
    #in case of gif
    url = over.get_gif_url(ctx, command_end_index)
    if url != 0:
        #get list of frames
        imgList = over.gif_url_to_image_list(url, 1)
        if imgList == 0:
            #if invalid list return
            await channel.send(embed=discord.Embed(description="invalid image",
                                                   color=discord.Color.red()))
            return
            #get list of image clips
        gifClip = make_draw_gif(imgList, 0)
        gifClip.write_gif(name + '.gif', 24, program='imageio')
        try:
            #check if message is <8 mb
            message = await channel.send(file=discord.File(name + '.gif'))
        except:
            #random color cause why not
            randRGB = lambda: random.randint(0, 255)
            randColor = int('%02X%02X%02X' % (randRGB(), randRGB(), randRGB()),
                            16)
            os.remove(name + '.gif')
            await channel.send(embed=discord.Embed(
                description="GIF + image becomes too large to send, sorry :(",
                color=randColor))
            return
        track_command(ctx.author.id, message)
        os.remove(name + '.gif')
        return
    url = over.get_image_url(ctx, command_end_index)
    if url == 0:  # no url, hand should write the inputed text
        output = over.draw_text(ctx.message.content[command_end_index:],
                                Path(path), origin)
    else:  # url inputed, hand should draw on the image
        output = over.overlay_image(over.url_to_image(url), Path(path), origin)
    output.save(name + '.png')
    try:
        message = await channel.send(file=discord.File(name + '.png'))
    except:
        message = await channel.send(embed=discord.Embed(
            description="Image too large", color=discord.Color.red()))
    track_command(ctx.author.id,
                  message)  # tracks the most recent command of a user
    os.remove(name + '.png')
Ejemplo n.º 2
0
async def bdraw(ctx):
    url = get_image_url(ctx)
    if url == 0:
        output = draw_text(ctx.message.content[7:],
                           Path('memes/barrington/bdraw.png'))
    else:
        output = overlay_image(url_to_image(url),
                               Path('memes/barrington/bdraw.png'))
    output.save('barrington-drawing.png')
    await client.send_file(ctx.message.channel, 'barrington-drawing.png')
    os.remove('barrington-drawing.png')
Ejemplo n.º 3
0
async def mdraw(ctx):
    url = get_image_url(ctx)
    if url == 0:
        output = draw_text(ctx.message.content[7:],
                           Path('memes/marius/draw.png'))
    else:
        output = overlay_image(url_to_image(url),
                               Path('memes/marius/draw.png'))
    name = 'marius-drawing.png'
    output.save(name)
    await client.send_file(ctx.message.channel, name)
    os.remove(name)
Ejemplo n.º 4
0
async def on_member_join(member):
    if member.guild.id == 387465995176116224:
        welcome_channel = client.get_channel(
            705670780704391259)  # introductions

        num_members = member.guild.member_count

        # used to randomly pick one of the available drawing professors
        professor_chosen = random.randint(0, 6)

        welcome_message = 'Welcome ' + member.display_name + '!|' + \
                          'You are member ' + str(num_members) + '!|' + \
                          'To see all the channels set your major|' + \
                          'and housing roles in #role-assignment!'
        if professor_chosen == 0:
            output = overlay.draw_text(welcome_message,
                                       Path('memes/barrington/bdraw.png'),
                                       overlay.barr_origin)
        elif professor_chosen == 1:
            output = overlay.draw_text(welcome_message,
                                       Path('memes/marius/draw.png'),
                                       overlay.marius_origin)
        elif professor_chosen == 2:
            output = overlay.draw_text(welcome_message,
                                       Path('memes/tim/tdraw.png'),
                                       overlay.tim_origin)
        elif professor_chosen == 3:
            output = overlay.draw_text(welcome_message,
                                       Path('memes/lan/lan-draw.png'),
                                       overlay.lan_origin)
        elif professor_chosen == 4:
            output = overlay.draw_text(welcome_message,
                                       Path('memes/lan/landrew.png'),
                                       overlay.landrew_origin)
        else:
            output = overlay.draw_text(welcome_message,
                                       Path('memes/sheldraw.png'),
                                       overlay.shel_origin)
        name = 'welcome-' + member.display_name + '.png'
        output.save(name)
        await welcome_channel.send(member.mention, file=discord.File(name))
        os.remove(name)
        embed = discord.Embed(color=discord.Color.blue())
        embed.set_author(
            name='Welcome to the UMass Amherst STEM Discord Server',
            icon_url=
            'https://cdn.discordapp.com/attachments/501594682820788224/558396074868342785/UMass_Stem_discord_logo.png'
        )
        embed.add_field(
                name = 'How to see all the channels',
                value = 'Set at least one housing role and at least one major role\n' \
                        'To set roles go to **#role-assignment** and use the `$get` command\n\n' \
                        'For example, if you live off campus and you\'re a chemistry major you would run these two commands:\n\n' \
                        '`$get Off-Campus`\n' \
                        '`$get Chemistry`\n\n' \
                        '*If you would like to see all the possible housing and major roles run the `$getlist` command*\n\n' \
                        '*If you have graduated already you may use the `Almuni` role in place of a housing role, if you are considering or planning on attending UMass and don\'t yet have a residential area you should assign yourself the `Prospective Student` role*',
                inline = False
            )
        await member.send(embed=embed)
Ejemplo n.º 5
0
async def bdraw(ctx):
    url = get_image_url(ctx)
    if url == 0:
        output = draw_text(ctx.message.content[7:],
                           Path('memes/barrington/bdraw.png'), barr_origin)
    else:
        output = overlay_image(url_to_image(url),
                               Path('memes/barrington/bdraw.png'), barr_origin)
    output.save('barrington-drawing.png')
    message = await client.send_file(ctx.message.channel,
                                     'barrington-drawing.png')
    track_command(ctx.message.author.id, message)
    os.remove('barrington-drawing.png')
Ejemplo n.º 6
0
async def mdraw(ctx):
    url = get_image_url(ctx)
    if url == 0:
        output = draw_text(ctx.message.content[7:],
                           Path('memes/marius/draw.png'), marius_origin)
    else:
        output = overlay_image(url_to_image(url),
                               Path('memes/marius/draw.png'), marius_origin)
    name = 'marius-drawing.png'
    output.save(name)
    message = await client.send_file(ctx.message.channel, name)
    track_command(ctx.message.author.id, message)
    os.remove(name)
Ejemplo n.º 7
0
async def draw_universal(ctx, path, command_end_index, origin, name):
    """Universal function which is called by draw command with the following arguments

       Args:
        - ctx: context that the command occured use this to access the message and other attributes
        - path: path to the drawing image (ie memes/lan/landrew.png)
        - command_end_index: index the end of the command (ie. for bdraw its 7 for '$' 'b' 'd' 'r' 'a' 'w' ' ')
        - origin: pixel origin imported from overlay.py
        - name: output file name
    """
    channel = ctx.channel
    async with channel.typing():
        url = over.get_image_url(ctx.message, command_end_index)
        if url == 0:  # no url, hand should write the inputed text
            if len(ctx.message.content[command_end_index:].strip()) == 0:
                # no input given, try to use previous bot output
                if bot_last_command[ctx.author.id] is not None:
                    message = bot_last_command[ctx.author.id]
                    url = over.get_image_url(message, 0)
                    output = over.overlay_image(over.url_to_image(url),
                                                Path(path), origin)
                else:
                    await channel.send(embed=discord.Embed(
                        description=
                        "No previous bot command to pull from. Please specify text or an image.",
                        color=discord.Color.red()))
                    return
            else:
                output = over.draw_text(
                    ctx.message.content[command_end_index:], Path(path),
                    origin)
        else:  # url inputed, hand should draw on the image
            output = over.overlay_image(over.url_to_image(url), Path(path),
                                        origin)
        output.save(name + '.png')
        try:
            message = await channel.send(file=discord.File(name + '.png'))
        except:
            message = await channel.send(embed=discord.Embed(
                description="Image too large", color=discord.Color.red()))
        track_command(ctx.author.id,
                      message)  # tracks the most recent command of a user
    os.remove(name + '.png')
Ejemplo n.º 8
0
def test_overlay02():
    """Test draw text command with multiple lines"""

    fname = base + '02.png'
    tname = os.path.join(tdir, fname)
    rname = os.path.join(refd, fname)

    text = 'This is a|multi-line test'
    path = Path('memes/tim/tdraw.png')
    origin = overlay.tim_origin

    output = overlay.draw_text(text, path, origin)
    output.save(tname)

    tsize = os.path.getsize(tname)
    print(glob.glob(tname), '[', tsize, 'bytes', ']')

    rsize = os.path.getsize(rname)
    print(glob.glob(rname), '[', rsize, 'bytes', ']')

    result = compare_images(rname, tname, tol=TOLERANCE)
    if result is not None:
        print('result=', result)
    assert result is None