fix implementation issues in
@@ -12,22 +12,23 @@ class ImageConvert:
self.bot = bot
print('Addon "{}" loaded'.format(self.__class__.__name__))
- async def on_message(self, message):
- # BMP conversion
- def img_convert(self, in_img):
+ @staticmethod
+ def img_convert(in_img):
img_obj = Image.open(BytesIO(in_img))
img_out = BytesIO()
img_obj.save(img_out, 'png')
img_out.seek(0)
return img_out
+ async def on_message(self, message):
+ # BMP conversion
for f in message.attachments:
if f["filename"].lower().endswith('.bmp') and f["size"] <= 600000: # 600kb
async with aiohttp.ClientSession() as session:
async with session.get(f["url"], timeout=45) as img_request:
img_content = await img_request.read()
with concurrent.futures.ProcessPoolExecutor() as pool:
- img_out = await self.bot.loop.run_in_executor(pool, functools.partial(img_convert, img_content))
+ img_out = await self.bot.loop.run_in_executor(pool, functools.partial(self.img_convert, img_content))
out_message = "{} from {}".format(self.bot.escape_name(f["filename"]), message.author.mention)
new_filename = f["filename"][:-3] + "png"
await self.bot.send_file(message.channel, img_out, filename=new_filename, content=out_message)
