Skip to content

Commit

Permalink
Make module http, rich_presence and bot private
Browse files Browse the repository at this point in the history
  • Loading branch information
AS1100K committed Feb 6, 2025
1 parent 7e063d7 commit 4cef0af
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 65 deletions.
4 changes: 4 additions & 0 deletions PRERELEASE-CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.6.0-rc.1] - [Unreleased]

### Added
- `new` method to `DiscordPluginGroup` based on feature configuration

### Changed
- Hide functions available in `docsrs` feature
- `plugins` module is now private
- disabled default features of dependencies
- Moved all resources to `res` module
- Moved all configuration structs to `config` module
- Make module `http`, `rich_presence` and `bot` private

### Fixed
- Typos in documentation
Expand Down
2 changes: 2 additions & 0 deletions src/bot/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Not Accessible Publicly

//! Discord bot integration for Bevy applications.
//!
//! This module provides a plugin system for integrating a Discord bot into your Bevy application,
Expand Down
13 changes: 12 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
macro_rules! new {
($doc:expr $(, $field:ident : $type:ty)*) => {
#[doc = concat!($doc)]
pub fn new($($field: $type),*) -> Self {
Self {
$($field),*
}
}
};
}

/// Creates a function that override the field which is `Option` and documentation
macro_rules! override_field_with_doc {
($name:ident, $type:ty, $doc:expr) => {
Expand Down Expand Up @@ -80,6 +91,6 @@ macro_rules! send_event_tuple {
}

pub(crate) use {
create_event_collection_and_handler, initialize_field_with_doc, override_field_with_doc,
create_event_collection_and_handler, initialize_field_with_doc, new, override_field_with_doc,
send_event, send_event_tuple,
};
20 changes: 2 additions & 18 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Not Accessible Publicly

//! HTTP Client functionality for Discord API interactions.
//!
//! This module provides a Bevy plugin wrapper around Serenity's HTTP client,
Expand All @@ -24,24 +26,6 @@ use std::sync::Arc;
/// and makes it available throughout the application as a Bevy resource.
pub struct DiscordHttpPlugin(String);

impl DiscordHttpPlugin {
/// Creates a new instance of the Discord HTTP plugin.
///
/// # Arguments
///
/// * `token` - A Discord bot token used for authentication
///
/// # Example
/// ```no_run
/// use bevy_discord::http::DiscordHttpPlugin;
///
/// let plugin = DiscordHttpPlugin::new("your-bot-token-here".to_string());
/// ```
pub fn new(token: String) -> DiscordHttpPlugin {
DiscordHttpPlugin(token)
}
}

impl Plugin for DiscordHttpPlugin {
fn build(&self, app: &mut App) {
let http: Arc<Http> = Arc::new(Http::new(&self.0));
Expand Down
125 changes: 79 additions & 46 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use bevy_app::{PluginGroup, PluginGroupBuilder};
use bevy_ecs::schedule::SystemSet;

#[cfg(feature = "bot")]
#[cfg_attr(docsrs, doc(cfg(feature = "bot")))]
pub mod bot;
mod bot;

#[cfg(any(feature = "bot", feature = "rich_presence"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "bot", feature = "rich_presence"))))]
Expand All @@ -24,12 +23,10 @@ pub mod res;
mod common;

#[cfg(feature = "http")]
#[cfg_attr(docsrs, doc(cfg(feature = "http")))]
pub mod http;
mod http;

#[cfg(feature = "rich_presence")]
#[cfg_attr(docsrs, doc(cfg(feature = "rich_presence")))]
pub mod rich_presence;
mod rich_presence;

/// Tokio runtime, use this if you want to use async code inside bevy systems
pub mod runtime;
Expand All @@ -53,37 +50,69 @@ pub use discord_sdk;
#[derive(SystemSet, Debug, Clone, PartialEq, Eq, Hash)]
pub struct DiscordSet;

#[cfg(any(feature = "bot", feature = "rich_presence"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "bot", feature = "rich_presence"))))]
#[cfg(any(feature = "bot", feature = "rich_presence", feature = "http"))]
#[cfg_attr(
docsrs,
doc(cfg(any(feature = "bot", feature = "rich_presence", feature = "http")))
)]
pub struct DiscordPluginGroup {
#[cfg(feature = "bot")]
/// _Only available in feature `bot`_
pub bot_config: crate::config::DiscordBotConfig,
#[cfg(feature = "rich_presence")]
/// _Only available in feature `rich_presence`_
pub rich_presence_config: crate::config::DiscordRichPresenceConfig,
#[cfg(any(all(feature = "http", not(feature = "bot")), feature = "docsrs"))]
/// _Only available in feature `http` and ~`bot`~_
pub token: String,
}

#[cfg(all(feature = "bot", feature = "rich_presence"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "bot", feature = "rich_presence"))))]
impl DiscordPluginGroup {
/// Creates a new `DiscordPluginGroup` with the specified bot and rich presence configurations.
#[cfg(all(feature = "docsrs", feature = "bot", feature = "rich_presence"))]
/// Creates a new instance of `DiscordPluginGroup`.
///
/// **NOTE:** This function arguments depends on the feature flag that is
/// enabled. See the following table:
///
/// | Feature | Arguments |
/// |--------------------|------------------------|
/// | `bot` | `bot_config` |
/// | `rich_presence` | `rich_presence_config` |
/// | `http` and ~`bot`~ | `token` |
///
/// _Feature `full` includes both `bot`, and `rich_presence` feature_
///
/// _Feature `bot` includes `http` feature_
///
/// # Arguments
/// ## Arguments
///
/// * `bot_config` - Configuration for the Discord bot [_only on feature `bot`_].
/// * `rich_presence_config` - Configuration for Discord rich presence [_only on feature `rich_presence`_].
/// - `bot_config`: [DiscordBotConfig](crate::config::DiscordBotConfig)
/// - `rich_presence_config`: [DiscordRichPresenceConfig](crate::config::DiscordRichPresenceConfig)
/// - `token`: [String], Discord Token _Can only send messages_
///
/// # Returns
/// ## Resources Available
///
/// A new instance of `DiscordPluginGroup`.
/// Once this plugin group is added to the App, it makes the configuration struct
/// i.e. `DiscordBotConfig` and `DiscorsRichPresenceConfig` available.
///
/// The following are the resources availabe in `res` module are created after the
/// Startup schedule. Refer to the table below for more information.
///
/// | Feature | Resource |
/// |-----------------|----------------------------------------------------------------|
/// | `bot` or `http` | [`DiscordHttpResource`](crate::res::DiscordHttpResource) |
/// | `rich_presence` | [`DiscordRichPresenceRes`](crate::res::DiscordRichPresenceRes) |
pub fn new(
bot_config: crate::config::DiscordBotConfig,
rich_presence_config: crate::config::DiscordRichPresenceConfig,
token: String,
) -> Self {
Self {
bot_config,
rich_presence_config,
token,
}
}

Expand All @@ -97,6 +126,7 @@ impl DiscordPluginGroup {
Self {
bot_config,
rich_presence_config: crate::config::DiscordRichPresenceConfig::default(),
token: String::new(),
}
}

Expand All @@ -112,44 +142,42 @@ impl DiscordPluginGroup {
Self {
rich_presence_config,
bot_config: Default::default(),
token: String::new(),
}
}
}

#[cfg(all(feature = "bot", not(feature = "rich_presence")))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "bot", not(feature = "rich_presence")))))]
#[cfg(any(feature = "bot", feature = "rich_presence", feature = "http"))]
impl DiscordPluginGroup {
/// Creates a new `DiscordPluginGroup` with the specified bot configurations.
///
/// # Arguments
///
/// * `bot_config` - Configuration for the Discord bot.
///
/// # Returns
///
/// A new instance of `DiscordPluginGroup`.
pub fn new(bot_config: crate::config::DiscordBotConfig) -> Self {
Self { bot_config }
}
}
// feature only `bot`
#[cfg(all(feature = "bot", not(feature = "rich_presence")))]
common::new!(
"Creates a new `DiscordPluginGroup`. _Available only on `bot` feature._\n\nFor more information, please refer to https://docs.rs/bevy-discord",
bot_config: crate::config::DiscordBotConfig
);

// feature only `http`
#[cfg(all(feature = "http", not(feature = "rich_presence"), not(feature = "bot")))]
common::new!(
"Creates a new `DiscordPluginGroup`. _Available only on `http` feature._\n\nFor more information, please refer to https://docs.rs/bevy-discord",
token: String
);

// feature `http` and `rich_presence`
#[cfg(all(feature = "http", feature = "rich_presence", not(feature = "bot")))]
common::new!(
"Creates a new `DiscordPluginGroup`. _Available only on `http` + `rich_presence` features._\n\nFor more information, please refer to https://docs.rs/bevy-discord",
token: String,
rich_presence_config: crate::config::DiscordRichPresenceConfig,
);

#[cfg(all(feature = "rich_presence", not(feature = "bot")))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "rich_presence", not(feature = "bot")))))]
impl DiscordPluginGroup {
/// Creates a new `DiscordPluginGroup` with the specified rich_presence configurations.
///
/// # Arguments
///
/// * `rich_presence` - Configuration for Discord rich presence.
///
/// # Returns
///
/// A new instance of `DiscordPluginGroup`.
pub fn new(rich_presence_config: crate::config::DiscordRichPresenceConfig) -> Self {
Self {
rich_presence_config,
}
}
// feature `bot` and `rich_presence`
#[cfg(all(feature = "bot", feature = "rich_presence", not(feature = "docsrs")))]
common::new!(
"Creates a new `DiscordPluginGroup`. _Available only on `bot` + `rich_presence` features._\n\nFor more information, please refer to https://docs.rs/bevy-discord",
bot_config: crate::config::DiscordBotConfig,
rich_presence_config: crate::config::DiscordRichPresenceConfig,
);
}

#[cfg(any(feature = "bot", feature = "rich_presence"))]
Expand All @@ -170,6 +198,11 @@ impl PluginGroup for DiscordPluginGroup {
plugin_group.add(DiscordRichPresencePlugin::new(self.rich_presence_config));
}

#[cfg(all(feature = "http", not(feature = "bot")))]
{
plugin_group = plugin_group.add(http::DiscordHttpPlugin(self.token));
}

plugin_group
}
}
2 changes: 2 additions & 0 deletions src/rich_presence/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// // Not Accessible Publicly

//! [Discord Rich Presence](https://discord.com/developers/docs/rich-presence/overview) Integration with bevy
//!
//! # NOTE before using
Expand Down

0 comments on commit 4cef0af

Please sign in to comment.