How to use the cogs.utils.tabledraw.TextCell function in Cogs

To help you get started, we’ve selected a few Cogs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mdiller / MangoByte / cogs / utils / drawdota.py View on Github external
box_width = 306
	box_height = 73
	box_margin_y = 14

	start_y = 70
	start_x_left = 14
	start_x_right = 370
	start_x = [ start_x_left, start_x_right ]

	for i in range(0, 4):
		for j in range(0, 2):
			x = start_x[j]
			y = start_y + (i * (box_height + box_margin_y))
			text = talent_rows[i][j]

			cell = TextCell(text, color="#cca770", font_size=20, wrap=True, padding=[ 0, 15, 0, 15 ], horizontal_align="center")
			cell.render(draw, image, x, y, box_width, box_height)

	fp = BytesIO()
	image.save(fp, format="PNG")
	fp.seek(0)

	return fp
github mdiller / MangoByte / cogs / utils / drawdota.py View on Github external
def get_datetime_cell(match, region_data):
	match_date = datetime.utcfromtimestamp(match["start_time"])
	region = str(match.get("region"))
	if region and region in region_data:
		match_date += timedelta(hours=region_data[region]["UTC_offset"])
	# character for leading space is different on windows
	lead_char = "#" if os.name == "nt" else "-"
	str_date = match_date.strftime(f"%b %{lead_char}d %Y")
	str_time = match_date.strftime(f"%{lead_char}I:%M %p")
	return DoubleCell(
		TextCell(str_date, font_size=18, horizontal_align="center"),
		TextCell(str_time, font_size=18, horizontal_align="center")
	)
github mdiller / MangoByte / cogs / utils / drawdota.py View on Github external
lobby_type = game_strings.get(f"lobby_type_{match['lobby_type']}", "Unknown")
		if first:
			first = False
		else:
			table.add_row([ColorCell(color=discord_color2, height=12) for i in range(len(headers))])
		table.add_row([
			ImageCell(img=await get_hero_image(match["hero_id"]), height=48),
			DoubleCell(
				TextCell(get_hero_name(match["hero_id"]), font_size=24),
				TextCell(match.get("match_id"), font_size=12, horizontal_align="left", color=grey_color)
			),
			TextCell("Win" if won_match else "Loss", color=("green" if won_match else "red"), horizontal_align="center"),
			TextCell(match.get("kills")),
			TextCell(match.get("deaths")),
			TextCell(match.get("assists")),
			TextCell(format_duration_simple(match.get("duration")), horizontal_align="center"),
			DoubleCell(
				TextCell(game_mode, font_size=18, padding_right=15, color=grey_color),
				TextCell(lobby_type, font_size=18, padding_right=15, color=grey_color)
			),
			get_datetime_cell(match, region_data)
		])
	image = table.render()

	border_image = Image.new('RGBA', (image.size[0] + (border_size * 2), image.size[1] + border_size), color=discord_color1)
	image = paste_image(border_image, image, border_size, 0)

	fp = BytesIO()
	image.save(fp, format="PNG")
	fp.seek(0)

	return fp
github mdiller / MangoByte / cogs / utils / drawdota.py View on Github external
# Header
	headers = [
		TextCell("", padding=0),
		TextCell(""),
		TextCell(""),
		TextCell("K", horizontal_align="center"),
		TextCell("D", horizontal_align="center"),
		TextCell("A", horizontal_align="center"),
		TextCell("GPM", color="yellow"),
		TextCell("Items")
	]
	if is_parsed:
		headers[-1:-1] = [
			TextCell("APM"),
			TextCell("Lane"),
			TextCell("Pings")
		]
	table.add_row(headers)
	for cell in table.rows[0]:
		cell.background = discord_color1

	# Do players
	for player in match["players"]:
		if player['isRadiant']:
			await add_player_row(table, player, is_parsed)
	table.add_row([ColorCell(color=discord_color1, height=5) for i in range(len(headers))])
	for player in match["players"]:
		if not player['isRadiant']:
			await add_player_row(table, player, is_parsed)
	return table.render()
github mdiller / MangoByte / cogs / utils / drawdota.py View on Github external
cost = card.mana_cost
		last_cell = ""
		if card.type == "Hero":
			last_cell = f"Turn {hero_turns.get(card.id)}"
		else:
			last_cell = f"x {card_counts.get(card.id)}"
		if first:
			first = False
		else:
			table.add_row([ColorCell(color=discord_color2, height=2) for i in range(column_count)])
		table.add_row([
			ImageCell(img=await get_url_image(card.mini_image), height=48),
			ImageCell(img=await get_url_image(card.type_image), height=48),
			TextCell(cost),
			TextCell(card.name),
			TextCell(last_cell, horizontal_align="right")
		])
		card_color = card.color.blend(Color(discord_color2), 0.5)
		for cell in table.rows[len(table.rows) - 1]:
			cell.background = card_color.hex
	image = table.render()

	border_image = Image.new('RGBA', (image.size[0] + (border_size * 2), image.size[1] + border_size), color=discord_color1)
	image = paste_image(border_image, image, border_size, 0)

	image.save(filename, format="PNG")

	return filename
github mdiller / MangoByte / cogs / utils / drawdota.py View on Github external
table = Table(background=discord_color2)
	# Header
	headers = [
		TextCell("", padding=0),
		TextCell(""),
		TextCell(""),
		TextCell("K", horizontal_align="center"),
		TextCell("D", horizontal_align="center"),
		TextCell("A", horizontal_align="center"),
		TextCell("GPM", color="yellow"),
		TextCell("Items")
	]
	if is_parsed:
		headers[-1:-1] = [
			TextCell("APM"),
			TextCell("Lane"),
			TextCell("Pings")
		]
	table.add_row(headers)
	for cell in table.rows[0]:
		cell.background = discord_color1

	# Do players
	for player in match["players"]:
		if player['isRadiant']:
			await add_player_row(table, player, is_parsed)
	table.add_row([ColorCell(color=discord_color1, height=5) for i in range(len(headers))])
	for player in match["players"]:
		if not player['isRadiant']:
			await add_player_row(table, player, is_parsed)
	return table.render()
github mdiller / MangoByte / cogs / utils / drawdota.py View on Github external
async def draw_matches_table(matches, game_strings):
	region_data = read_json(settings.resource("json/region_data.json"))	

	border_size = 10
	grey_color = "#BBBBBB"
	table = Table(background=discord_color2)
	# Header
	headers = [
		TextCell("Hero", padding=0),
		TextCell(""),
		TextCell("Result"),
		TextCell("K", horizontal_align="center"),
		TextCell("D", horizontal_align="center"),
		TextCell("A", horizontal_align="center"),
		TextCell("Duration"),
		TextCell("Type"),
		TextCell("Date")
	]
	table.add_row(headers)
	for cell in table.rows[0]:
		cell.background = discord_color1

	table.add_row([ColorCell(color=discord_color1, height=6) for i in range(len(headers))])
	first = True
	for match in matches:
		won_match = bool(match["radiant_win"]) == bool(match["player_slot"] < 128)
		game_mode = game_strings.get(f"game_mode_{match['game_mode']}", "Unknown")
		lobby_type = game_strings.get(f"lobby_type_{match['lobby_type']}", "Unknown")
github mdiller / MangoByte / cogs / utils / drawdota.py View on Github external
else:
			table.add_row([ColorCell(color=discord_color2, height=12) for i in range(len(headers))])
		table.add_row([
			ImageCell(img=await get_hero_image(match["hero_id"]), height=48),
			DoubleCell(
				TextCell(get_hero_name(match["hero_id"]), font_size=24),
				TextCell(match.get("match_id"), font_size=12, horizontal_align="left", color=grey_color)
			),
			TextCell("Win" if won_match else "Loss", color=("green" if won_match else "red"), horizontal_align="center"),
			TextCell(match.get("kills")),
			TextCell(match.get("deaths")),
			TextCell(match.get("assists")),
			TextCell(format_duration_simple(match.get("duration")), horizontal_align="center"),
			DoubleCell(
				TextCell(game_mode, font_size=18, padding_right=15, color=grey_color),
				TextCell(lobby_type, font_size=18, padding_right=15, color=grey_color)
			),
			get_datetime_cell(match, region_data)
		])
	image = table.render()

	border_image = Image.new('RGBA', (image.size[0] + (border_size * 2), image.size[1] + border_size), color=discord_color1)
	image = paste_image(border_image, image, border_size, 0)

	fp = BytesIO()
	image.save(fp, format="PNG")
	fp.seek(0)

	return fp
github mdiller / MangoByte / cogs / utils / drawdota.py View on Github external
async def add_player_row(table, player, is_parsed):
	row = [
		ColorCell(width=5, color=("green" if player["isRadiant"] else "red")),
		ImageCell(img=await get_hero_image(player["hero_id"]), height=48),
		TextCell(player.get("personaname", "Anonymous")),
		TextCell(player.get("kills")),
		TextCell(player.get("deaths")),
		TextCell(player.get("assists")),
		TextCell(player.get("gold_per_min"), color="yellow"),
		ImageCell(img=await get_item_images(player), height=48)
	]
	if is_parsed:
		row[-1:-1] = [
			TextCell(player.get("actions_per_min")),
			TextCell(get_lane(player)),
			TextCell(player.get("pings", "-"), horizontal_align="center")
		]
	table.add_row(row)