Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 65 additions & 57 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edition.workspace = true
rust-version.workspace = true

[workspace]
members = ["examples/*"]
members = ["examples/*", "serenity-core", "serenity-voice-model"]

[workspace.package]
documentation = "https://docs.rs/serenity"
Expand All @@ -26,51 +26,50 @@ license = "ISC"
edition = "2024"
rust-version = "1.88"

[dependencies]
# Required dependencies
bitflags = "2.4.2"
serde_json = { version = "1.0.108", features = ["raw_value"] }
async-trait = "0.1.74"
tracing = { version = "0.1.40", features = ["log"] }
serde = { version = "1.0.192", features = ["derive", "rc"] }
url = { version = "2.4.1", features = ["serde"] }
tokio = { version = "1.34.0", features = ["macros", "rt", "sync", "time", "io-util"] }
[workspace.dependencies]
aformat = "0.1.3"
dashmap = "6.1.0"
extract_map = { version = "0.3.0", features = ["serde"] }
futures = { version = "0.3.29", default-features = false, features = ["std"] }
time = { version = "0.3.36", features = ["formatting", "parsing", "serde-well-known"] }
base64 = { version = "0.22.0" }
zeroize = { version = "1.7" } # Not used in serenity, but bumps the minimal version from secrecy
arrayvec = { version = "0.7.4", features = ["serde"] }
serde_cow = { version = "0.1.0" }
parking_lot = "0.12.1"
reqwest = { version = "0.12.2", default-features = false, features = ["multipart", "stream", "json"] }
serde = { version = "1.0.192", features = ["derive", "rc"] }
serde_json = { version = "1.0.108", features = ["raw_value"] }
small-fixed-array = { version = "0.4.10", features = ["serde"] }
bool_to_bitflags = { version = "0.1.2" }
nonmax = { version = "0.5.5", features = ["serde"] }
strum = { version = "0.26", features = ["derive"] }
to-arraystring = "0.2.0"
extract_map = { version = "0.3.0", features = ["serde"] }
aformat = "0.1.3"
bytes = "1.5.0"
ref-cast = "1.0.23"
# Optional dependencies
foldhash = { version = "0.1.4", optional = true }
chrono = { version = "0.4.31", default-features = false, features = ["clock", "serde"], optional = true }
tokio = { version = "1.34.0", features = ["macros", "rt", "sync", "time", "io-util"] }
tracing = { version = "0.1.40", features = ["log"] }
typesize = { version = "0.1.13", features = ["url", "time", "serde_json", "secrecy", "parking_lot", "nonmax"] }
url = { version = "2.4.1", features = ["serde"] }

[dependencies]
# Serenity workspace crates
serenity-core = { path = "serenity-core" }

# Workspace dependencies
aformat = { workspace = true, optional = true }
dashmap = { workspace = true, optional = true }
futures = { workspace = true }
parking_lot = { workspace = true }
reqwest = { workspace = true, optional = true }
serde = { workspace = true }
serde_json = { workspace = true }
small-fixed-array = { workspace = true }
strum = { workspace = true, optional = true }
to-arraystring = { workspace = true, optional = true }
tokio = { workspace = true }
tracing = { workspace = true, optional = true }
typesize = { workspace = true, optional = true }
url = { workspace = true, optional = true }

# Additional dependencies
async-trait = "0.1.74"
ed25519-dalek = { version = "2.0.0", optional = true }
extract_map = { workspace = true, optional = true }
flate2 = { version = "1.0.28", optional = true }
zstd-safe = { version = "7.2.1", optional = true }
reqwest = { version = "0.12.2", default-features = false, features = ["multipart", "stream", "json"], optional = true }
tokio-tungstenite = { version = "0.26.1", features = ["url"], optional = true }
percent-encoding = { version = "2.3.0", optional = true }
mini-moka = { version = "0.10.2", optional = true }
mime_guess = { version = "2.0.4", optional = true }
dashmap = { version = "6.1.0", features = ["serde"], optional = true }
parking_lot = { version = "0.12.1"}
ed25519-dalek = { version = "2.0.0", optional = true }
typesize = { version = "0.1.13", optional = true, features = ["url", "time", "serde_json", "secrecy", "parking_lot", "nonmax"] }
# serde feature only allows for serialisation,
# Serenity workspace crates
serenity-voice-model = { version = "0.2.0", path = "./voice-model", optional = true }

[dev-dependencies.http_crate]
version = "1.1.0"
package = "http"
zstd-safe = { version = "7.2.1", optional = true }

[features]
# Defaults with different backends
Expand All @@ -88,40 +87,50 @@ default_no_backend = [

# Enables builder structs to configure Discord HTTP requests. Without this feature, you have to
# construct JSON manually at some places.
builder = ["tokio/fs"]
builder = ["serenity-core/builder"]
# Enables the cache, which stores the data received from Discord gateway to provide access to
# complete guild data, channels, users and more without needing HTTP requests.
cache = ["foldhash", "dashmap"]
cache = ["serenity-core/cache"]
# 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"]
collector = ["gateway", "to-arraystring"]
# Enables the Framework trait which is an abstraction for old-style text commands.
framework = ["gateway"]
# Enables gateway support, which allows bots to listen for Discord events.
gateway = ["model", "flate2", "dashmap"]
gateway = [
"model",
"aformat",
"extract_map",
"flate2",
"dashmap",
"reqwest",
"strum",
"tracing",
"url"
]
# Enables HTTP, which enables bots to execute actions on Discord.
http = ["dashmap", "mime_guess", "percent-encoding"]
http = ["serenity-core/http"]
# Enables wrapper methods around HTTP requests on model types.
# Requires "builder" to configure the requests and "http" to execute them.
# Note: the model type definitions themselves are always active, regardless of this feature.
# TODO: remove dependeny on utils feature
model = ["builder", "http", "utils"]
voice_model = ["serenity-voice-model"]
model = ["serenity-core/model", "builder", "http", "utils"]
voice_model = ["serenity-core/voice_model"]
# Enables zlib-stream transport compression of incoming gateway events.
transport_compression_zlib = ["flate2", "gateway"]
# Enables zstd-stream transport compression of incoming gateway events.
transport_compression_zstd = ["zstd-safe", "gateway"]
# Enables support for Discord API functionality that's not stable yet, as well as serenity APIs that
# are allowed to change even in semver non-breaking updates.
unstable = []
unstable = ["serenity-core/unstable"]
# Enables some utility functions that can be useful for bot creators.
utils = []
utils = ["serenity-core/utils"]
voice = ["gateway"]
# Enables unstable tokio features to give explicit names to internally spawned tokio tasks
tokio_task_builder = ["tokio/tracing"]
tokio_task_builder = ["tokio/tracing", "serenity-core/tokio_task_builder"]
interactions_endpoint = ["ed25519-dalek"]
# Uses chrono for Timestamp, instead of time
chrono = ["dep:chrono", "typesize?/chrono"]
chrono = ["serenity-core/chrono"]

# This enables all parts of the serenity codebase
# (Note: all feature-gated APIs to be documented should have their features listed here!)
Expand All @@ -130,27 +139,26 @@ chrono = ["dep:chrono", "typesize?/chrono"]
full = ["default", "collector", "voice", "voice_model", "interactions_endpoint"]

# Enables temporary caching in functions that retrieve data via the HTTP API.
temp_cache = ["cache", "mini-moka", "typesize?/mini_moka", "typesize?/dashmap"]
temp_cache = ["serenity-core/temp_cache"]

typesize = ["dep:typesize", "dashmap/typesize", "small-fixed-array/typesize", "bool_to_bitflags/typesize", "extract_map/typesize"]
typesize = ["dep:typesize", "serenity-core/typesize"]

# Enables compile-time heavy instrument macros from tracing
tracing_instrument = ["tracing/attributes"]
tracing_instrument = ["serenity-core/tracing_instrument", "tracing/attributes"]

# Backends to pick from:
# - Rustls Backends
rustls_backend = [
"reqwest/rustls-tls",
"serenity-core/rustls_backend",
"tokio-tungstenite/rustls-tls-webpki-roots",
]

# - Native TLS Backends
native_tls_backend = [
"reqwest/native-tls",
"serenity-core/native_tls_backend",
"tokio-tungstenite/native-tls",
]


[package.metadata.docs.rs]
features = ["full"]
rustdoc-args = ["--cfg", "docsrs"]
1 change: 1 addition & 0 deletions examples/testing/src/model_type_sizes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use serenity::gateway::GatewayEvent;
use serenity::model::prelude::*;

pub fn print_ranking() {
Expand Down
75 changes: 75 additions & 0 deletions serenity-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[package]
name = "serenity-core"
version = "0.12.4"

documentation.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.workspace = true
license.workspace = true
edition.workspace = true
rust-version.workspace = true

[dependencies]
# Serenity workspace crates
serenity-voice-model = { version = "0.2.0", path = "../serenity-voice-model", optional = true }

# Workspace dependencies
aformat = { workspace = true }
dashmap = { workspace = true, optional = true }
extract_map = { workspace = true }
futures = { workspace = true, optional = true }
parking_lot = { workspace = true }
reqwest = { workspace = true, optional = true }
serde = { workspace = true }
serde_json = { workspace = true }
small-fixed-array = { workspace = true }
strum = { workspace = true }
to-arraystring = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
typesize = { workspace = true, optional = true }
url = { workspace = true }

# Required dependencies
arrayvec = { version = "0.7.4", features = ["serde"] }
base64 = "0.22.0"
bitflags = "2.4.2"
bool_to_bitflags = "0.1.2"
nonmax = { version = "0.5.5", features = ["serde"] }
ref-cast = "1.0.23"
serde_cow = "0.1.0"
time = { version = "0.3.36", features = ["formatting", "parsing", "serde-well-known"] }
zeroize = "1.7"

# Optional dependencies
bytes = { version = "1.5.0", optional = true }
chrono = { version = "0.4.31", default-features = false, features = ["clock", "serde"], optional = true }
foldhash = { version = "0.1.4", optional = true }
mime_guess = { version = "2.0.4", optional = true }
percent-encoding = { version = "2.3.0", optional = true }
mini-moka = { version = "0.10.2", optional = true }

[dev-dependencies.http_crate]
version = "1.1.0"
package = "http"

[features]
builder = ["tokio/fs", "bytes"]
cache = ["foldhash", "dashmap"]
http = ["dashmap", "mime_guess", "percent-encoding"]
model = ["builder", "http", "utils", "futures"]
utils = []
chrono = ["dep:chrono", "typesize?/chrono"]
typesize = ["dep:typesize", "dashmap/typesize", "small-fixed-array/typesize", "bool_to_bitflags/typesize", "extract_map/typesize"]

unstable = []
tracing_instrument = ["tracing/attributes"]
tokio_task_builder = ["tokio/tracing"]
voice_model = ["serenity-voice-model"]

temp_cache = ["cache", "mini-moka", "typesize?/mini_moka", "typesize?/dashmap"]

rustls_backend = ["reqwest/rustls-tls"]

native_tls_backend = ["reqwest/native-tls"]
13 changes: 13 additions & 0 deletions serenity-core/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[cfg(all(feature = "http", not(any(feature = "rustls_backend", feature = "native_tls_backend"))))]
compile_error!(
"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\
If you are unsure, go with `rustls_backend`."
);

fn main() {
println!("cargo:rustc-check-cfg=cfg(tokio_unstable, ignore_serenity_deprecated)");
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use nonmax::NonMaxU8;

#[cfg(feature = "http")]
use crate::http::Http;
use crate::internal::prelude::Result;
#[cfg(feature = "http")]
use crate::internal::prelude::*;
use crate::model::id::{EntitlementId, GuildId, SkuId, UserId};
#[cfg(feature = "http")]
use crate::model::monetization::Entitlement;

/// Builds a request to fetch active and ended [`Entitlement`]s.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 7 additions & 14 deletions src/cache/mod.rs → serenity-core/src/cache/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! A cache containing data received from [`Shard`]s.
//! A cache containing data received from the API.
//!
//! Using the cache allows to avoid REST API requests via the [`http`] module where possible.
//! Issuing too many requests will lead to ratelimits.
Expand All @@ -20,7 +20,6 @@
//! is "definitely no". If you do not care about RAM and want your bot to be able to access data
//! while needing to hit the REST API as little as possible, then the answer is "yes".
//!
//! [`Shard`]: crate::gateway::Shard
//! [`http`]: crate::http
//! [Manage Guild]: Permissions::MANAGE_GUILD

Expand Down Expand Up @@ -125,7 +124,7 @@ struct CachedShardData {
has_sent_shards_ready: bool,
}

/// A cache containing data received from [`Shard`]s.
/// A cache containing data received from the API.
///
/// Using the cache allows to avoid REST API requests via the [`http`] module where possible.
/// Issuing too many requests will lead to ratelimits.
Expand All @@ -141,7 +140,6 @@ struct CachedShardData {
///
/// The documentation of each event contains the required gateway intents.
///
/// [`Shard`]: crate::gateway::Shard
/// [`http`]: crate::http
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Debug)]
Expand Down Expand Up @@ -268,10 +266,8 @@ impl Cache {
/// data received. A single [`User`] may have multiple associated member objects that have not
/// been received.
///
/// This can be used in combination with [`Shard::chunk_guild`], and can be used to determine
/// how many members have not yet been received.
///
/// [`Shard::chunk_guild`]: crate::gateway::Shard::chunk_guild
/// This can be used in combination with guild chunking, and can be used to determine how many
/// members have not yet been received.
pub fn unknown_members(&self) -> u64 {
let mut total = 0;

Expand All @@ -290,9 +286,9 @@ impl Cache {

/// Fetches a vector of all [`Guild`]s' Ids that are stored in the cache.
///
/// Note that if you are utilizing multiple [`Shard`]s, then the guilds retrieved over all
/// shards are included in this count -- not just the current [`Context`]'s shard, if accessing
/// from one.
/// Note that if you are utilizing multiple shards, then the guilds retrieved over all shards
/// are included in this count -- not just the current shard (assuming you are connecting via
/// the gateway).
///
/// # Examples
///
Expand All @@ -319,9 +315,6 @@ impl Cache {
/// }
/// }
/// ```
///
/// [`Context`]: crate::gateway::client::Context
/// [`Shard`]: crate::gateway::Shard
pub fn guilds(&self) -> Vec<GuildId> {
let unavailable_guilds = self.unavailable_guilds();

Expand Down
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions serenity-core/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! A set of constants used by the library.

use nonmax::NonMaxU16;

/// The maximum length of the textual size of an embed.
pub const EMBED_MAX_LENGTH: usize = 6000;

/// The maximum number of embeds in a message.
pub const EMBED_MAX_COUNT: usize = 10;

/// The maximum number of stickers in a message.
pub const STICKER_MAX_COUNT: usize = 3;

/// The maximum unicode code points allowed within a message by Discord.
pub const MESSAGE_CODE_LIMIT: usize = 2000;

/// The maximum number of members the bot can fetch at once
pub const MEMBER_FETCH_LIMIT: NonMaxU16 = match NonMaxU16::new(1000) {
Some(m) => m,
None => unreachable!(),
};

/// The [UserAgent] sent along with every request.
///
/// [UserAgent]: ::reqwest::header::USER_AGENT
pub const USER_AGENT: &str = concat!(
"DiscordBot (https://github.com/serenity-rs/serenity, ",
env!("CARGO_PKG_VERSION"),
")"
);
Loading
Loading