1+ //! This module keeps state of the bot
2+ //!
3+ //! Even though it started as storing configuration about bot, now it is
4+ //! responsible to store everything from configuration to music player state and
5+ //! probably the most confusing file/module in this project yet it is
6+ //! surprisingly straightforward.
7+ //!
8+ //! Main [`Config`] struct is divided into substructs/submodules. Each submodule
9+ //! is responsible for storing configuration about a specific part of the bot.
10+ //! Every struct is its own file to make it easier to find them.
11+ //!
12+ //! Also to not make every struct public their functions are re-exported in the
13+ //! main [`Config`] struct.
14+ //!
15+ //! ## Why constructer is named `generate()`?
16+ //! Every struct in config module and its submodules use `generate()` function
17+ //! to generate their struct. This is because this structs only created once and
18+ //! third party resources such as config files and environmental variables used
19+ //! in their creation. Using different name for the constructor other than
20+ //! `new()` is to make it clear that it is not a normal constructor.
21+
122#[ cfg( feature = "cmd" ) ]
223mod cmd_arguments;
324mod defaults;
@@ -47,9 +68,13 @@ use crate::{
4768 server:: Server ,
4869} ;
4970
71+ /// Dummy type to use when `config_file` feature is not enabled. When
72+ /// `config_file` feature is disabled, [`taplo`] crate is disabled. therefore,
73+ /// there is no Node type, and this creates a compilation error.
5074#[ cfg( not( feature = "config_file" ) ) ]
5175struct Node ;
5276
77+ /// Main struct to store everything
5378#[ non_exhaustive]
5479pub struct Config {
5580 general : GeneralConfig ,
@@ -66,6 +91,7 @@ pub struct Config {
6691}
6792
6893impl Config {
94+ /// Generate [`Config`] from config sources
6995 pub fn generate ( ) -> Result < Self > {
7096 #[ cfg( feature = "cmd" ) ]
7197 let cmd_arguments = CMDArguments :: parse ( ) ;
@@ -172,48 +198,95 @@ impl Config {
172198 } )
173199 }
174200
201+ /// Get `Discord` token for bot
175202 pub const fn token ( & self ) -> & String { self . general . token ( ) }
176203
204+ /// Get prefix for `prefix commands`
177205 pub const fn prefix ( & self ) -> & String { self . general . prefix ( ) }
178206
207+ /// Register `slash commands` to `Discord`
179208 pub const fn auto_register_commands ( & self ) -> bool { self . general . auto_register_commands ( ) }
180209
210+ /// Get `vc_auto_change` setting
181211 #[ cfg( feature = "music" ) ]
182212 pub const fn vc_auto_change ( & self ) -> bool { self . general . vc_auto_change ( ) }
183213
214+ /// Get `message_always_embed` setting
215+ ///
216+ /// WARNING: You do not need to use this setting. [`message!()`] macro
217+ /// already obeys this setting.
218+ ///
219+ /// [`message!()`]: crate::messager::message!()
184220 pub const fn message_always_embed ( & self ) -> bool { self . message . always_embed ( ) }
185221
222+ /// Get `message_randowm_colors` setting
223+ ///
224+ /// WARNING: You do not need to use this setting. [`message!()`] macro
225+ /// already obeys this setting.
226+ ///
227+ /// [`message!()`]: crate::messager::message!()
186228 pub const fn message_random_embed_colors ( & self ) -> bool { self . message . random_embed_colors ( ) }
187229
230+ /// Get `message_success_color` setting
231+ ///
232+ /// WARNING: You do not need to use this setting. [`message!()`] macro
233+ /// already obeys this setting.
234+ ///
235+ /// [`message!()`]: crate::messager::message!()
188236 pub const fn message_success_color ( & self ) -> u32 { self . message . success_color ( ) }
189237
238+ /// Get `message_normal_color` setting
239+ ///
240+ /// WARNING: You do not need to use this setting. [`message!()`] macro
241+ /// already obeys this setting.
242+ ///
243+ /// [`message!()`]: crate::messager::message!()
190244 pub const fn message_normal_color ( & self ) -> u32 { self . message . normal_color ( ) }
191245
246+ /// Get `message_error_color` setting
247+ ///
248+ /// WARNING: You do not need to use this setting. [`message!()`] macro
249+ /// already obeys this setting.
250+ ///
251+ /// [`message!()`]: crate::messager::message!()
192252 pub const fn message_error_color ( & self ) -> u32 { self . message . error_color ( ) }
193253
254+ /// Get `message_interaction_time_limit` setting
194255 pub const fn message_interaction_time_limit ( & self ) -> u64 {
195256 self . message . interaction_time_limit ( )
196257 }
197258
259+ /// Get `youtube_search_count` setting
198260 #[ cfg( feature = "music" ) ]
199261 pub const fn youtube_search_count ( & self ) -> u8 { self . youtube . search_count ( ) }
200262
263+ /// Get `youtube_age_resricted` setting
201264 #[ cfg( feature = "music" ) ]
202265 pub const fn youtube_age_restricted ( & self ) -> bool { self . youtube . age_restricted ( ) }
203266
267+ /// Chack if `Spotify` enabled
204268 #[ cfg( feature = "spotify" ) ]
205269 pub const fn is_spotify_initialized ( & self ) -> bool { self . spotify . is_some ( ) }
206270
271+ /// Get `Spotify` client credentials
207272 #[ cfg( feature = "spotify" ) ]
208273 pub fn spotify_client ( & self ) -> Option < ( & String , & String ) > {
209274 Some ( self . spotify . as_ref ( ) ?. client ( ) )
210275 }
211276
277+ /// Get `Spotify` token
212278 #[ cfg( feature = "spotify" ) ]
213279 pub async fn spotify_token ( & self ) -> Option < String > {
214280 Some ( self . spotify . as_ref ( ) ?. token ( ) . await )
215281 }
216282
283+ /// Get databse pool to interact with database
284+ ///
285+ /// WARNING: use [`bot::commands::macros::db_connection!()`] instead of this
286+ /// if you want database connection in [bot command].
287+ ///
288+ /// [`bot::commands::macros::db_connection!()`]: crate::bot::commands::macros::db_connection!()
289+ /// [bot_command]: crate::bot::commands
217290 #[ cfg( feature = "database" ) ]
218291 pub const fn database_pool ( & self ) -> Option < & SqlitePool > {
219292 if let Some ( db) = & self . database {
@@ -223,6 +296,7 @@ impl Config {
223296 }
224297 }
225298
299+ /// Get database URL
226300 #[ cfg( feature = "database" ) ]
227301 pub const fn database_url ( & self ) -> Option < & String > {
228302 if let Some ( db) = & self . database {
@@ -232,6 +306,7 @@ impl Config {
232306 }
233307 }
234308
309+ /// Run database migrations to setup database
235310 #[ cfg( feature = "database" ) ]
236311 pub async fn run_database_migrations ( & self ) -> Result < ( ) > {
237312 if let Some ( db) = & self . database {
@@ -241,8 +316,10 @@ impl Config {
241316 Ok ( ( ) )
242317 }
243318
319+ /// Get connected servers
244320 pub const fn servers ( & self ) -> & RwLock < HashMap < GuildId , Arc < Server > > > { & self . servers }
245321
322+ /// Get main [`Songbird`] strcut
246323 #[ cfg( feature = "music" ) ]
247324 pub fn songbird ( & self ) -> Arc < Songbird > { Arc :: clone ( & self . songbird ) }
248325}
0 commit comments