Skip to content

Commit

Permalink
Merge client feature/module into gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Aug 16, 2024
1 parent b167b4d commit ef2f6e2
Show file tree
Hide file tree
Showing 46 changed files with 76 additions and 186 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
- name: no default features
features: " "
- name: no cache
features: builder client framework gateway model http utils rustls_backend
features: framework rustls_backend
- name: no gateway
features: model http rustls_backend
features: model rustls_backend
- name: chrono
features: chrono
- name: unstable API + typesize
Expand Down
17 changes: 4 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,9 @@ default_native_tls = ["default_no_backend", "native_tls_backend"]

# Serenity requires a backend, this picks all default features without a backend.
default_no_backend = [
"builder",
"cache",
"chrono",
"client",
"framework",
"gateway",
"model",
"http",
"utils",
]

# Enables builder structs to configure Discord HTTP requests. Without this feature, you have to
Expand All @@ -87,14 +81,11 @@ builder = ["tokio/fs"]
cache = ["fxhash", "dashmap"]
# Enables collectors, a utility feature that lets you await interaction events in code with
# zero setup, without needing to setup an InteractionCreate event listener.
collector = ["gateway", "model"]
# Wraps the gateway and http functionality into a single interface
# TODO: should this require "gateway"?
client = ["http"]
collector = ["gateway"]
# Enables the Framework trait which is an abstraction for old-style text commands.
framework = ["client", "model", "utils"]
framework = ["gateway"]
# Enables gateway support, which allows bots to listen for Discord events.
gateway = ["flate2"]
gateway = ["model", "flate2"]
# Enables HTTP, which enables bots to execute actions on Discord.
http = ["dashmap", "mime_guess", "percent-encoding"]
# Enables wrapper methods around HTTP requests on model types.
Expand All @@ -108,7 +99,7 @@ voice_model = ["serenity-voice-model"]
unstable = []
# Enables some utility functions that can be useful for bot creators.
utils = []
voice = ["client", "model"]
voice = ["gateway"]
# Enables unstable tokio features to give explicit names to internally spawned tokio tasks
tokio_task_builder = ["tokio/tracing"]
interactions_endpoint = ["ed25519-dalek"]
Expand Down
9 changes: 3 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#[cfg(all(
any(feature = "http", feature = "gateway"),
not(any(feature = "rustls_backend", feature = "native_tls_backend"))
))]
#[cfg(all(feature = "http", not(any(feature = "rustls_backend", feature = "native_tls_backend"))))]
compile_error!(
"You have the `http` or `gateway` feature enabled, either the `rustls_backend` or \
`native_tls_backend` feature must be selected to let Serenity use `http` or `gateway`.\n\
"You have the `http` feature enabled; either the `rustls_backend` or `native_tls_backend` \
feature must be enabled to let Serenity make requests over the network.\n\
- `rustls_backend` uses Rustls, a pure Rust TLS-implemenation.\n\
- `native_tls_backend` uses SChannel on Windows, Secure Transport on macOS, and OpenSSL on \
other platforms.\n\
Expand Down
2 changes: 1 addition & 1 deletion examples/e01_basic_ping_bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
serenity = { path = "../../", default-features = false, features = ["gateway", "model", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
2 changes: 1 addition & 1 deletion examples/e02_transparent_guild_sharding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
serenity = { path = "../../", default-features = false, features = ["gateway", "model", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
2 changes: 1 addition & 1 deletion examples/e03_struct_utilities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
serenity = { path = "../../", default-features = false, features = ["gateway", "model", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
2 changes: 1 addition & 1 deletion examples/e04_message_builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
serenity = { path = "../../", default-features = false, features = ["gateway", "model", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
2 changes: 1 addition & 1 deletion examples/e05_sample_bot_structure/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["my name <[email protected]>"]
edition = "2021"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "collector"] }
serenity = { path = "../../", default-features = false, features = ["collector", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
2 changes: 1 addition & 1 deletion examples/e06_env_logging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ tracing-subscriber = "0.3"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }

[dependencies.serenity]
features = ["client", "rustls_backend"]
features = ["gateway", "rustls_backend"]
path = "../../"
2 changes: 1 addition & 1 deletion examples/e07_shard_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "time"] }

[dependencies.serenity]
default-features = false
features = ["client", "gateway", "rustls_backend", "model"]
features = ["gateway", "model", "rustls_backend"]
path = "../../"
2 changes: 1 addition & 1 deletion examples/e08_create_message_builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "chrono"] }
serenity = { path = "../../", default-features = false, features = ["gateway", "model", "chrono", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
2 changes: 1 addition & 1 deletion examples/e09_collectors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies.serenity]
features = ["framework", "rustls_backend", "collector"]
features = ["collector", "framework", "rustls_backend"]
path = "../../"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/e10_gateway_intents/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
serenity = { path = "../../", default-features = false, features = ["gateway", "model", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
2 changes: 1 addition & 1 deletion examples/e12_parallel_loops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache"] }
serenity = { path = "../../", default-features = false, features = ["gateway", "model", "cache", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
sys-info = "0.9"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
2 changes: 1 addition & 1 deletion examples/e13_sqlite_database/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
serenity = { path = "../../", default-features = false, features = ["gateway", "model", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
sqlx = { version = "0.7", features = ["runtime-tokio-rustls", "sqlite"] }
2 changes: 1 addition & 1 deletion examples/e14_message_components/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "collector"] }
serenity = { path = "../../", default-features = false, features = ["gateway", "model", "collector", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
dotenv = { version = "0.15.0" }
2 changes: 1 addition & 1 deletion examples/e15_webhook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["rustls_backend", "model"] }
serenity = { path = "../../", default-features = false, features = ["model", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
2 changes: 1 addition & 1 deletion examples/testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ authors = ["my name <[email protected]>"]
edition = "2018"

[dependencies]
serenity = { path = "../../", default-features = false, features = ["client", "gateway", "rustls_backend", "model", "cache", "collector"] }
serenity = { path = "../../", default-features = false, features = ["gateway", "model", "cache", "collector", "rustls_backend"] }
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
env_logger = "0.10.0"
1 change: 0 additions & 1 deletion src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ impl Cache {
/// struct Handler;
///
/// #[serenity::async_trait]
/// # #[cfg(feature = "client")]
/// impl EventHandler for Handler {
/// async fn cache_ready(&self, ctx: Context, _: Vec<GuildId>) {
/// println!("{} unknown members", ctx.cache.unknown_members());
Expand Down
25 changes: 0 additions & 25 deletions src/client/error.rs

This file was deleted.

11 changes: 0 additions & 11 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use reqwest::{header::InvalidHeaderValue, Error as ReqwestError};
#[cfg(feature = "gateway")]
use tokio_tungstenite::tungstenite::error::Error as TungsteniteError;

#[cfg(feature = "client")]
use crate::client::ClientError;
#[cfg(feature = "gateway")]
use crate::gateway::GatewayError;
#[cfg(feature = "http")]
Expand Down Expand Up @@ -38,11 +36,6 @@ pub enum Error {
///
/// [`model`]: crate::model
Model(ModelError),
/// A [client] error.
///
/// [client]: crate::client
#[cfg(feature = "client")]
Client(ClientError),
/// An error from the [`gateway`] module.
///
/// [`gateway`]: crate::gateway
Expand Down Expand Up @@ -117,8 +110,6 @@ impl fmt::Display for Error {
Self::Io(inner) => fmt::Display::fmt(&inner, f),
Self::Json(inner) => fmt::Display::fmt(&inner, f),
Self::Model(inner) => fmt::Display::fmt(&inner, f),
#[cfg(feature = "client")]
Self::Client(inner) => fmt::Display::fmt(&inner, f),
#[cfg(feature = "gateway")]
Self::Gateway(inner) => fmt::Display::fmt(&inner, f),
#[cfg(feature = "http")]
Expand All @@ -136,8 +127,6 @@ impl StdError for Error {
Self::Io(inner) => Some(inner),
Self::Json(inner) => Some(inner),
Self::Model(inner) => Some(inner),
#[cfg(feature = "client")]
Self::Client(inner) => Some(inner),
#[cfg(feature = "gateway")]
Self::Gateway(inner) => Some(inner),
#[cfg(feature = "http")]
Expand Down
2 changes: 1 addition & 1 deletion src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use async_trait::async_trait;

use crate::client::{Client, Context, FullEvent};
use crate::gateway::{Client, Context, FullEvent};

/// A trait for defining your own framework for serenity to use.
///
Expand Down
12 changes: 8 additions & 4 deletions src/gateway/bridge/shard_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ use super::VoiceGatewayManager;
use super::{ShardId, ShardQueue, ShardQueuer, ShardQueuerMessage, ShardRunnerInfo};
#[cfg(feature = "cache")]
use crate::cache::Cache;
use crate::client::InternalEventHandler;
#[cfg(feature = "framework")]
use crate::framework::Framework;
use crate::gateway::{ConnectionStage, GatewayError, PresenceData};
use crate::gateway::{ConnectionStage, GatewayError, InternalEventHandler, PresenceData};
use crate::http::Http;
use crate::internal::prelude::*;
use crate::internal::tokio::spawn_named;
Expand Down Expand Up @@ -49,8 +48,13 @@ use crate::model::gateway::GatewayIntents;
/// use std::env;
/// use std::sync::{Arc, OnceLock};
///
/// use serenity::client::{EventHandler, InternalEventHandler, RawEventHandler};
/// use serenity::gateway::{ShardManager, ShardManagerOptions};
/// use serenity::gateway::{
/// EventHandler,
/// InternalEventHandler,
/// RawEventHandler,
/// ShardManager,
/// ShardManagerOptions,
/// };
/// use serenity::http::Http;
/// use serenity::model::gateway::GatewayIntents;
/// use serenity::prelude::*;
Expand Down
9 changes: 7 additions & 2 deletions src/gateway/bridge/shard_queuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ use super::{
};
#[cfg(feature = "cache")]
use crate::cache::Cache;
use crate::client::InternalEventHandler;
#[cfg(feature = "framework")]
use crate::framework::Framework;
use crate::gateway::{ConnectionStage, PresenceData, Shard, ShardRunnerMessage};
use crate::gateway::{
ConnectionStage,
InternalEventHandler,
PresenceData,
Shard,
ShardRunnerMessage,
};
use crate::http::Http;
use crate::internal::prelude::*;
use crate::internal::tokio::spawn_named;
Expand Down
12 changes: 9 additions & 3 deletions src/gateway/bridge/shard_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ use super::VoiceGatewayManager;
use super::{ShardId, ShardManager, ShardRunnerMessage};
#[cfg(feature = "cache")]
use crate::cache::Cache;
use crate::client::dispatch::dispatch_model;
use crate::client::{Context, InternalEventHandler};
#[cfg(feature = "framework")]
use crate::framework::Framework;
use crate::gateway::{GatewayError, ReconnectType, Shard, ShardAction};
use crate::gateway::dispatch::dispatch_model;
use crate::gateway::{
Context,
GatewayError,
InternalEventHandler,
ReconnectType,
Shard,
ShardAction,
};
use crate::http::Http;
use crate::internal::prelude::*;
use crate::internal::tokio::spawn_named;
Expand Down
Loading

0 comments on commit ef2f6e2

Please sign in to comment.