From 50da9fcf24efd0f39b7b907ace43d5a217038d3c Mon Sep 17 00:00:00 2001 From: wlinator Date: Sat, 3 Aug 2024 13:33:01 -0400 Subject: [PATCH] chore: Add birthday module configuration commands --- config/JSON/strings.json | 4 ++ modules/config/__init__.py | 96 ++------------------------- modules/config/c_birthday.py | 42 ++++++++++++ modules/config/{show.py => c_show.py} | 0 4 files changed, 52 insertions(+), 90 deletions(-) create mode 100644 modules/config/c_birthday.py rename modules/config/{show.py => c_show.py} (100%) diff --git a/config/JSON/strings.json b/config/JSON/strings.json index 7dc5feb..a729db2 100644 --- a/config/JSON/strings.json +++ b/config/JSON/strings.json @@ -22,6 +22,7 @@ "case_type_field": "Type:", "case_type_field_value": "`{0}`", "case_type_field_value_with_duration": "`{0} ({1})`", + "config_author": "Server Configuration", "config_show_author": "{0} Configuration", "config_show_birthdays": "Birthdays", "config_show_boost_announcements": "Boost announcements", @@ -35,6 +36,9 @@ "config_show_moderation_log_enabled": "✅ {0}", "config_show_moderation_log_not_configured": "⚠️ **Not configured yet**", "config_show_new_member_greets": "New member greets", + "config_birthday_channel_set": "birthday announcements will be sent in {0}.", + "config_birthday_module_already_disabled": "the birthday module was already disabled.", + "config_birthday_module_disabled": "the birthday module was successfully disabled.", "daily_already_claimed_author": "Already Claimed", "daily_already_claimed_description": "you can claim your daily reward again .", "daily_already_claimed_footer": "Daily reset is at 7 AM EST", diff --git a/modules/config/__init__.py b/modules/config/__init__.py index f98444f..3b7727f 100644 --- a/modules/config/__init__.py +++ b/modules/config/__init__.py @@ -7,7 +7,7 @@ from lib import formatter from lib.embeds.boost import Boost from lib.embeds.error import GenericErrors from lib.embeds.greet import Greet -from modules.config import show, set_prefix, xp_reward +from modules.config import c_show, c_birthday, set_prefix, xp_reward from services.config_service import GuildConfig strings = JsonCache.read_json("strings") @@ -78,8 +78,6 @@ class Config(commands.Cog): Only members with "manage guild" permissions can access commands in this group. - Birthdays - - Commands - - Intros - Welcome - Boosts - Levels @@ -96,103 +94,21 @@ class Config(commands.Cog): default_member_permissions=discord.Permissions(manage_guild=True), ) birthday_config = config.create_subgroup(name="birthdays") - command_config = config.create_subgroup(name="commands") - intro_config = config.create_subgroup(name="intros") welcome_config = config.create_subgroup(name="greetings") boost_config = config.create_subgroup(name="boosts") level_config = config.create_subgroup(name="levels") @config.command(name="show") async def config_command(self, ctx): - await show.cmd(ctx) + await c_show.cmd(ctx) - @birthday_config.command( - name="channel", - description="Set the birthday announcements channel.", - ) + @birthday_config.command(name="channel") async def config_birthdays_channel(self, ctx, *, channel: discord.TextChannel): - guild_config = GuildConfig(ctx.guild.id) - guild_config.birthday_channel_id = channel.id - guild_config.push() + await c_birthday.set_birthday_channel(ctx, channel) - embed = discord.Embed( - color=discord.Color.orange(), - description=f"✅ | Birthday announcements will be sent in {channel.mention}.", - ) - guild_icon = ( - ctx.guild.icon if ctx.guild.icon else "https://i.imgur.com/79XfsbS.png" - ) - embed.set_author(name="Server Configuration", icon_url=guild_icon) - - return await ctx.respond(embed=embed) - - @birthday_config.command( - name="disable", - description="Disable the birthday module.", - ) + @birthday_config.command(name="disable") async def config_birthdays_disable(self, ctx): - guild_config = GuildConfig(ctx.guild.id) - - embed = discord.Embed( - color=discord.Color.orange(), - ) - guild_icon = ( - ctx.guild.icon if ctx.guild.icon else "https://i.imgur.com/79XfsbS.png" - ) - embed.set_author(name="Server Configuration", icon_url=guild_icon) - - if not guild_config.birthday_channel_id: - embed.description = "👍 | The birthday module was already disabled." - return await ctx.respond(embed=embed) - - else: - guild_config.birthday_channel_id = None - guild_config.push() - embed.description = "✅ | The birthday module was successfully disabled." - return await ctx.respond(embed=embed) - - @command_config.command( - name="channel", - description="Configure where members can use Lumi commands.", - ) - async def config_commands_channel(self, ctx, *, channel: discord.TextChannel): - guild_config = GuildConfig(ctx.guild.id) - guild_config.command_channel_id = channel.id - guild_config.push() - - embed = discord.Embed( - color=discord.Color.orange(), - description=f"✅ | Commands can now only be used in {channel.mention}.", - ) - guild_icon = ( - ctx.guild.icon if ctx.guild.icon else "https://i.imgur.com/79XfsbS.png" - ) - embed.set_author(name="Server Configuration", icon_url=guild_icon) - embed.set_footer( - text="Note: mod & config commands are still available everywhere.", - ) - - return await ctx.respond(embed=embed) - - @command_config.command( - name="everywhere", - description="Allow members to do commands in all channels.", - ) - async def config_commands_everywhere(self, ctx): - guild_config = GuildConfig(ctx.guild.id) - guild_config.command_channel_id = None - guild_config.push() - - embed = discord.Embed( - color=discord.Color.orange(), - description="✅ | Server members can now use Lumi commands in all channels. ", - ) - guild_icon = ( - ctx.guild.icon if ctx.guild.icon else "https://i.imgur.com/79XfsbS.png" - ) - embed.set_author(name="Server Configuration", icon_url=guild_icon) - - return await ctx.respond(embed=embed) + await c_birthday.disable_birthday_module(ctx) @welcome_config.command( name="channel", diff --git a/modules/config/c_birthday.py b/modules/config/c_birthday.py new file mode 100644 index 0000000..0bf4d93 --- /dev/null +++ b/modules/config/c_birthday.py @@ -0,0 +1,42 @@ +import discord +from lib.embed_builder import EmbedBuilder +from lib.constants import CONST +from services.config_service import GuildConfig + + +async def set_birthday_channel(ctx, channel: discord.TextChannel): + guild_config = GuildConfig(ctx.guild.id) + guild_config.birthday_channel_id = channel.id + guild_config.push() + + embed = EmbedBuilder().create_success_embed( + ctx=ctx, + author_text=CONST.STRINGS["config_author"], + description=CONST.STRINGS["config_birthday_channel_set"].format( + channel.mention, + ), + ) + + return await ctx.respond(embed=embed) + + +async def disable_birthday_module(ctx): + guild_config = GuildConfig(ctx.guild.id) + + if not guild_config.birthday_channel_id: + embed = EmbedBuilder().create_warning_embed( + ctx=ctx, + author_text=CONST.STRINGS["config_author"], + description=CONST.STRINGS["config_birthday_module_already_disabled"], + ) + + else: + embed = EmbedBuilder().create_success_embed( + ctx=ctx, + author_text=CONST.STRINGS["config_author"], + description=CONST.STRINGS["config_birthday_module_disabled"], + ) + guild_config.birthday_channel_id = None + guild_config.push() + + return await ctx.respond(embed=embed) diff --git a/modules/config/show.py b/modules/config/c_show.py similarity index 100% rename from modules/config/show.py rename to modules/config/c_show.py