|
1 | 1 | """User management""" |
2 | 2 |
|
3 | 3 | import logging |
4 | | -import os |
5 | | -import sys |
6 | | - |
7 | 4 | import discord |
8 | 5 | from discord import Role, app_commands |
9 | 6 | from discord.ext import commands |
10 | | -from sqlalchemy import select, func, and_ |
| 7 | +from sqlalchemy import insert, select, func, and_ |
11 | 8 | from sqlalchemy.exc import IntegrityError |
12 | 9 |
|
13 | 10 | from bot import KDRBot |
14 | 11 | from database.dto.kd_roles import KDRole |
| 12 | +from database.dto.server_settings import ServerSetting |
15 | 13 | from database.dto.users import User |
16 | 14 | from database.error_handling import is_unique_violation |
17 | 15 | from utils.kd_roles import get_kd_roles |
18 | 16 | from utils.register import register |
19 | 17 | from utils.role_management import RoleManagement |
| 18 | +from utils.server_settings import add_guild, update_guild |
20 | 19 |
|
21 | 20 |
|
22 | 21 | class RegisterModal(discord.ui.Modal, title="Register your EA account"): |
@@ -222,6 +221,32 @@ async def generate_register(self, interaction: discord.Interaction) -> None: |
222 | 221 | embed=embed, view=RegisterView(self.bot) |
223 | 222 | ) |
224 | 223 |
|
| 224 | + logging_group = app_commands.Group( |
| 225 | + name="log", description="Manage the logging", parent=group |
| 226 | + ) |
| 227 | + |
| 228 | + @logging_group.command( |
| 229 | + name="channel", |
| 230 | + description="Set the channel to log new registration attempts to", |
| 231 | + ) |
| 232 | + @app_commands.guild_only() |
| 233 | + @app_commands.default_permissions(administrator=True) |
| 234 | + @app_commands.checks.has_permissions(administrator=True) |
| 235 | + async def set_log_channel( |
| 236 | + self, interaction: discord.Interaction, channel: discord.TextChannel |
| 237 | + ) -> None: |
| 238 | + """Set the channel to log new registration attempts to""" |
| 239 | + await interaction.response.defer() |
| 240 | + if interaction.guild is None: |
| 241 | + return # is already set to guild_only |
| 242 | + async with self.bot.db.create_session() as session: |
| 243 | + await update_guild( |
| 244 | + session, interaction.guild, {"log_channel_id": channel.id} |
| 245 | + ) |
| 246 | + await interaction.followup.send( |
| 247 | + f'Set the logging channel to "{channel.name}"', ephemeral=True |
| 248 | + ) |
| 249 | + |
225 | 250 |
|
226 | 251 | async def setup(bot: KDRBot) -> None: |
227 | 252 | """Setup the cog within discord.py lib""" |
|
0 commit comments