22
33from __future__ import annotations
44
5- from typing import TYPE_CHECKING
6-
7- if TYPE_CHECKING :
8- from uuid import UUID
5+ from enum import StrEnum
6+ from uuid import UUID # noqa: TC003
97
108from pydantic import Field
119
1210from byte_bot .server .lib .schema import CamelizedBaseModel
11+ from byte_bot .server .lib .serialization import convert_camel_to_snake_case
12+
13+ __all__ = (
14+ "AllowedUsersConfigSchema" ,
15+ "ForumConfigSchema" ,
16+ "GitHubConfigSchema" ,
17+ "GuildCreate" ,
18+ "GuildSchema" ,
19+ "GuildUpdate" ,
20+ "SOTagsConfigSchema" ,
21+ "UpdateableGuildSetting" ,
22+ )
23+
24+
25+ class GitHubConfigSchema (CamelizedBaseModel ):
26+ """Schema for validating GitHub configuration."""
27+
28+ guild_id : UUID
29+ discussion_sync : bool
30+ github_organization : str | None
31+ github_repository : str | None
32+
33+
34+ class SOTagsConfigSchema (CamelizedBaseModel ):
35+ """Schema for validating StackOverflow tags configuration."""
36+
37+ guild_id : UUID
38+ tag_name : str
1339
14- __all__ = ("GuildCreate" , "GuildSchema" , "GuildUpdate" )
40+
41+ class AllowedUsersConfigSchema (CamelizedBaseModel ):
42+ """Schema for validating allowed users for certain admin actions within a guild."""
43+
44+ guild_id : UUID
45+ user_id : UUID
46+
47+
48+ class ForumConfigSchema (CamelizedBaseModel ):
49+ """Schema for validating forum configuration."""
50+
51+ guild_id : UUID
52+ help_forum : bool = Field (title = "Help Forum" , description = "Is the help forum enabled." )
53+ help_forum_category : str
54+ help_thread_auto_close : bool
55+ help_thread_auto_close_days : int
56+ help_thread_notify : bool
57+ help_thread_notify_roles : list [int ]
58+ help_thread_notify_days : int
59+ help_thread_sync : bool
60+ showcase_forum : bool
61+ showcase_forum_category : str
62+ showcase_thread_auto_close : bool
63+ showcase_thread_auto_close_days : int
1564
1665
1766class GuildSchema (CamelizedBaseModel ):
@@ -28,6 +77,18 @@ class GuildSchema(CamelizedBaseModel):
2877 issue_linking : bool | None = Field (title = "Issue Linking" , description = "Is issue linking enabled." )
2978 comment_linking : bool | None = Field (title = "Comment Linking" , description = "Is comment linking enabled." )
3079 pep_linking : bool | None = Field (title = "PEP Linking" , description = "Is PEP linking enabled." )
80+ github_config : GitHubConfigSchema | None = Field (
81+ title = "GitHub Config" , description = "The GitHub configuration for the guild."
82+ )
83+ sotags_configs : list [SOTagsConfigSchema ] = Field (
84+ title = "StackOverflow Tags Configs" , description = "The StackOverflow tags configuration for the guild."
85+ )
86+ allowed_users : list [AllowedUsersConfigSchema ] = Field (
87+ title = "Allowed Users" , description = "The allowed users configuration for the guild."
88+ )
89+ forum_config : ForumConfigSchema | None = Field (
90+ title = "Forum Config" , description = "The forum configuration for the guild."
91+ )
3192
3293
3394class GuildCreate (CamelizedBaseModel ):
@@ -52,3 +113,75 @@ class GuildUpdate(CamelizedBaseModel):
52113 issue_linking : bool | None = Field (title = "Issue Linking" , description = "Is issue linking enabled." )
53114 comment_linking : bool | None = Field (title = "Comment Linking" , description = "Is comment linking enabled." )
54115 pep_linking : bool | None = Field (title = "PEP Linking" , description = "Is PEP linking enabled." )
116+
117+
118+ class UpdateableGuildSetting (CamelizedBaseModel ):
119+ """Allowed settings that admins can update for their guild."""
120+
121+ """Guild Model Settings"""
122+ prefix : str = Field (title = "Prefix" , description = "The prefix for the guild." )
123+ help_channel_id : int = Field (title = "Help Channel ID" , description = "The channel ID for the help forum." )
124+ showcase_channel_id : int = Field (title = "Showcase Channel ID" , description = "The channel ID for the showcase forum." )
125+ sync_label : str = Field (title = "Sync Label" , description = "The forum label to use for GitHub discussion syncs." )
126+ issue_linking : bool = Field (title = "Issue Linking" , description = "Is issue linking enabled." )
127+ comment_linking : bool = Field (title = "Comment Linking" , description = "Is comment linking enabled." )
128+ pep_linking : bool = Field (title = "PEP Linking" , description = "Is PEP linking enabled." )
129+
130+ """GitHub Config Settings"""
131+ discussion_sync : bool = Field (title = "Discussion Sync" , description = "Is GitHub discussion sync enabled." )
132+ github_organization : str = Field (title = "GitHub Organization" , description = "The GitHub organization to sync." )
133+ github_repository : str = Field (title = "GitHub Repository" , description = "The GitHub repository to sync." )
134+
135+ """StackOverflow Tags Config Settings"""
136+ tag_name : list [str ] = Field (
137+ title = "StackOverflow Tag(s)" ,
138+ description = "The StackOverflow tag(s) to sync." ,
139+ examples = ["litestar" , "byte" , "python" ],
140+ )
141+
142+ """Allowed Users Config Settings"""
143+ allowed_user_id : int = Field (title = "User ID" , description = "The user or role ID to allow." )
144+
145+ """Forum Config Settings"""
146+ """Help Forum"""
147+ help_forum : bool = Field (title = "Help Forum" , description = "Is the help forum enabled." )
148+ help_forum_category : str = Field (title = "Help Forum Category" , description = "The help forum category." )
149+ help_thread_auto_close : bool = Field (
150+ title = "Help Thread Auto Close" , description = "Is the help thread auto close enabled."
151+ )
152+ help_thread_auto_close_days : int = Field (
153+ title = "Help Thread Auto Close Days" , description = "The days to auto close help threads after inactivity."
154+ )
155+ help_thread_notify : bool = Field (
156+ title = "Help Thread Notify" , description = "Whether to notify roles for unresponded help threads."
157+ )
158+ help_thread_notify_roles : list [int ] = Field (
159+ title = "Help Thread Notify Roles" , description = "The roles to notify for unresponded help threads."
160+ )
161+ help_thread_notify_days : int = Field (
162+ title = "Help Thread Notify Days" , description = "The days to notify `notify_roles` after not receiving a response."
163+ )
164+ help_thread_sync : bool = Field (
165+ title = "Help Thread Sync" , description = "Is the help thread GitHub discussions sync enabled."
166+ )
167+
168+ """Showcase forum"""
169+ showcase_forum : bool = Field (title = "Showcase Forum" , description = "Is the showcase forum enabled." )
170+ showcase_forum_category : str = Field (title = "Showcase Forum Category" , description = "The showcase forum category." )
171+ showcase_thread_auto_close : bool = Field (
172+ title = "Showcase Thread Auto Close" , description = "Is the showcase thread auto close enabled."
173+ )
174+ showcase_thread_auto_close_days : int = Field (
175+ title = "Showcase Thread Auto Close Days" , description = "The days to auto close showcase threads after inactivity."
176+ )
177+
178+ @classmethod
179+ def as_enum (cls ) -> type [StrEnum ]:
180+ """Helper to dynamically create an enum from the class fields."""
181+ enum_items = {
182+ convert_camel_to_snake_case (field .alias or field_name ): convert_camel_to_snake_case (
183+ field .alias or field_name
184+ )
185+ for field_name , field in cls .model_fields .items ()
186+ }
187+ return type (cls .__name__ , (StrEnum ,), enum_items )
0 commit comments