feat(bible): added the api.bible icon to embeds

This commit is contained in:
SeaswimmerTheFsh 2024-04-06 06:15:00 -04:00
parent 9f7244cd65
commit f572a0d535
Signed by untrusted user: cswimr
GPG key ID: B8953EC01E5C4063
5 changed files with 151 additions and 79 deletions

View file

@ -6,11 +6,14 @@
# |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_|
import random
from io import BytesIO
import aiohttp
from discord import Embed
import numpy as np
from discord import Colour, Embed, File
from PIL import Image
from red_commons.logging import getLogger
from redbot.core import Config, commands
from redbot.core import Config, commands, data_manager
from redbot.core.bot import Red
from redbot.core.utils.chat_formatting import error, humanize_list
@ -22,7 +25,7 @@ class Bible(commands.Cog):
"""Retrieve Bible verses from the API.bible API."""
__author__ = ["SeaswimmerTheFsh"]
__version__ = "1.0.2"
__version__ = "1.1.0"
__documentation__ = "https://seacogs.coastalcommits.com/bible/"
def __init__(self, bot: Red):
@ -47,6 +50,22 @@ class Bible(commands.Cog):
]
return "\n".join(text)
def get_icon(self, color: Colour) -> File:
"""Get the docs.api.bible favicon with a given color."""
image_path = data_manager.bundled_data_path(self) / "api.bible-logo.png"
image = Image.open(image_path)
image = image.convert("RGBA")
data = np.array(image)
red, green, blue, alpha = data.T
white_areas = (red == 255) & (blue == 255) & (green == 255)
data[..., :-1][white_areas.T] = color.to_rgb()
image = Image.fromarray(data)
with BytesIO() as image_binary:
image.save(image_binary, "PNG")
image_binary.seek(0)
return File(image_binary, filename="icon.png", description="API.Bible Icon")
async def translate_book_name(self, bible_id: str, book_name: str) -> str:
"""Translate a book name to a book ID."""
book_name_list = [
@ -248,15 +267,17 @@ class Bible(commands.Cog):
return
if await ctx.embed_requested():
icon = await self.get_icon(await ctx.embed_color)
embed = Embed(
title=f"{passage['reference']}",
description=passage["content"].replace("", ""),
color=await self.bot.get_embed_color(ctx.channel),
color=await ctx.embed_color,
)
embed.set_footer(
text=f"{ctx.prefix}bible passage - Powered by API.Bible - {version.abbreviationLocal} ({version.languageLocal}, {version.descriptionLocal})"
text=f"{ctx.prefix}bible passage - Powered by API.Bible - {version.abbreviationLocal} ({version.languageLocal}, {version.descriptionLocal})",
icon_url="attachment://favicon.png"
)
await ctx.send(embed=embed)
await ctx.send(embed=embed, file=icon)
else:
await ctx.send(f"## {passage['reference']}\n{passage['content']}")
@ -288,14 +309,16 @@ class Bible(commands.Cog):
return
if await ctx.embed_requested():
icon = await self.get_icon(await ctx.embed_color)
embed = Embed(
title=f"{passage['reference']}",
description=passage["content"].replace("", ""),
color=await self.bot.get_embed_color(ctx.channel),
color=await ctx.embed_color,
)
embed.set_footer(
text=f"{ctx.prefix}bible random - Powered by API.Bible - {version.abbreviationLocal} ({version.languageLocal}, {version.descriptionLocal})"
text=f"{ctx.prefix}bible random - Powered by API.Bible - {version.abbreviationLocal} ({version.languageLocal}, {version.descriptionLocal})",
icon_url="attachment://favicon.png"
)
await ctx.send(embed=embed)
await ctx.send(embed=embed, file=icon)
else:
await ctx.send(f"## {passage['reference']}\n{passage['content']}")