mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 18:03:12 +00:00
chore: Update config show command to display server configuration options
This commit is contained in:
parent
e3bd957609
commit
c009fd5412
5 changed files with 112 additions and 195 deletions
|
@ -22,12 +22,26 @@
|
|||
"case_type_field": "Type:",
|
||||
"case_type_field_value": "`{0}`",
|
||||
"case_type_field_value_with_duration": "`{0} ({1})`",
|
||||
"config_show_author": "{0} Configuration",
|
||||
"config_show_birthdays": "Birthdays",
|
||||
"config_show_boost_announcements": "Boost announcements",
|
||||
"config_show_default_enabled": "✅ Enabled (default)",
|
||||
"config_show_disabled": "❌ Disabled",
|
||||
"config_show_enabled": "✅ Enabled",
|
||||
"config_show_guide": "Guide: {0}",
|
||||
"config_show_level_announcements": "Level announcements",
|
||||
"config_show_moderation_log": "Moderation Log",
|
||||
"config_show_moderation_log_channel_deleted": "⚠️ **Not configured** (channel deleted?)",
|
||||
"config_show_moderation_log_enabled": "✅ {0}",
|
||||
"config_show_moderation_log_not_configured": "⚠️ **Not configured yet**",
|
||||
"config_show_new_member_greets": "New member greets",
|
||||
"daily_already_claimed_author": "Already Claimed",
|
||||
"daily_already_claimed_description": "you can claim your daily reward again <t:{0}:R>.",
|
||||
"daily_already_claimed_footer": "Daily reset is at 7 AM EST",
|
||||
"daily_streak_footer": "You're on a streak of {0} days",
|
||||
"daily_success_claim_author": "Reward Claimed",
|
||||
"daily_success_claim_description": "you claimed your reward of **${0}**!",
|
||||
"default_level_up_message": "**{0}** you have reached **Level {1}**.",
|
||||
"error_actionable_hierarchy_bot": "I don't have permission to perform this action on this user due to role hierarchy.",
|
||||
"error_actionable_hierarchy_user": "you don't have permission to perform this action on this user due to role hierarchy.",
|
||||
"error_actionable_self": "you can't perform this action on yourself.",
|
||||
|
|
|
@ -36,6 +36,9 @@ class Constants:
|
|||
MARIADB_ROOT_PASSWORD: Optional[str] = os.environ.get("MARIADB_ROOT_PASSWORD", None)
|
||||
MARIADB_DATABASE: Optional[str] = os.environ.get("MARIADB_DATABASE", None)
|
||||
|
||||
# config
|
||||
CONFIG_GUIDE_URL = "https://wiki.wlinator.org/serverconfig"
|
||||
|
||||
# emotes
|
||||
EMOTES_GUILD_ID = 1038051105642401812
|
||||
|
||||
|
|
|
@ -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 config, set_prefix, xp_reward
|
||||
from modules.config import show, set_prefix, xp_reward
|
||||
from services.config_service import GuildConfig
|
||||
|
||||
strings = JsonCache.read_json("strings")
|
||||
|
@ -17,19 +17,6 @@ class Config(commands.Cog):
|
|||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
@bridge.bridge_command(
|
||||
name="configuration",
|
||||
aliases=["config"],
|
||||
description="Show your server configuration.",
|
||||
help="Shows information about how Lumi is configured in your server. "
|
||||
"[Read the guide](https://wiki.wlinator.org/serverconfig).",
|
||||
guild_only=True,
|
||||
)
|
||||
@commands.guild_only()
|
||||
@commands.has_permissions(manage_channels=True)
|
||||
async def config_command(self, ctx):
|
||||
await config.cmd(self, ctx)
|
||||
|
||||
@bridge.bridge_command(
|
||||
name="setprefix",
|
||||
aliases=["sp"],
|
||||
|
@ -85,13 +72,28 @@ class Config(commands.Cog):
|
|||
await xp_reward.remove_reward(ctx, level)
|
||||
|
||||
"""
|
||||
The guild config code is a mess.
|
||||
CONFIG GROUPS
|
||||
The 'config' group consists of many different configuration types, each being guild-specific and guild-only.
|
||||
All commands in this group are exclusively available as slash-commands.
|
||||
Only members with "manage guild" permissions can access commands in this group.
|
||||
|
||||
- Birthdays
|
||||
- Commands
|
||||
- Intros
|
||||
- Welcome
|
||||
- Boosts
|
||||
- Levels
|
||||
- Modlog channel
|
||||
- XP rewards
|
||||
- Permissions preset (coming soon)
|
||||
|
||||
Running '/config show' will show a list of all available configuration types.
|
||||
"""
|
||||
config = SlashCommandGroup(
|
||||
"config",
|
||||
"server config commands.",
|
||||
guild_only=True,
|
||||
default_member_permissions=discord.Permissions(manage_channels=True),
|
||||
default_member_permissions=discord.Permissions(manage_guild=True),
|
||||
)
|
||||
birthday_config = config.create_subgroup(name="birthdays")
|
||||
command_config = config.create_subgroup(name="commands")
|
||||
|
@ -100,6 +102,10 @@ class Config(commands.Cog):
|
|||
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)
|
||||
|
||||
@birthday_config.command(
|
||||
name="channel",
|
||||
description="Set the birthday announcements channel.",
|
||||
|
@ -188,47 +194,6 @@ class Config(commands.Cog):
|
|||
|
||||
return await ctx.respond(embed=embed)
|
||||
|
||||
# @intro_config.command(
|
||||
# name="channel",
|
||||
# description="Set the introductions channel."
|
||||
# )
|
||||
# async def config_intros_channel(self, ctx, *, channel: discord.TextChannel):
|
||||
# guild_config = GuildConfig(ctx.guild.id)
|
||||
# guild_config.intro_channel_id = channel.id
|
||||
# guild_config.push()
|
||||
#
|
||||
# embed = discord.Embed(
|
||||
# color=discord.Color.orange(),
|
||||
# description=f"✅ | New introductions 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)
|
||||
#
|
||||
# @intro_config.command(
|
||||
# name="disable",
|
||||
# introduction="Disable the introductions module."
|
||||
# )
|
||||
# async def config_intros_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.intro_channel_id:
|
||||
# embed.description = "👍 | The introductions module was already disabled."
|
||||
# return await ctx.respond(embed=embed)
|
||||
#
|
||||
# else:
|
||||
# guild_config.intro_channel_id = None
|
||||
# guild_config.push()
|
||||
# embed.description = "✅ | The introductions module was successfully disabled."
|
||||
# return await ctx.respond(embed=embed)
|
||||
|
||||
@welcome_config.command(
|
||||
name="channel",
|
||||
description="Set the greeting announcements channel.",
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
import discord
|
||||
|
||||
from config.parser import JsonCache
|
||||
from services.config_service import GuildConfig
|
||||
|
||||
strings = JsonCache.read_json("strings")
|
||||
|
||||
|
||||
async def cmd(self, ctx):
|
||||
guild_config = GuildConfig(ctx.guild.id)
|
||||
|
||||
embed = discord.Embed(
|
||||
color=discord.Color.embed_background(),
|
||||
description="Guide: https://wiki.wlinator.org/serverconfig",
|
||||
)
|
||||
icon = ctx.guild.icon if ctx.guild.icon else "https://i.imgur.com/79XfsbS.png"
|
||||
embed.set_author(name=f"{ctx.guild.name} config", icon_url=icon)
|
||||
|
||||
# birthdays
|
||||
if guild_config.birthday_channel_id:
|
||||
channel = await self.client.get_or_fetch_channel(
|
||||
ctx.guild,
|
||||
guild_config.birthday_channel_id,
|
||||
)
|
||||
|
||||
if channel:
|
||||
birthday_config = f"✅ | in {channel.mention}."
|
||||
else:
|
||||
birthday_config = "❌ | enable the module with `/config birthdays channel`"
|
||||
|
||||
else:
|
||||
birthday_config = "❌ | enable the module with `/config birthdays channel`"
|
||||
|
||||
embed.add_field(name="BIRTHDAYS", value=birthday_config, inline=False)
|
||||
|
||||
# commands
|
||||
if guild_config.command_channel_id:
|
||||
channel = await self.client.get_or_fetch_channel(
|
||||
ctx.guild,
|
||||
guild_config.command_channel_id,
|
||||
)
|
||||
|
||||
if channel:
|
||||
commands_config = f"✅ | commands only allowed in {channel.mention}."
|
||||
else:
|
||||
commands_config = "✅ | commands allowed anywhere."
|
||||
else:
|
||||
commands_config = "✅ | commands allowed anywhere."
|
||||
|
||||
embed.add_field(name="COMMANDS", value=commands_config, inline=False)
|
||||
|
||||
# greetings
|
||||
if guild_config.welcome_channel_id:
|
||||
channel = await self.client.get_or_fetch_channel(
|
||||
ctx.guild,
|
||||
guild_config.welcome_channel_id,
|
||||
)
|
||||
|
||||
if channel:
|
||||
greeting_config = f"✅ | in {channel.mention}"
|
||||
|
||||
if guild_config.welcome_message:
|
||||
greeting_config += (
|
||||
f" with template:\n```{guild_config.welcome_message}```"
|
||||
)
|
||||
else:
|
||||
greeting_config += " without custom template."
|
||||
|
||||
else:
|
||||
greeting_config = "❌ | enable the module with `/config greetings channel`"
|
||||
else:
|
||||
greeting_config = "❌ | enable the module with `/config greetings channel`"
|
||||
|
||||
embed.add_field(name="GREETINGS", value=greeting_config, inline=False)
|
||||
|
||||
# boosts
|
||||
if guild_config.boost_channel_id:
|
||||
channel = await self.client.get_or_fetch_channel(
|
||||
ctx.guild,
|
||||
guild_config.boost_channel_id,
|
||||
)
|
||||
|
||||
if channel:
|
||||
boost_config = f"✅ | in {channel.mention}"
|
||||
|
||||
if guild_config.boost_message:
|
||||
if guild_config.boost_image_url:
|
||||
boost_config += f" with custom image and template:\n```{guild_config.boost_message}```"
|
||||
else:
|
||||
boost_config += (
|
||||
f" with custom template:\n```{guild_config.boost_message}```"
|
||||
)
|
||||
else:
|
||||
if guild_config.boost_image_url:
|
||||
boost_config += " with custom image, but no template."
|
||||
else:
|
||||
boost_config += " without custom image or template."
|
||||
|
||||
else:
|
||||
boost_config = "❌ | enable the module with `/config boosts channel`"
|
||||
else:
|
||||
boost_config = "❌ | enable the module with `/config boosts channel`"
|
||||
|
||||
embed.add_field(name="BOOSTS", value=boost_config, inline=False)
|
||||
|
||||
# levels
|
||||
if guild_config.level_message_type == 0:
|
||||
level_config = "❌ | enable levels with `/config levels enable`"
|
||||
|
||||
elif guild_config.level_message_type == 1:
|
||||
level_config = "✅ | whimsical/sarcastic announcements"
|
||||
|
||||
else:
|
||||
level_config = "✅ | generic announcements"
|
||||
|
||||
if guild_config.level_channel_id and guild_config.level_message_type != 0:
|
||||
channel = await self.client.get_or_fetch_channel(
|
||||
ctx.guild,
|
||||
guild_config.level_channel_id,
|
||||
)
|
||||
|
||||
if channel:
|
||||
level_config += f" in {channel.mention}"
|
||||
else:
|
||||
level_config += " in the user's current channel"
|
||||
|
||||
else:
|
||||
if guild_config.level_message_type != 0:
|
||||
level_config += " in the user's current channel"
|
||||
|
||||
if guild_config.level_message and guild_config.level_message_type == 2:
|
||||
level_config += f" with template:\n```{guild_config.level_message}```"
|
||||
if not guild_config.level_message and guild_config.level_message_type == 2:
|
||||
level_config += f" with template:\n```{strings['level_up']}```"
|
||||
|
||||
embed.add_field(name="LEVELS", value=level_config, inline=False)
|
||||
|
||||
await ctx.respond(embed=embed)
|
73
modules/config/show.py
Normal file
73
modules/config/show.py
Normal file
|
@ -0,0 +1,73 @@
|
|||
import discord
|
||||
from typing import List, Tuple, Optional
|
||||
from discord import Guild
|
||||
from lib.embed_builder import EmbedBuilder
|
||||
from lib.constants import CONST
|
||||
from services.config_service import GuildConfig
|
||||
from services.moderation.modlog_service import ModLogService
|
||||
|
||||
|
||||
async def cmd(ctx) -> None:
|
||||
guild_config: GuildConfig = GuildConfig(ctx.guild.id)
|
||||
guild: Guild = ctx.guild
|
||||
embed: discord.Embed = EmbedBuilder().create_success_embed(
|
||||
ctx=ctx,
|
||||
author_text=CONST.STRINGS["config_show_author"].format(guild.name),
|
||||
thumbnail_url=guild.icon.url if guild.icon else CONST.LUMI_LOGO_TRANSPARENT,
|
||||
show_name=False,
|
||||
)
|
||||
|
||||
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: Optional[int] = 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 ctx.respond(embed=embed)
|
Loading…
Reference in a new issue