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

Refactor greet module to use new configuration structure

This commit is contained in:
wlinator 2024-08-15 04:47:42 -04:00
parent ebd1f95eba
commit c1e2413869
6 changed files with 23 additions and 110 deletions

View file

@ -1,4 +1,6 @@
{
"greet_default_description": "_ _\n**Welcome** to **{0}**",
"greet_template_description": "↓↓↓\n{0}",
"boost_default_title": "New Booster",
"boost_default_description": "Thanks for boosting, **{0}**!!",
"lumi_exception_generic": "An error occurred.",

View file

@ -1,8 +1,7 @@
from discord.ext.commands import Cog
from loguru import logger
from modules.config import c_boost
from lib.embeds.greet import Greet
from modules.config import c_boost, c_greet
from services.blacklist_service import BlacklistUserService
from services.config_service import GuildConfig
@ -21,7 +20,7 @@ class EventHandler(Cog):
if not config.welcome_channel_id:
return
embed = Greet.message(member, config.welcome_message)
embed = c_greet.create_greet_embed(member, config.welcome_message)
try:
await member.guild.get_channel(config.welcome_channel_id).send(

View file

@ -1,25 +0,0 @@
import discord
from config.parser import JsonCache
from lib import formatter
resources = JsonCache.read_json("art")
question_icon = resources["icons"]["question"]
exclaim_icon = resources["icons"]["exclaim"]
class Greet:
@staticmethod
def message(member, template=None):
embed = discord.Embed(
color=discord.Color.embed_background(),
description=f"_ _\n**Welcome** to **{member.guild.name}**",
)
if template:
embed.description += "↓↓↓\n" + formatter.template(template, member.name)
embed.set_thumbnail(url=member.display_avatar)
return embed

View file

@ -1,77 +0,0 @@
import discord
from config.parser import JsonCache
from lib import formatter
resources = JsonCache.read_json("art")
question_icon = resources["icons"]["question"]
exclaim_icon = resources["icons"]["exclaim"]
streak_icon = resources["icons"]["streak"]
def clean_info_embed(ctx):
embed = discord.Embed(
color=discord.Color.blurple(),
description=f"**{ctx.author.name}** ",
)
return embed
class MiscInfo:
@staticmethod
def ping(ctx, client):
embed = clean_info_embed(ctx)
embed.description += "I'm online!"
embed.set_footer(
text=f"Latency: {round(1000 * client.latency)}ms",
icon_url=exclaim_icon,
)
return embed
@staticmethod
def uptime(ctx, client, unix_time):
embed = clean_info_embed(ctx)
embed.description += f"I've been online since <t:{unix_time}:R>"
embed.set_footer(
text=f"Latency: {round(1000 * client.latency)}ms",
icon_url=exclaim_icon,
)
return embed
@staticmethod
def set_prefix(ctx, prefix):
embed = clean_info_embed(ctx)
embed.description += f"my prefix changed to `{prefix}`"
return embed
@staticmethod
def get_prefix(ctx, prefix):
embed = clean_info_embed(ctx)
embed.description += f"my prefix is `{prefix}`"
embed.set_footer(
text=f"You can change this with '{formatter.get_prefix(ctx)}setprefix'",
icon_url=question_icon,
)
return embed
class BdayInfo:
@staticmethod
def set_month(ctx, month, day):
embed = clean_info_embed(ctx)
embed.description += f"your birthday was set to {month} {day}."
return embed
@staticmethod
def delete(ctx):
embed = clean_info_embed(ctx)
embed.description += "your birthday was deleted from this server."
return embed

View file

@ -10,7 +10,6 @@ from services.birthday_service import Birthday
async def add(ctx, month, month_index, day):
"""Set a user's birthday in a specific guild."""
leap_year = 2020
max_days = calendar.monthrange(leap_year, month_index)[1]
@ -35,7 +34,6 @@ async def add(ctx, month, month_index, day):
async def delete(ctx):
"""Delete a user's birthday in a specific server."""
Birthday(ctx.author.id, ctx.guild.id).delete()
embed = EmbedBuilder.create_success_embed(
@ -48,7 +46,6 @@ async def delete(ctx):
async def upcoming(ctx):
"""Get the upcoming birthdays for a specific server."""
upcoming_birthdays = Birthday.get_upcoming_birthdays(ctx.guild.id)
if not upcoming_birthdays:

View file

@ -2,7 +2,7 @@ import discord
from lib.embed_builder import EmbedBuilder
from lib.constants import CONST
from services.config_service import GuildConfig
from lib.embeds.greet import Greet
import lib.formatter
async def set_welcome_channel(ctx, channel: discord.TextChannel):
@ -60,5 +60,22 @@ async def set_welcome_template(ctx, text: str):
await ctx.respond(embed=embed)
example_embed = Greet.message(ctx.author, text)
example_embed = create_greet_embed(ctx.author, text)
return await ctx.send(embed=example_embed, content=ctx.author.mention)
async def create_greet_embed(member: discord.Member, template: str | None = None):
embed = discord.Embed(
color=discord.Color.embed_background(),
description=CONST.STRINGS["greet_default_description"].format(
member.guild.name,
),
)
if template and embed.description is not None:
embed.description += CONST.STRINGS["greet_template_description"].format(
lib.formatter.template(template, member.name),
)
embed.set_thumbnail(url=member.display_avatar)
return embed