Skip to content

Commit 1bf225a

Browse files
committed
Merge branch 'documentation' into 'main'
docs: create internal documentation See merge request Erenoit/discord-bot!15
2 parents 74c119f + ab99539 commit 1bf225a

File tree

24 files changed

+435
-2
lines changed

24 files changed

+435
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
//! Contains all the entertainment commands.
2+
13
pub mod meme;
24
pub mod sus;

src/bot/commands/macros.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/// Gives [`Server`] and [`Guild`] for the given [`Context`].
2+
///
3+
/// Most of the commands need these two, so this macro is used to reduce code
4+
/// repetition.
5+
///
6+
/// [`Server`]: crate::server::Server
7+
/// [`Guild`]: serenity::model::guild::Guild
8+
/// [`Context`]: crate::bot::commands::Context
19
macro_rules! get_common {
210
($ctx:ident) => {{
311
use std::sync::Arc;
@@ -9,6 +17,11 @@ macro_rules! get_common {
917
}};
1018
}
1119

20+
/// Gives [`PoolConnection<Sqlite>`] and sending `Discord` messages for errors.
21+
/// Needs [`bot::commands::Context`] to be able to send error messages.
22+
///
23+
/// [`PoolConnection<Sqlite>`]: sqlx::pool::PoolConnection
24+
/// [`Bot::commands::Context`]: crate::bot::commands::Context
1225
#[cfg(feature = "database")]
1326
macro_rules! db_connection {
1427
($ctx: ident) => {{

src/bot/commands/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//! The module containing all the commands for the bot.
2+
//!
3+
//! The commands are split into categories, which are then split into their
4+
//! individual modules. This is done to make it easier to find commands and to
5+
//! make it easier to add new commands.
6+
//!
7+
//! The categories are:
8+
//! - Entertainment
9+
//! - Music
10+
//! - Others
11+
112
#[macro_use]
213
mod macros;
314

src/bot/commands/music/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Contains all the music commands.
2+
13
pub mod clear;
24
pub mod join;
35
pub mod leave;

src/bot/commands/others/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Contains all the commands that don't fit in any other category.
2+
13
pub mod help;
24
pub mod ping;
35
pub mod register;

src/bot/event.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use serenity::{
1111

1212
use crate::server::Server;
1313

14+
/// Struct for handling `Discord` events.
15+
///
16+
/// It currently handles `Ready`, `GuildCreate` and `GuildDelete` events.
1417
pub struct Handler;
1518
impl Handler {
1619
pub const fn new() -> Self { Self }

src/bot/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//! Main module for the bot.
2+
//!
3+
//! This module contains the main struct for the bot, which is `Bot`. It also
4+
//! handles everything related to discord except music. For music see
5+
//! [`Player`].
6+
//!
7+
//! [`Player`]: crate::music::Player
8+
19
mod commands;
210
mod event;
311

@@ -8,12 +16,17 @@ use songbird::SerenityInit;
816

917
pub use crate::bot::commands::Context;
1018

19+
/// The main struct for the bot.
20+
///
21+
/// Every interaction with `Discord` is done through this struct.
1122
#[non_exhaustive]
1223
pub struct Bot;
1324

1425
impl Bot {
26+
/// Creates a new instance of the bot.
1527
pub const fn new() -> Self { Self }
1628

29+
/// Runs the bot.
1730
pub async fn run(&mut self) {
1831
#[cfg(feature = "database")]
1932
get_config!()

src/config/database.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Database Configuration
2+
13
use std::{fs, path::PathBuf};
24

35
use anyhow::{anyhow, Result};
@@ -10,11 +12,14 @@ use crate::config::Node;
1012

1113
#[non_exhaustive]
1214
pub(super) struct DatabaseConfig {
15+
/// Database pool.
1316
pool: SqlitePool,
17+
/// Database URL/location.
1418
url: String,
1519
}
1620

1721
impl DatabaseConfig {
22+
/// Generate a new `DatabaseConfig` from the config file.
1823
pub fn generate(config_file: &Node, default_path: PathBuf) -> Result<Self> {
1924
// TODO: make cmd argument priority over config file one
2025
let path = get_value!(config_file, PathBuf, "BOT_DATABASE_LOCATION", "database"=>"location", default_path)?;
@@ -38,12 +43,15 @@ impl DatabaseConfig {
3843
Ok(Self { pool, url })
3944
}
4045

46+
/// Run database migrations.
4147
pub async fn run_migrations(&self) -> Result<()> {
4248
sqlx::migrate!().run(&self.pool).await?;
4349
Ok(())
4450
}
4551

52+
/// Returns the database pool.
4653
pub const fn pool(&self) -> &SqlitePool { &self.pool }
4754

55+
/// Returns the database URL.
4856
pub const fn url(&self) -> &String { &self.url }
4957
}

src/config/defaults.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! Default values for the config.
2+
//!
3+
//! This file contains the default values for the config. These values are used
4+
//! when the config file is not present or when a value is missing from the
5+
//! config file.
6+
17
pub(super) const PREFIX: &str = "-";
28
pub(super) const AUTO_REGISTER_COMMANDS: bool = true;
39
#[cfg(feature = "music")]

src/config/general.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! General Configuration
2+
13
use anyhow::Result;
24
#[cfg(feature = "config_file")]
35
use taplo::dom::Node;
@@ -10,14 +12,20 @@ use crate::config::Node;
1012

1113
#[non_exhaustive]
1214
pub(super) struct GeneralConfig {
15+
/// Discord token.
1316
token: String,
17+
/// Prefix for commands.
1418
prefix: String,
19+
/// Whether to auto register commands.
1520
auto_register_commands: bool,
21+
/// Whether to auto change voice channel when user sended the command from
22+
/// another voice cahnnel.
1623
#[cfg(feature = "music")]
1724
vc_auto_change: bool,
1825
}
1926

2027
impl GeneralConfig {
28+
/// Generate a new `GeneralConfig` from the config file.
2129
pub fn generate(config_file: &Node) -> Result<Self> {
2230
let token = get_value!(config_file, String, "BOT_TOKEN", "general"=>"token", "Discord token couldn't found.")?;
2331
let prefix = get_value!(config_file, String, "BOT_PREFIX", "general"=>"prefix", PREFIX)?;
@@ -34,12 +42,17 @@ impl GeneralConfig {
3442
})
3543
}
3644

45+
/// Returns the Discord token.
3746
pub const fn token(&self) -> &String { &self.token }
3847

48+
/// Returns the prefix for commands.
3949
pub const fn prefix(&self) -> &String { &self.prefix }
4050

51+
/// Returns whether to auto register commands.
4152
pub const fn auto_register_commands(&self) -> bool { self.auto_register_commands }
4253

54+
/// Returns whether to auto change voice channel when user sended the
55+
/// command from another voice cahnnel.
4356
#[cfg(feature = "music")]
4457
pub const fn vc_auto_change(&self) -> bool { self.vc_auto_change }
4558
}

0 commit comments

Comments
 (0)