Skip to content

Commit

Permalink
Merge pull request #531 from petabyte-imo/EmbedCreator-usage-fix
Browse files Browse the repository at this point in the history
Embed Creator usage fix
  • Loading branch information
wlinator authored Sep 7, 2024
2 parents ee4aafc + 76d0715 commit a627920
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 257 deletions.
15 changes: 9 additions & 6 deletions tux/cogs/fun/fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ async def fact(self, ctx: commands.Context[Tux]) -> None:
user_display_avatar=ctx.author.display_avatar.url,
title="Fun Fact",
description=random.choice(self.facts),
custom_author_text="Click here to submit more facts here!",
custom_author_text_url="https://github.com/allthingslinux/tux/blob/main/tux/cogs/fun/fact.py",
custom_author_icon_url="https://github.com/allthingslinux/tux/blob/main/assets/emojis/tux_info.png?raw=true",
)

# set author
embed.set_author(
name="Submit more facts here!",
url="https://github.com/allthingslinux/tux/blob/main/tux/cogs/fun/fact.py",
icon_url="https://github.com/allthingslinux/tux/blob/main/assets/emojis/tux_info.png?raw=true",
)
# # set author
# embed.set_author(
# name="Submit more facts here!",
# url="https://github.com/allthingslinux/tux/blob/main/tux/cogs/fun/fact.py",
# icon_url="https://github.com/allthingslinux/tux/blob/main/assets/emojis/tux_info.png?raw=true",
# )

await ctx.send(embed=embed)

Expand Down
4 changes: 2 additions & 2 deletions tux/cogs/fun/xkcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ async def get_comic_and_embed(
embed_type=EmbedCreator.INFO,
title="",
description=f"\n\n> {comic.description.strip()}" if comic.description else "",
custom_author_text=f"xkcd {comic.id} - {comic.title}",
image_url=comic.image_url,
)

embed.set_author(name=f"xkcd {comic.id} - {comic.title}")
embed.set_image(url=comic.image_url)
ephemeral = False

except xkcd.HttpError:
Expand Down
30 changes: 17 additions & 13 deletions tux/cogs/guild/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from tux.bot import Tux
from tux.database.controllers import DatabaseController
from tux.ui.embeds import EmbedCreator
from tux.ui.embeds import EmbedCreator, EmbedType
from tux.ui.views.config import ConfigSetChannels, ConfigSetPrivateLogs, ConfigSetPublicLogs
from tux.utils.constants import CONST

Expand Down Expand Up @@ -183,10 +183,11 @@ async def config_get_roles(

assert interaction.guild

embed = discord.Embed(
embed = EmbedCreator.create_embed(
title="Config - Roles",
color=discord.Color.blue(),
timestamp=discord.utils.utcnow(),
embed_type=EmbedType.INFO,
custom_color=discord.Color.blue(),
message_timestamp=discord.utils.utcnow(),
)

jail_role_id = await self.db.get_jail_role_id(interaction.guild.id)
Expand All @@ -213,10 +214,11 @@ async def config_get_perms(

assert interaction.guild

embed = discord.Embed(
embed = EmbedCreator.create_embed(
embed_type=EmbedType.INFO,
custom_color=discord.Color.blue(),
title="Config - Permission Level Roles",
color=discord.Color.blue(),
timestamp=discord.utils.utcnow(),
message_timestamp=discord.utils.utcnow(),
)

for i in range(8):
Expand Down Expand Up @@ -245,10 +247,11 @@ async def config_get_channels(

assert interaction.guild

embed = discord.Embed(
embed = EmbedCreator.create_embed(
title="Config - Channels",
color=discord.Color.blue(),
timestamp=discord.utils.utcnow(),
embed_type=EmbedType.INFO,
custom_color=discord.Color.blue(),
message_timestamp=discord.utils.utcnow(),
)

jail_channel_id = await self.db.get_jail_channel_id(interaction.guild.id)
Expand Down Expand Up @@ -283,10 +286,11 @@ async def config_get_logs(

assert interaction.guild

embed = discord.Embed(
embed = EmbedCreator.create_embed(
title="Config - Logs",
color=discord.Color.blue(),
timestamp=discord.utils.utcnow(),
embed_type=EmbedType.INFO,
custom_color=discord.Color.blue(),
message_timestamp=discord.utils.utcnow(),
)

join_log_id = await self.db.get_join_log_id(interaction.guild.id)
Expand Down
34 changes: 23 additions & 11 deletions tux/cogs/info/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from reactionmenu import ViewButton, ViewMenu

from tux.bot import Tux
from tux.ui.embeds import EmbedCreator, EmbedType


class Info(commands.Cog):
def __init__(self, bot: Tux) -> None:
self.bot = bot

@commands.guild_only()
@commands.hybrid_group(name="info", aliases=["i"], usage="info <subcommand>")
async def info(self, ctx: commands.Context[Tux]) -> None:
"""
Expand All @@ -25,6 +27,7 @@ async def info(self, ctx: commands.Context[Tux]) -> None:
if ctx.invoked_subcommand is None:
await ctx.send_help("info")

@commands.guild_only()
@info.command(name="server", aliases=["s"], usage="info server")
async def server(self, ctx: commands.Context[Tux]) -> None:
"""
Expand All @@ -37,14 +40,18 @@ async def server(self, ctx: commands.Context[Tux]) -> None:
"""
guild = ctx.guild
assert guild
assert guild.icon

embed: discord.Embed = (
discord.Embed(
EmbedCreator.create_embed(
embed_type=EmbedType.INFO,
title=guild.name,
description=guild.description or "No description available.",
color=discord.Color.blurple(),
custom_color=discord.Color.blurple(),
custom_author_text="Server Information",
custom_author_icon_url=guild.icon.url,
custom_footer_text=f"ID: {guild.id} | Created: {guild.created_at.strftime('%B %d, %Y')}",
)
.set_author(name="Server Information", icon_url=guild.icon)
.add_field(name="Owner", value=str(guild.owner.mention) if guild.owner else "Unknown")
.add_field(name="Vanity URL", value=guild.vanity_url_code or "None")
.add_field(name="Boosts", value=guild.premium_subscription_count)
Expand All @@ -57,11 +64,11 @@ async def server(self, ctx: commands.Context[Tux]) -> None:
.add_field(name="Humans", value=sum(not member.bot for member in guild.members))
.add_field(name="Bots", value=sum(member.bot for member in guild.members))
.add_field(name="Bans", value=len([entry async for entry in guild.bans(limit=2000)]))
.set_footer(text=f"ID: {guild.id} | Created: {guild.created_at.strftime('%B %d, %Y')}")
)

await ctx.send(embed=embed)

@commands.guild_only()
@info.command(name="member", aliases=["m", "user", "u"], usage="info member [member]")
async def member(self, ctx: commands.Context[Tux], member: discord.Member) -> None:
"""
Expand All @@ -74,15 +81,15 @@ async def member(self, ctx: commands.Context[Tux], member: discord.Member) -> No
member : discord.Member
The member to get information about.
"""
user = await self.bot.fetch_user(member.id)
embed: discord.Embed = (
discord.Embed(
EmbedCreator.create_embed(
embed_type=EmbedType.INFO,
title=member.display_name,
custom_color=discord.Color.blurple(),
description="Here is some information about the member.",
color=discord.Color.blurple(),
)
.set_thumbnail(url=member.display_avatar.url)
.set_image(
url=(await self.bot.fetch_user(member.id)).banner, # Fetched member's banner
thumbnail_url=member.display_avatar.url,
image_url=user.banner.url if user.banner else None,
)
.add_field(name="Bot?", value="✅" if member.bot else "❌", inline=False)
.add_field(name="Username", value=member.name, inline=False)
Expand All @@ -106,6 +113,7 @@ async def member(self, ctx: commands.Context[Tux], member: discord.Member) -> No

await ctx.send(embed=embed)

@commands.guild_only()
@info.command(name="roles", aliases=["r"], usage="info roles")
async def roles(self, ctx: commands.Context[Tux]) -> None:
"""
Expand Down Expand Up @@ -166,7 +174,11 @@ async def paginated_embed(
chunk_size : int
The size of each chunk for pagination.
"""
embed: discord.Embed = discord.Embed(title=title, color=discord.Color.blurple())
embed: discord.Embed = EmbedCreator.create_embed(
embed_type=EmbedType.INFO,
title=title,
custom_color=discord.Color.blurple(),
)
chunks: list[list[str]] = list(self._chunks(iter(items), chunk_size))

if not chunks:
Expand Down
20 changes: 13 additions & 7 deletions tux/cogs/moderation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from prisma.enums import CaseType
from tux.bot import Tux
from tux.database.controllers import DatabaseController
from tux.ui.embeds import EmbedCreator
from tux.ui.embeds import EmbedCreator, EmbedType
from tux.utils.constants import Constants as CONST


Expand All @@ -17,6 +17,7 @@ def __init__(self, bot: Tux) -> None:
self.db = DatabaseController()
self.config = DatabaseController().guild_config

# TODO: Get rid of create_embed in the ModerationCogBase command as its only being used once and is replacable
def create_embed(
self,
ctx: commands.Context[Tux],
Expand Down Expand Up @@ -50,17 +51,22 @@ def create_embed(
discord.Embed
The embed for the moderation action.
"""

embed = discord.Embed(color=color, timestamp=timestamp or ctx.message.created_at)
embed.set_author(name=title, icon_url=icon_url)
embed.set_thumbnail(url=thumbnail_url)

footer_text, footer_icon_url = EmbedCreator.get_footer(
bot=self.bot,
user_name=ctx.author.name,
user_display_avatar=ctx.author.display_avatar.url,
)
embed.set_footer(text=footer_text, icon_url=footer_icon_url)

embed = EmbedCreator.create_embed(
embed_type=EmbedType.INFO,
custom_color=color,
message_timestamp=timestamp or ctx.message.created_at,
custom_author_text=title,
custom_author_icon_url=icon_url,
thumbnail_url=thumbnail_url,
custom_footer_text=footer_text,
custom_footer_icon_url=footer_icon_url,
)

for name, value, inline in fields:
embed.add_field(name=name, value=value, inline=inline)
Expand Down
31 changes: 17 additions & 14 deletions tux/cogs/moderation/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from prisma.models import Case
from prisma.types import CaseWhereInput
from tux.bot import Tux
from tux.ui.embeds import EmbedCreator
from tux.ui.embeds import EmbedCreator, EmbedType
from tux.utils import checks
from tux.utils.constants import Constants as CONST
from tux.utils.flags import CaseModifyFlags, CasesViewFlags, generate_usage
Expand Down Expand Up @@ -276,10 +276,10 @@ async def _handle_case_response(
)
embed.set_thumbnail(url=user.avatar)
else:
embed = discord.Embed(
embed = EmbedCreator.create_embed(
embed_type=EmbedType.ERROR,
title=f"Case {action}",
description="Failed to find case.",
color=CONST.EMBED_COLORS["ERROR"],
)

await ctx.send(embed=embed, delete_after=30, ephemeral=True)
Expand All @@ -293,10 +293,10 @@ async def _handle_case_list_response(
menu = ViewMenu(ctx, menu_type=ViewMenu.TypeEmbed, all_can_click=True, delete_on_timeout=True)

if not cases:
embed = discord.Embed(
embed = EmbedCreator.create_embed(
embed_type=EmbedType.ERROR,
title="Cases",
description="No cases found.",
color=CONST.EMBED_COLORS["ERROR"],
)
await ctx.send(embed=embed, delete_after=30, ephemeral=True)
return
Expand Down Expand Up @@ -337,21 +337,24 @@ def _create_case_list_embed(
cases: list[Case],
total_cases: int,
) -> discord.Embed:
embed = discord.Embed(
title=f"Total Cases ({total_cases})",
description="",
color=CONST.EMBED_COLORS["CASE"],
)

if ctx.guild:
embed.set_author(name=ctx.guild.name, icon_url=ctx.guild.icon)
assert ctx.guild
assert ctx.guild.icon

footer_text, footer_icon_url = EmbedCreator.get_footer(
bot=self.bot,
user_name=ctx.author.name,
user_display_avatar=ctx.author.display_avatar.url,
)
embed.set_footer(text=footer_text, icon_url=footer_icon_url)

embed = EmbedCreator.create_embed(
title=f"Total Cases ({total_cases})",
description="",
embed_type=EmbedType.CASE,
custom_author_text=ctx.guild.name,
custom_author_icon_url=ctx.guild.icon.url,
custom_footer_text=footer_text,
custom_footer_icon_url=footer_icon_url,
)

for case in cases:
self._add_case_to_embed(embed, case)
Expand Down
23 changes: 10 additions & 13 deletions tux/cogs/services/starboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from tux.bot import Tux
from tux.database.controllers.starboard import StarboardController, StarboardMessageController
from tux.ui.embeds import EmbedCreator
from tux.ui.embeds import EmbedCreator, EmbedType
from tux.utils import checks


Expand Down Expand Up @@ -263,20 +263,17 @@ async def create_or_update_starboard_message(
if not starboard:
return

embed = discord.Embed(
description=original_message.content,
color=discord.Color.gold(),
timestamp=original_message.created_at,
)
embed.set_author(
name=original_message.author.display_name,
icon_url=original_message.author.avatar.url if original_message.author.avatar else None,
embed = EmbedCreator.create_embed(
embed_type=EmbedType.INFO,
custom_color=discord.Color.gold(),
message_timestamp=original_message.created_at,
custom_author_text=original_message.author.display_name,
custom_author_icon_url=original_message.author.avatar.url if original_message.author.avatar else None,
custom_footer_text=f"{reaction_count} {starboard.starboard_emoji}",
image_url=original_message.attachments[0].url if original_message.attachments else None,
)
embed.add_field(name="Source", value=f"[Jump to message]({original_message.jump_url})")
embed.set_footer(text=f"{reaction_count} {starboard.starboard_emoji}")

if original_message.attachments:
embed.set_image(url=original_message.attachments[0].url)
embed.add_field(name="Source", value=f"[Jump to message]({original_message.jump_url})")

starboard_message = await self.get_existing_starboard_message(starboard_channel, original_message)

Expand Down
7 changes: 2 additions & 5 deletions tux/cogs/utility/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ async def query(self, ctx: commands.Context[Tux], *, search_term: str) -> None:
user_display_avatar=ctx.author.display_avatar.url,
title=f'Answer to "{search_term}"',
description=f"{data['Abstract']}\n\nData from **{data['AbstractURL']}**",
custom_footer_text="Data via DuckDuckGo API.",
custom_footer_icon_url="https://duckduckgo.com/favicon.png",
)

embed.set_author(
Expand All @@ -115,11 +117,6 @@ async def query(self, ctx: commands.Context[Tux], *, search_term: str) -> None:
icon_url=f"https://duckduckgo.com{data['Image']}" if data["Image"] else CONST.EMBED_ICONS["DEFAULT"],
)

embed.set_footer(
text="Data via DuckDuckGo API.",
icon_url="https://duckduckgo.com/favicon.png",
)

if redirect:
embed.add_field(
name="Search Term Changed",
Expand Down
Loading

0 comments on commit a627920

Please sign in to comment.