Skip to content

Commit

Permalink
Streamline discord embed color definition, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jackra1n committed Mar 22, 2024
1 parent 4f181f7 commit 8dabea2
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 40 deletions.
1 change: 1 addition & 0 deletions core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

PRIMARY_COLOR = 0xE3621E
SECONDARY_COLOR = 0x292B3E
CYAN_COLOR = 0x1E9FE3

UPVOTE_EMOTE_ID = 877668616810692608
DOWNVOTE_EMOTE_ID = 877668628261126144
8 changes: 4 additions & 4 deletions extensions/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from discord import app_commands
from discord.ext import commands

from core.bot import Substiify
import core

logger = logging.getLogger(__name__)

Expand All @@ -29,7 +29,7 @@ class FeedbackOutcome(Enum):
class Feedback(commands.Cog):
COG_EMOJI = "📝"

def __init__(self, bot: Substiify):
def __init__(self, bot: core.Substiify):
self.bot = bot

@commands.Cog.listener()
Expand Down Expand Up @@ -151,7 +151,7 @@ async def on_submit(self, interaction: discord.Interaction):
embed = discord.Embed(
title=f"New {self.feedback_type.value} submission",
description=f"```{self.feedback.value}```",
color=0x1E9FE3,
color=core.constants.CYAN_COLOR,
)
embed.set_footer(text=interaction.user, icon_url=interaction.user.avatar)
message = await channel.send(embed=embed)
Expand All @@ -178,5 +178,5 @@ async def on_error(self, interaction: discord.Interaction, error: Exception) ->
logger.error(type(error), error, error.__traceback__)


async def setup(bot: Substiify):
async def setup(bot: core.Substiify):
await bot.add_cog(Feedback(bot))
4 changes: 2 additions & 2 deletions extensions/free_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ async def epic(self, ctx: commands.Context):
logger.error(f"Error while creating 'Game' object: {ex}")

if not current_free_games:
embed = discord.Embed(color=0x000000)
embed = discord.Embed(color=discord.Colour.dark_embed())
embed.description = "Could not find any currently free games"
await ctx.send(embed=embed)

for game in current_free_games:
try:
embed = discord.Embed(title=game.title, url=game.epic_store_link, color=0x000000)
embed = discord.Embed(title=game.title, url=game.epic_store_link, color=discord.Colour.dark_embed())
embed.set_thumbnail(url=f"{EPIC_GAMES_LOGO_URL}")
available_string = (
f"started <t:{int(game.start_date.timestamp())}:R>, ends <t:{int(game.end_date.timestamp())}:R>"
Expand Down
8 changes: 4 additions & 4 deletions extensions/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import discord
from discord.ext import commands

from core.bot import Substiify
import core

logger = logging.getLogger(__name__)


class Fun(commands.Cog):
COG_EMOJI = "🎱"

def __init__(self, bot: Substiify):
def __init__(self, bot: core.Substiify):
self.bot = bot

@commands.command(name="teams", aliases=["team"])
Expand All @@ -35,7 +35,7 @@ async def teams(self, ctx: commands.Context, *, players: str = None):
team_1 = players_list[: len(players_list) // 2]
team_2 = players_list[len(players_list) // 2 :]

embed = discord.Embed(title="Teams", color=0x00FFFF)
embed = discord.Embed(title="Teams", color=discord.Colour.dark_embed())
embed.add_field(name="Team 1", value="\n".join([f"{member} " for member in team_1]))
embed.add_field(name="Team 2", value="\n".join([f"{member} " for member in team_2]))
if ctx.author.voice and players:
Expand Down Expand Up @@ -76,5 +76,5 @@ async def eightball(self, ctx: commands.Context, *, question: str):
await ctx.send(embed=embed)


async def setup(bot: Substiify):
async def setup(bot: core.Substiify):
await bot.add_cog(Fun(bot))
46 changes: 25 additions & 21 deletions extensions/karma.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ async def votes(self, ctx: commands.Context):
Shows if votes are enabled in the current channel
"""
if ctx.channel.id in self.vote_channels:
embed = discord.Embed(color=0x23B40C)
embed = discord.Embed(color=discord.Color.green())
embed.description = f"Votes are **ALREADY enabled** in {ctx.channel.mention}!"
else:
embed = discord.Embed(color=0xF66045)
embed = discord.Embed(color=discord.Color.red())
embed.description = f"Votes are **NOT enabled** in {ctx.channel.mention}!"
await ctx.reply(embed=embed)

Expand All @@ -69,7 +69,7 @@ async def list_votes(self, ctx: commands.Context):
stmt = "SELECT * FROM discord_channel WHERE discord_server_id = $1 AND upvote = True"
upvote_channels = await self.bot.db.fetch(stmt, ctx.guild.id)
channels_string = "\n".join([f"{x['discord_channel_id']} ({x['channel_name']})" for x in upvote_channels])
embed = discord.Embed(color=0x23B40C)
embed = discord.Embed(color=core.constants.PRIMARY_COLOR)
if not channels_string:
embed.description = "No votes channels found."
return await ctx.send(embed=embed)
Expand All @@ -93,17 +93,18 @@ async def start(self, ctx: commands.Context, channel: discord.abc.GuildChannel =
stmt = "SELECT * FROM discord_channel WHERE discord_channel_id = $1 AND upvote = True"
votes_enabled = await self.bot.db.fetch(stmt, channel.id)
logger.info(f"Votes enabled: {votes_enabled}")
if not votes_enabled:
stmt = """INSERT INTO discord_channel (discord_channel_id, channel_name, discord_server_id, parent_discord_channel_id, upvote)
VALUES ($1, $2, $3, $4, $5) ON CONFLICT (discord_channel_id) DO UPDATE SET upvote = $5"""
await self.bot.db.execute(stmt, channel.id, channel.name, channel.guild.id, None, True)
else:
embed = discord.Embed(description=f"Votes are **already active** in {ctx.channel.mention}!", color=0x23B40C)

embed = discord.Embed(color=discord.Colour.green())
if votes_enabled:
embed.description = f"Votes are **already active** in {ctx.channel.mention}!"
return await ctx.send(embed=embed)
embed = discord.Embed(description=f"Votes **enabled** in {channel.mention}!", color=0x23B40C)

stmt = """INSERT INTO discord_channel (discord_channel_id, channel_name, discord_server_id, parent_discord_channel_id, upvote)
VALUES ($1, $2, $3, $4, $5) ON CONFLICT (discord_channel_id) DO UPDATE SET upvote = $5"""
await self.bot.db.execute(stmt, channel.id, channel.name, channel.guild.id, None, True)

embed.description = f"Votes **enabled** in {channel.mention}!"
await ctx.send(embed=embed)
if not ctx.interaction:
await ctx.message.delete()

@votes.command()
@commands.check_any(commands.has_permissions(manage_channels=True), commands.is_owner())
Expand All @@ -120,9 +121,11 @@ async def stop(self, ctx: commands.Context, channel: discord.TextChannel = None)
if channel.id in self.vote_channels:
self.vote_channels.remove(channel.id)

await ctx.send(embed=discord.Embed(description=f"Votes has been stopped in {channel.mention}!", color=0xF66045))
if not ctx.interaction:
await ctx.message.delete()
embed = discord.Embed(
description=f"Votes has been stopped in {channel.mention}!",
color=discord.Colour.red(),
)
await ctx.send(embed=embed)

@commands.group(
aliases=["k"],
Expand All @@ -141,7 +144,8 @@ async def karma(self, ctx: commands.Context, user: discord.User = None):
user = ctx.author

if user.bot:
return await ctx.reply(embed=discord.Embed(description="Bots don't have karma!", color=0xF66045))
embed = discord.Embed(description="Bots don't have karma!", color=discord.Colour.red())
return await ctx.reply(embed=embed)

user_karma = await self._get_user_karma(user.id, ctx.guild.id)
user_karma = 0 if user_karma is None else user_karma
Expand All @@ -152,7 +156,7 @@ async def karma(self, ctx: commands.Context, user: discord.User = None):
@karma.error
async def karma_error(self, ctx: commands.Context, error):
if isinstance(error, commands.BadArgument):
embed = discord.Embed(color=0xF66045, description=error)
embed = discord.Embed(description=error, color=discord.Colour.red())
await ctx.send(embed=embed)

@commands.cooldown(3, 10)
Expand Down Expand Up @@ -185,7 +189,7 @@ async def karma_donate(self, ctx: commands.Context, *args):
)
return await ctx.reply("Could not find a user or amount in the provided arguments.")

embed = discord.Embed(color=0xF66045)
embed = discord.Embed(color=discord.Colour.red())
if user.bot:
embed.description = "You can't donate to bots!"
return await ctx.send(embed=embed)
Expand All @@ -211,7 +215,7 @@ async def karma_donate(self, ctx: commands.Context, *args):
UPDATE_KARMA_QUERY, [(user.id, ctx.guild.id, amount), (ctx.author.id, ctx.guild.id, -amount)]
)

embed = discord.Embed(color=0x23B40C)
embed = discord.Embed(color=discord.Colour.green())
embed.description = f"{ctx.author.mention} has donated {amount} karma to {user.mention}!"
await ctx.send(embed=embed)

Expand All @@ -238,7 +242,7 @@ def pred(m: discord.Member) -> bool:

@karma_donate.error
async def karma_donate_error(self, ctx: commands.Context, error):
embed = discord.Embed(color=0xF66045)
embed = discord.Embed(color=discord.Colour.red())
if isinstance(error, NotEnoughArguments):
embed.description = "You didn't specify an `amount` or a `user` to donate to!"
elif isinstance(error, commands.BadArgument):
Expand Down Expand Up @@ -660,7 +664,7 @@ async def kasino_close_error(self, ctx: commands.Context, error):
if isinstance(error, commands.errors.MissingRequiredArgument):
msg = f"You didn't provide a required argument!\nCorrect usage is `{ctx.prefix}kasino close <kasino_id> <winning_option>`"
msg += "\nUse option `3` to close and abort the kasino (no winner)."
embed = discord.Embed(description=msg, color=0xF66045)
embed = discord.Embed(description=msg, color=discord.Colour.red())
await ctx.send(embed=embed)
elif isinstance(error, commands.errors.BadArgument):
await ctx.send(f"Bad argument: {error}")
Expand Down
11 changes: 5 additions & 6 deletions extensions/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
from discord import ButtonStyle, Interaction, ui
from discord.ext import commands

import core
import utils
from core import config
from core.bot import Substiify

logger = logging.getLogger(__name__)

EMBED_COLOR = 0x292B3E
EMBED_COLOR = core.constants.CYAN_COLOR


class Music(commands.Cog):
COG_EMOJI = "🎵"

def __init__(self, bot: Substiify):
def __init__(self, bot: core.Substiify):
self.bot = bot

async def cog_command_error(self, ctx, error):
Expand Down Expand Up @@ -421,8 +420,8 @@ def __init__(self):
super().__init__("No playing agent is available at the moment. Please try again later or contact support.")


async def setup(bot: Substiify):
if all([config.LAVALINK_NODE_URL, config.LAVALINK_PASSWORD]):
async def setup(bot: core.Substiify):
if all([core.config.LAVALINK_NODE_URL, core.config.LAVALINK_PASSWORD]):
await bot.add_cog(Music(bot))
else:
logger.warning("Lavalink is not configured. Skipping Music cog.")
2 changes: 1 addition & 1 deletion extensions/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def shutdown(self, ctx: commands.Context):
"""
Shuts down the bot. Made this in case something goes wrong.
"""
embed = discord.Embed(description="Shutting down...", color=0xF66045)
embed = discord.Embed(description="Shutting down...", color=discord.Colour.red())
await ctx.send(embed=embed)
await self.bot.close()

Expand Down
12 changes: 10 additions & 2 deletions extensions/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ def convert(self, time):
return time_val * time_dict[unit]

def create_giveaway_embed(self, author: discord.Member, prize):
embed = discord.Embed(title=":tada: Giveaway :tada:", description=f"Win **{prize}**!", color=0x00FFFF)
embed = discord.Embed(
title=":tada: Giveaway :tada:",
description=f"Win **{prize}**!",
color=core.constants.CYAN_COLOR,
)
host = author.mention if isinstance(author, (discord.Member, discord.User)) else author
embed.add_field(name="Hosted By:", value=host)
return embed
Expand All @@ -243,7 +247,11 @@ async def avatar(self, ctx: commands.Context, member: discord.Member | discord.U
"""
member = member or ctx.author
current_avatar = member.display_avatar
embed = discord.Embed(title=f"{str(member.display_name)}'s avatar", url=current_avatar.url, color=0x1E9FE3)
embed = discord.Embed(
title=f"{member.display_name}'s avatar",
url=current_avatar.url,
color=core.constants.CYAN_COLOR,
)
embed.set_image(url=current_avatar.url)
await ctx.send(embed=embed)

Expand Down

0 comments on commit 8dabea2

Please sign in to comment.