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

Add /config show

This commit is contained in:
wlinator 2024-08-30 04:21:10 -04:00
parent b36a9ae1b6
commit 9e35ee1fa5
4 changed files with 152 additions and 84 deletions

View file

@ -1,4 +1,6 @@
import os
from collections.abc import Mapping
from pathlib import Path
from typing import Any
from discord.ext import commands
@ -30,15 +32,21 @@ class LumiHelp(commands.HelpCommand):
hide_name_in_description=True,
)
for cog, lumi_commands in mapping.items():
filtered: list[commands.Command[Any, Any, Any]] = await self.filter_commands(lumi_commands, sort=True)
modules_dir = Path(__file__).parent.parent / "modules"
module_names = [name for name in os.listdir(modules_dir) if Path(modules_dir / name).is_dir()]
if command_signatures := [self.get_command_qualified_name(c) for c in filtered]:
# Remove duplicates using set() and convert back to a list
unique_command_signatures: list[str] = list(set(command_signatures))
cog_name: str = getattr(cog, "qualified_name", "Help")
for module_name in module_names:
module_commands: list[commands.Command[Any, ..., Any]] = []
for cog, lumi_commands in mapping.items():
if cog and cog.__module__.startswith(f"modules.{module_name}"):
filtered = await self.filter_commands(lumi_commands, sort=True)
module_commands.extend(filtered)
if module_commands:
command_signatures = [self.get_command_qualified_name(c) for c in module_commands]
unique_command_signatures = list(set(command_signatures))
embed.add_field(
name=cog_name,
name=module_name.capitalize(),
value=", ".join(sorted(unique_command_signatures)),
inline=False,
)

View file

@ -1,11 +0,0 @@
from discord.ext import commands
from modules.config.c_birthday import BirthdayConfig
class Config(BirthdayConfig, group_name="config"):
pass
async def setup(bot: commands.Bot) -> None:
await bot.add_cog(Config(bot))

View file

@ -1,66 +0,0 @@
import discord
from discord import app_commands
from discord.ext import commands
from lib.const import CONST
from services.config_service import GuildConfig
from ui.embeds import Builder
class BirthdayConfig(commands.GroupCog, group_name="config"):
def __init__(self, bot: commands.Bot):
self.bot = bot
birthday = app_commands.Group(name="birthday", description="Birthday commands")
@birthday.command(name="channel", description="Set the birthday announcement channel")
@app_commands.describe(channel="The channel to set for birthday announcements")
async def birthday_channel(self, interaction: discord.Interaction, channel: discord.TextChannel) -> None:
if not interaction.guild:
return
guild_config = GuildConfig(interaction.guild.id)
guild_config.birthday_channel_id = channel.id
guild_config.push()
embed = Builder.create_embed(
theme="success",
user_name=interaction.user.name,
author_text=CONST.STRINGS["config_author"],
description=CONST.STRINGS["config_birthday_channel_set"].format(
channel.mention,
),
)
await interaction.response.send_message(embed=embed)
@birthday.command(name="disable", description="Disable the birthday module")
async def birthday_disable(self, interaction: discord.Interaction) -> None:
if not interaction.guild:
return
guild_config = GuildConfig(interaction.guild.id)
if not guild_config.birthday_channel_id:
embed = Builder.create_embed(
theme="warning",
user_name=interaction.user.name,
author_text=CONST.STRINGS["config_author"],
description=CONST.STRINGS["config_birthday_module_already_disabled"],
)
else:
embed = Builder.create_embed(
theme="success",
user_name=interaction.user.name,
author_text=CONST.STRINGS["config_author"],
description=CONST.STRINGS["config_birthday_module_disabled"],
)
guild_config.birthday_channel_id = None
guild_config.push()
await interaction.response.send_message(embed=embed)
async def setup(bot: commands.Bot) -> None:
await bot.add_cog(BirthdayConfig(bot))

137
modules/config/config.py Normal file
View file

@ -0,0 +1,137 @@
import discord
from discord import app_commands
from discord.ext import commands
from lib.const import CONST
from services.config_service import GuildConfig
from services.modlog_service import ModLogService
from ui.embeds import Builder
@app_commands.guild_only()
@app_commands.default_permissions(administrator=True)
class Config(commands.GroupCog, group_name="config"):
def __init__(self, bot: commands.Bot):
self.bot = bot
birthdays = app_commands.Group(name="birthdays", description="Birthday commands")
levels = app_commands.Group(name="levels", description="Level commands")
moderation = app_commands.Group(name="moderation", description="Moderation commands")
prefix = app_commands.Group(name="prefix", description="Prefix commands")
boosts = app_commands.Group(name="boosts", description="Boost commands")
greets = app_commands.Group(name="greets", description="Greet commands")
@app_commands.command(name="show")
async def config_help(self, interaction: discord.Interaction) -> None:
assert interaction.guild
guild_config: GuildConfig = GuildConfig(interaction.guild.id)
guild: discord.Guild = interaction.guild
embed: discord.Embed = Builder.create_embed(
theme="success",
user_name=interaction.user.name,
author_text=CONST.STRINGS["config_show_author"].format(guild.name),
thumbnail_url=guild.icon.url if guild.icon else CONST.LUMI_LOGO_TRANSPARENT,
hide_name_in_description=True,
)
config_items: list[tuple[str, bool, bool]] = [
(
CONST.STRINGS["config_show_birthdays"],
bool(guild_config.birthday_channel_id),
False,
),
(
CONST.STRINGS["config_show_new_member_greets"],
bool(guild_config.welcome_channel_id),
False,
),
(
CONST.STRINGS["config_show_boost_announcements"],
bool(guild_config.boost_channel_id),
False,
),
(
CONST.STRINGS["config_show_level_announcements"],
guild_config.level_message_type != 0,
False,
),
]
for name, enabled, default_enabled in config_items:
status: str = CONST.STRINGS["config_show_enabled"] if enabled else CONST.STRINGS["config_show_disabled"]
if not enabled and default_enabled:
status = CONST.STRINGS["config_show_default_enabled"]
embed.add_field(name=name, value=status, inline=False)
modlog_service: ModLogService = ModLogService()
modlog_channel_id: int | None = modlog_service.fetch_modlog_channel_id(guild.id)
modlog_channel = guild.get_channel(modlog_channel_id) if modlog_channel_id else None
modlog_status: str
if modlog_channel:
modlog_status = CONST.STRINGS["config_show_moderation_log_enabled"].format(
modlog_channel.mention,
)
elif modlog_channel_id:
modlog_status = CONST.STRINGS["config_show_moderation_log_channel_deleted"]
else:
modlog_status = CONST.STRINGS["config_show_moderation_log_not_configured"]
embed.add_field(
name=CONST.STRINGS["config_show_moderation_log"],
value=modlog_status,
inline=False,
)
await interaction.response.send_message(embed=embed)
@birthdays.command(name="channel", description="The channel to set for birthday announcements")
async def birthday_channel(self, interaction: discord.Interaction, channel: discord.TextChannel) -> None:
if not interaction.guild:
return
guild_config = GuildConfig(interaction.guild.id)
guild_config.birthday_channel_id = channel.id
guild_config.push()
embed = Builder.create_embed(
theme="success",
user_name=interaction.user.name,
author_text=CONST.STRINGS["config_author"],
description=CONST.STRINGS["config_birthday_channel_set"].format(
channel.mention,
),
)
await interaction.response.send_message(embed=embed)
@birthdays.command(name="disable")
async def birthday_disable(self, interaction: discord.Interaction) -> None:
if not interaction.guild:
return
guild_config = GuildConfig(interaction.guild.id)
if not guild_config.birthday_channel_id:
embed = Builder.create_embed(
theme="warning",
user_name=interaction.user.name,
author_text=CONST.STRINGS["config_author"],
description=CONST.STRINGS["config_birthday_module_already_disabled"],
)
else:
embed = Builder.create_embed(
theme="success",
user_name=interaction.user.name,
author_text=CONST.STRINGS["config_author"],
description=CONST.STRINGS["config_birthday_module_disabled"],
)
guild_config.birthday_channel_id = None
guild_config.push()
await interaction.response.send_message(embed=embed)
async def setup(bot: commands.Bot) -> None:
await bot.add_cog(Config(bot))