Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Add await breakpoints to render algorithms
Browse files Browse the repository at this point in the history
+ Added disdain_for_jpegs.gif
* Image rendering algorithms now await regularly to mitigate
  long lockups for large processes
* Made finishing touches on Portuguese (BR) lang file
* Dither charts no longer have 'assets/' in their filename strings
- Killed off some pesky print() statements
  • Loading branch information
DiamondIceNS committed May 16, 2018
1 parent 6028d51 commit 1442c81
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
Binary file added assets/disdain_for_jpegs.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions commands/canvas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import discord
from discord.ext import commands
from discord.ext.commands import BucketType
from discord.utils import get as dget
Expand Down Expand Up @@ -43,7 +44,11 @@ async def parse_diff(ctx, coords):
att = ctx.message.attachments[0]
if att.filename[-4:].lower() != ".png":
if att.filename[-4:].lower() == ".jpg" or att.filename[-5:].lower() == ".jpeg":
await ctx.send(getlang(ctx.guild.id, "bot.error.jpeg"))
try:
f = discord.File("assets/disdain_for_jpegs.gif", "disdain_for_jpegs.gif")
await ctx.send(getlang(ctx.guild.id, "bot.error.jpeg"), file=f)
except IOError:
await ctx.send(getlang(ctx.guild.id, "bot.error.jpeg"))
return
await ctx.send(getlang(ctx.guild.id, "bot.error.no_png"))
return
Expand Down Expand Up @@ -194,7 +199,11 @@ async def check_attachment(ctx):
filename = ctx.message.attachments[0].filename
if filename[-4:].lower() != ".png":
if filename[-4:].lower() == ".jpg" or filename[-5:].lower() == ".jpeg":
await ctx.send(getlang(ctx.guild.id, "bot.error.jpeg"))
try:
f = discord.File("assets/disdain_for_jpegs.gif", "disdain_for_jpegs.gif")
await ctx.send(getlang(ctx.guild.id, "bot.error.jpeg"), file=f)
except IOError:
await ctx.send(getlang(ctx.guild.id, "bot.error.jpeg"))
return False
await ctx.send(getlang(ctx.guild.id, "bot.error.no_png"))
return False
Expand Down Expand Up @@ -262,7 +271,6 @@ async def repeat(self, ctx):
x = int(match.group(3))
y = int(match.group(4))
zoom = int(match.group(5)) if match.group(5) is not None else 1
print("cmd: {}, scmd: {}, x: {}, y: {}".format(cmd, sub_cmd, x, y))
if (cmd == "diff" or cmd == "d") and len(msg.attachments) > 0 \
and msg.attachments[0].filename[-4:].lower() == ".png":
att = msg.attachments[0]
Expand Down
9 changes: 4 additions & 5 deletions glimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ async def on_guild_update(before, after):

@bot.event
async def on_command_error(ctx, error):
print(type(error))
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(getlang(ctx.guild.id, "bot.error.command_on_cooldown").format(error.retry_after))
return
Expand Down Expand Up @@ -224,25 +223,25 @@ async def ditherchart(ctx):

@ditherchart.command(name="pixelcanvas")
async def ditherchart_pixelcanvas(ctx):
f = discord.File("assets/dither_chart_pixelcanvas.png", "assets/dither_chart_pixelcanvas.png")
f = discord.File("assets/dither_chart_pixelcanvas.png", "dither_chart_pixelcanvas.png")
await ctx.send(file=f)


@ditherchart.command(name="pixelzio")
async def ditherchart_pixelzio(ctx):
f = discord.File("assets/dither_chart_pixelzio.png", "assets/dither_chart_pixelzio.png")
f = discord.File("assets/dither_chart_pixelzio.png", "dither_chart_pixelzio.png")
await ctx.send(file=f)


@ditherchart.command(name="pixelzone")
async def ditherchart_pixelzio(ctx):
f = discord.File("assets/dither_chart_pixelzone.png", "assets/dither_chart_pixelzone.png")
f = discord.File("assets/dither_chart_pixelzone.png", "dither_chart_pixelzone.png")
await ctx.send(file=f)


@ditherchart.command(name="pxlsspace")
async def ditherchart_pixelzio(ctx):
f = discord.File("assets/dither_chart_pxlsspace.png", "assets/dither_chart_pxlsspace.png")
f = discord.File("assets/dither_chart_pxlsspace.png", "dither_chart_pxlsspace.png")
await ctx.send(file=f)


Expand Down
38 changes: 20 additions & 18 deletions lang/pt_BR.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"configuration.alert_channel_set": "O canal de Alerta foi definido para {0}.",
"configuration.autoscan_disabled": "Autoscan foi desativado.",
"configuration.autoscan_enabled": "Autoscan foi ativado.",
"configuration.canvas_check": "O canvas padrão desta guild é ** {0} **. \ n"
"Para alterar o canvas padrão, execute este comando novamente com um canvas suportado. (Use `{1}help canvas` para ver uma lista.)",
"configuration.canvas_set": "O canvas padrão foi definido para **{0}**.",
"configuration.language_check": "O idioma atual deste guild é **{1}**.\n"
"Para definir um novo idioma, execute este comando novamente com uma das seguintes opções:\n"
Expand Down Expand Up @@ -235,47 +237,47 @@
"command.version": "version",

# Command signatures
"signature.alertchannel": "alertchannel <subcommand>",
"signature.alertchannel": "alertchannel <subcomando>",
"signature.alertchannel.clear": "alertchannel clear",
"signature.alertchannel.set": "alertchannel set <channel>",
"signature.alertchannel.set": "alertchannel set <canal>",
"signature.autoscan": "autoscan",
"signature.canvas": "canvas <canvas>",
"signature.canvas.pixelcanvas": "canvas pixelcanvas",
"signature.canvas.pixelzio": "canvas pixelzio",
"signature.canvas.pixelzone": "canvas pixelzone",
"signature.canvas.pxlsspace": "canvas pxlsspace",
"signature.changelog": "changelog",
"signature.diff": "diff <subcommand>",
"signature.diff.pixelcanvas": "diff pixelcanvas <coordinates> (zoom)",
"signature.diff.pixelzio": "diff pixelzio <coordinates> (zoom)",
"signature.diff.pixelzone": "diff pixelzone <coordinates> (zoom)",
"signature.diff.pxlsspace": "diff pxlsspace <coordinates> (zoom)",
"signature.ditherchart": "ditherchart <subcommand>",
"signature.diff": "diff <subcomando>",
"signature.diff.pixelcanvas": "diff pixelcanvas <coordenadas> (zoom)",
"signature.diff.pixelzio": "diff pixelzio <coordenadas> (zoom)",
"signature.diff.pixelzone": "diff pixelzone <coordenadas> (zoom)",
"signature.diff.pxlsspace": "diff pxlsspace <coordenadas> (zoom)",
"signature.ditherchart": "ditherchart <subcomando>",
"signature.ditherchart.pixelcanvas": "ditherchart pixelcanvas",
"signature.ditherchart.pixelzio": "ditherchart pixelzio",
"signature.ditherchart.pixelzone": "ditherchart pixelzone",
"signature.ditherchart.pxlsspace": "ditherchart pxlsspace",
"signature.github": "github",
"signature.gridify": "gridify (size)",
"signature.gridify": "gridify (tamanho)",
"signature.help": "help",
"signature.invite": "invite",
"signature.language": "language (code)",
"signature.language": "language (código)",
"signature.listemotes": "listemotes",
"signature.ping": "ping",
"signature.prefix": "prefix <prefix>",
"signature.prefix": "prefix <prefixo>",
"signature.preview": "preview <subcommand>",
"signature.preview.pixelcanvas": "preview pixelcanvas <coordinates> (zoom)",
"signature.preview.pixelzio": "preview pixelzio <coordinates> (zoom)",
"signature.preview.pixelzone": "preview pixelzone <coordinates> (zoom)",
"signature.preview.pxlsspace": "preview pxlsspace <coordinates> (zoom)",
"signature.quantize": "quantize <subcommand>",
"signature.preview.pixelcanvas": "preview pixelcanvas <coordenadas> (zoom)",
"signature.preview.pixelzio": "preview pixelzio <coordenadas> (zoom)",
"signature.preview.pixelzone": "preview pixelzone <coordenadas> (zoom)",
"signature.preview.pxlsspace": "preview pxlsspace <coordenadas> (zoom)",
"signature.quantize": "quantize <subcomando>",
"signature.quantize.pixelcanvas": "quantize pixelcanvas",
"signature.quantize.pixelzio": "quantize pixelzio",
"signature.quantize.pixelzone": "quantize pixelzone",
"signature.quantize.pxlsspace": "quantize pxlsspace",
"signature.register": "register",
"signature.registerguild": "registerguild",
"signature.repeat": "repeat",
"signature.suggest": "suggest <suggestion>",
"signature.suggest": "suggest <sugestão>",
"signature.version": "version",
}
}
7 changes: 7 additions & 0 deletions utils/render.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import aiohttp
import asyncio
import discord
import io
import json
Expand Down Expand Up @@ -43,6 +44,7 @@ async def diff(ctx, x, y, att, zoom, fetch, palette):
bad = 0 # Number of pixels in the template that are not in the color palette

for py in range(template.height):
await asyncio.sleep(0)
for px in range(template.width):
tp = template.getpixel((px, py))
dp = diff_img.getpixel((px, py))
Expand Down Expand Up @@ -108,6 +110,7 @@ async def quantize(ctx, att, palette):

bad_pixels = template.height * template.width
for py in range(template.height):
await asyncio.sleep(0)
for px in range(template.width):
pix = template.getpixel((px, py))

Expand Down Expand Up @@ -146,6 +149,7 @@ async def gridify(ctx, att, zoom):

grid_img = Image.new('RGBA', (template.width * (zoom + 1) - 1, template.height * (zoom + 1) - 1))
for iy in range(template.height):
await asyncio.sleep(0)
for ix in range(template.width):
for ziy in range(zoom):
for zix in range(zoom):
Expand Down Expand Up @@ -191,6 +195,7 @@ def pixel_to_data_index():
) / 2 # Pixels come packed in pairs

for py in range(dy):
await asyncio.sleep(0)
for px in range(dx):
i = pixel_to_data_index()
color_id = data[int(i)] & 15 if i % 1 != 0 else data[int(i)] >> 4
Expand Down Expand Up @@ -257,6 +262,7 @@ async def fetch_pixelzone(x, y, dx, dy):
tmp = lz4.frame.decompress(bytes(tmp))
chunk = Image.new('RGB', (512, 512), (255, 255, 255, 255))
for py in range(chunk.height):
await asyncio.sleep(0)
for px in range(chunk.width):
i = (py * 512 + px) / 2
color_id = tmp[int(i)] & 15 if i % 1 == 0 else tmp[int(i)] >> 4
Expand All @@ -277,6 +283,7 @@ async def fetch_pxlsspace(x, y, dx, dy):
data = await resp.read()

for py in range(dy):
await asyncio.sleep(0)
for px in range(dx):
if 1280 <= px+x or px+x < 0 or 720 <= py+y or py+y < 0:
continue
Expand Down

0 comments on commit 1442c81

Please sign in to comment.