1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 18:03:12 +00:00

Add the option to choose the booster image

This commit is contained in:
wlinator 2024-04-26 08:54:08 -04:00
parent b67fece334
commit 543d9fbc47
7 changed files with 56 additions and 10 deletions

View file

@ -14,6 +14,6 @@
"streak_gold": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_streak_gold.png?_=1",
"money_bag": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_money_bag.png?_=1",
"money_coins": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_money_coins.png?_=1",
"boost": "https://gitlab.com/wlinator/Racu/-/raw/main/art/racu_boost.png"
"boost": "https://gitlab.com/wlinator/Racu/-/raw/booster_announcements/art/racu_boost.png"
}
}

View file

@ -84,6 +84,7 @@ CREATE TABLE guild_config (
welcome_message TEXT,
boost_channel_id BIGINT,
boost_message TEXT,
boost_image_url TEXT,
level_channel_id BIGINT, /* level-up messages, if NULL the level-up message will be shown in current msg channel*/
level_message TEXT, /* if NOT NULL and LEVEL_TYPE = 2, this can be a custom level up message. */
level_message_type TINYINT(1) NOT NULL DEFAULT 1, /* 0: no level up messages, 1: levels.en-US.json, 2: generic message */

View file

@ -41,7 +41,7 @@ class EventHandler(Cog):
if not config.boost_channel_id:
return
embed = lib.embeds.boost.Boost.message(member, config.boost_message)
embed = lib.embeds.boost.Boost.message(member, config.boost_message, config.boost_image_url)
try:
await member.guild.get_channel(config.boost_channel_id).send(embed=embed, content=member.mention)

View file

@ -10,7 +10,7 @@ boost_icon = resources["icons"]["boost"]
class Boost:
@staticmethod
def message(member, template=None):
def message(member, template=None, image_url=None):
embed = discord.Embed(
color=discord.Color.nitro_pink(),
title="New Booster",
@ -22,7 +22,7 @@ class Boost:
embed.description = lib.formatter.template(template, member.name)
embed.set_author(name=member.name, icon_url=member.display_avatar)
embed.set_thumbnail(url=boost_icon)
embed.set_image(url=image_url if image_url else boost_icon)
embed.set_footer(text=f"Total server boosts: {member.guild.premium_subscription_count}",
icon_url=exclam_icon)

View file

@ -23,8 +23,6 @@ class GenericErrors:
def default_exception(ctx):
embed = clean_error_embed(ctx)
embed.description += "something went wrong."
embed.set_footer(text=f"For more info do {formatter.get_prefix(ctx)}help {formatter.get_invoked_name(ctx)}",
icon_url=question_icon)
return embed
@ -37,6 +35,13 @@ class GenericErrors:
return embed
@staticmethod
def bad_url(ctx, error="the image URL must end with `.jpg` or `.png`."):
embed = clean_error_embed(ctx)
embed.description += formatter.shorten(str(error), 100)
return embed
@staticmethod
def missing_permissions(ctx):
embed = clean_error_embed(ctx)

View file

@ -8,6 +8,7 @@ from config.parser import JsonCache
from lib import formatter
from lib.embeds.greet import Greet
from lib.embeds.boost import Boost
from lib.embeds.error import GenericErrors
from modules.config import config, set_prefix, xp_reward
from services.GuildConfig import GuildConfig
@ -336,7 +337,42 @@ class Config(commands.Cog):
embed.set_author(name="Server Configuration", icon_url=guild_icon)
await ctx.respond(embed=embed)
embed = Boost.message(ctx.author, text)
embed = Boost.message(ctx.author, text, guild_config.boost_image_url)
return await ctx.send(embed=embed, content=ctx.author.mention)
@boost_config.command(
name="image",
description="Add a custom image that will used for booster announcements."
)
async def config_boosts_image(self, ctx, *, image_url: str):
guild_config = GuildConfig(ctx.guild.id)
if image_url.lower() == "original":
guild_config.boost_image_url = None
guild_config.push()
image_url = None
elif not image_url.endswith(".jpg") and not image_url.lower().endswith(".png"):
return await ctx.respond(embed=GenericErrors.bad_url(ctx))
elif not image_url.startswith("http://") and not image_url.startswith("https://"):
return await ctx.respond(embed=GenericErrors.bad_url(ctx, "invalid URL."))
else:
guild_config.boost_image_url = image_url
guild_config.push()
embed = discord.Embed(
color=discord.Color.orange(),
description=f"✅ | The booster image was successfully updated."
)
guild_icon = ctx.guild.icon if ctx.guild.icon else "https://i.imgur.com/79XfsbS.png"
embed.add_field(name="Image", value=image_url if image_url else "Original Image", inline=False)
embed.add_field(name="Example", value="An example will be sent in a separate message.", inline=False)
embed.set_author(name="Server Configuration", icon_url=guild_icon)
await ctx.respond(embed=embed)
embed = Boost.message(ctx.author, guild_config.boost_message, image_url)
return await ctx.send(embed=embed, content=ctx.author.mention)
@level_config.command(

View file

@ -11,6 +11,7 @@ class GuildConfig:
self.welcome_message = None
self.boost_channel_id = None
self.boost_message = None
self.boost_image_url = None
self.level_channel_id = None
self.level_message = None
self.level_message_type = 1
@ -24,13 +25,14 @@ class GuildConfig:
query = """
SELECT birthday_channel_id, command_channel_id, intro_channel_id,
welcome_channel_id, welcome_message, boost_channel_id,
boost_message, level_channel_id, level_message, level_message_type
boost_message, boost_image_url, level_channel_id,
level_message, level_message_type
FROM guild_config WHERE guild_id = %s
"""
try:
(birthday_channel_id, command_channel_id, intro_channel_id,
welcome_channel_id, welcome_message, boost_channel_id, boost_message,
welcome_channel_id, welcome_message, boost_channel_id, boost_message, boost_image_url,
level_channel_id, level_message, level_message_type) = \
database.select_query(query, (self.guild_id,))[0]
@ -41,6 +43,7 @@ class GuildConfig:
self.welcome_message = welcome_message
self.boost_channel_id = boost_channel_id
self.boost_message = boost_message
self.boost_image_url = boost_image_url
self.level_channel_id = level_channel_id
self.level_message = level_message
self.level_message_type = level_message_type
@ -61,6 +64,7 @@ class GuildConfig:
welcome_message = %s,
boost_channel_id = %s,
boost_message = %s,
boost_image_url = %s,
level_channel_id = %s,
level_message = %s,
level_message_type = %s
@ -69,7 +73,7 @@ class GuildConfig:
database.execute_query(query, (self.birthday_channel_id, self.command_channel_id,
self.intro_channel_id, self.welcome_channel_id, self.welcome_message,
self.boost_channel_id, self.boost_message,
self.boost_channel_id, self.boost_message, self.boost_image_url,
self.level_channel_id, self.level_message,
self.level_message_type, self.guild_id))