From 47b1f344b59f9194f1753b2118810c852507d3ce Mon Sep 17 00:00:00 2001 From: sco1 Date: Thu, 30 May 2019 11:45:44 -0400 Subject: Fix snake draw command Change frame to bytes helper to return the BytesIO object rather than the full content of the buffer. Update variables & add an output type hint to reinforce the change to the helper's output. --- bot/seasons/evergreen/snakes/snakes_cog.py | 4 ++-- bot/seasons/evergreen/snakes/utils.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bot/seasons/evergreen/snakes/snakes_cog.py b/bot/seasons/evergreen/snakes/snakes_cog.py index 3927fab5..1d138aff 100644 --- a/bot/seasons/evergreen/snakes/snakes_cog.py +++ b/bot/seasons/evergreen/snakes/snakes_cog.py @@ -624,8 +624,8 @@ class Snakes(Cog): text_color=text_color, bg_color=bg_color ) - png_bytes = utils.frame_to_png_bytes(image_frame) - file = File(png_bytes, filename='snek.png') + png_bytesIO = utils.frame_to_png_bytes(image_frame) + file = File(png_bytesIO, filename='snek.png') await ctx.send(file=file) @snakes_group.command(name='get') diff --git a/bot/seasons/evergreen/snakes/utils.py b/bot/seasons/evergreen/snakes/utils.py index 4899c2a2..3754a122 100644 --- a/bot/seasons/evergreen/snakes/utils.py +++ b/bot/seasons/evergreen/snakes/utils.py @@ -352,11 +352,12 @@ def create_snek_frame( return image -def frame_to_png_bytes(image: Image): +def frame_to_png_bytes(image: Image) -> io.BytesIO: """Convert image to byte stream.""" stream = io.BytesIO() image.save(stream, format='PNG') - return stream.getvalue() + stream.seek(0) + return stream log = logging.getLogger(__name__) -- cgit v1.2.3