forked from serenity-rs/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial dirty attempt at crate split
- Loading branch information
1 parent
f1b4e98
commit 9c5787c
Showing
147 changed files
with
437 additions
and
1,094 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
[package] | ||
name = "serenity-core" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
bitflags = "2.4.2" | ||
base64 = { version = "0.22.0" } | ||
serde_json = "1.0.108" | ||
serde = { version = "1.0.192", features = ["derive", "rc"] } | ||
nonmax = { version = "0.5.5", features = ["serde"] } | ||
to-arraystring = "0.2.0" | ||
tokio = { version = "1.34.0", features = ["macros", "rt", "sync", "time", "io-util"] } | ||
zeroize = { version = "1.7" } # Not used in serenity, but bumps the minimal version from secrecy | ||
strum = { version = "0.26", features = ["derive"] } | ||
fxhash = { version = "0.2.1", optional = true } | ||
chrono = { version = "0.4.31", default-features = false, features = ["clock", "serde"], optional = true } | ||
dashmap = { version = "6.1.0", features = ["serde"], optional = true } | ||
mime_guess = { version = "2.0.4", optional = true } | ||
percent-encoding = { version = "2.3.0", optional = true } | ||
small-fixed-array = { version = "0.4", features = ["serde"] } | ||
bool_to_bitflags = { version = "0.1.2" } | ||
futures = { version = "0.3.29", default-features = false, features = ["std"] } | ||
reqwest = { version = "0.12.2", default-features = false, features = ["multipart", "stream", "json"], optional = true } | ||
tokio-tungstenite = { version = "0.21.0", optional = true } | ||
typesize = { version = "0.1.6", optional = true, features = ["url", "time", "serde_json", "secrecy", "parking_lot", "nonmax", "extract_map_01"] } | ||
extract_map = { version = "0.1.0", features = ["serde", "iter_mut"] } | ||
serde_cow = { version = "0.1.0" } | ||
aformat = "0.1.3" | ||
arrayvec = { version = "0.7.4", features = ["serde"] } | ||
url = { version = "2.4.1", features = ["serde"] } | ||
bytes = "1.5.0" | ||
parking_lot = { version = "0.12.1"} | ||
mini-moka = { version = "0.10.2", optional = true } | ||
tracing = { version = "0.1.40", features = ["log"] } | ||
serenity-voice-model = { version = "0.2.0", path = "../voice-model", optional = true } | ||
|
||
[features] | ||
default = ["cache", "chrono", "model", "rustls_backend"] | ||
|
||
builder = ["tokio/fs"] | ||
cache = ["fxhash", "dashmap"] | ||
http = ["dashmap", "mime_guess", "percent-encoding"] | ||
model = ["builder", "http", "utils"] | ||
utils = [] | ||
chrono = ["dep:chrono", "typesize?/chrono"] | ||
typesize = ["dep:typesize", "dashmap/typesize", "small-fixed-array/typesize", "bool_to_bitflags/typesize"] | ||
temp_cache = ["cache", "mini-moka", "typesize?/mini_moka"] | ||
unstable = [] | ||
tracing_instrument = ["tracing/attributes"] | ||
tokio_task_builder = ["tokio/tracing"] | ||
voice_model = ["serenity-voice-model"] | ||
|
||
rustls_backend = [ | ||
"reqwest/rustls-tls", | ||
"tokio-tungstenite/rustls-tls-webpki-roots", | ||
] | ||
|
||
native_tls_backend = [ | ||
"reqwest/native-tls", | ||
"tokio-tungstenite/native-tls", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
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.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
")" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
use std::error::Error as StdError; | ||
use std::fmt; | ||
use std::io::Error as IoError; | ||
|
||
#[cfg(feature = "http")] | ||
use reqwest::{header::InvalidHeaderValue, Error as ReqwestError}; | ||
|
||
#[cfg(feature = "http")] | ||
use crate::http::HttpError; | ||
use crate::internal::prelude::*; | ||
use crate::model::ModelError; | ||
use crate::secrets::TokenError; | ||
|
||
/// The common result type between most library functions. | ||
/// | ||
/// The library exposes functions which, for a result type, exposes only one type, rather than the | ||
/// usual 2 (`Result<T, Error>`). This is because all functions that return a result return | ||
/// serenity's [`Error`], so this is implied, and a "simpler" result is used. | ||
pub type Result<T, E = Error> = StdResult<T, E>; | ||
|
||
/// A common error enum returned by most of the library's functionality within a custom [`Result`]. | ||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub enum Error { | ||
/// An [`std::io`] error. | ||
Io(IoError), | ||
/// An error from the [`serde_json`] crate. | ||
Json(serde_json::Error), | ||
/// An error from the [`model`] module. | ||
/// | ||
/// [`model`]: crate::model | ||
Model(ModelError), | ||
/// An error from the [`http`] module. | ||
/// | ||
/// [`http`]: crate::http | ||
#[cfg(feature = "http")] | ||
Http(HttpError), | ||
/// An error from the [`secrets`] module. | ||
/// | ||
/// [`secrets`]: crate::secrets | ||
Token(TokenError), | ||
} | ||
|
||
impl From<IoError> for Error { | ||
fn from(e: IoError) -> Error { | ||
Error::Io(e) | ||
} | ||
} | ||
|
||
impl From<serde_json::Error> for Error { | ||
fn from(e: serde_json::Error) -> Error { | ||
Error::Json(e) | ||
} | ||
} | ||
|
||
impl From<ModelError> for Error { | ||
fn from(e: ModelError) -> Error { | ||
Error::Model(e) | ||
} | ||
} | ||
|
||
#[cfg(feature = "http")] | ||
impl From<HttpError> for Error { | ||
fn from(e: HttpError) -> Error { | ||
Error::Http(e) | ||
} | ||
} | ||
|
||
impl From<TokenError> for Error { | ||
fn from(e: TokenError) -> Error { | ||
Error::Token(e) | ||
} | ||
} | ||
|
||
#[cfg(feature = "http")] | ||
impl From<InvalidHeaderValue> for Error { | ||
fn from(e: InvalidHeaderValue) -> Error { | ||
HttpError::InvalidHeader(e).into() | ||
} | ||
} | ||
|
||
#[cfg(feature = "http")] | ||
impl From<ReqwestError> for Error { | ||
fn from(e: ReqwestError) -> Error { | ||
HttpError::Request(e).into() | ||
} | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
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 = "http")] | ||
Self::Http(inner) => fmt::Display::fmt(&inner, f), | ||
Self::Token(inner) => fmt::Display::fmt(&inner, f), | ||
} | ||
} | ||
} | ||
|
||
impl StdError for Error { | ||
#[cfg_attr(feature = "tracing_instrument", instrument)] | ||
fn source(&self) -> Option<&(dyn StdError + 'static)> { | ||
match self { | ||
Self::Io(inner) => Some(inner), | ||
Self::Json(inner) => Some(inner), | ||
Self::Model(inner) => Some(inner), | ||
#[cfg(feature = "http")] | ||
Self::Http(inner) => Some(inner), | ||
Self::Token(inner) => Some(inner), | ||
} | ||
} | ||
} |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#[macro_use] | ||
extern crate serde; | ||
|
||
#[macro_use] | ||
mod internal; | ||
|
||
mod constants; | ||
pub mod secrets; | ||
|
||
pub mod builder; | ||
pub mod cache; | ||
pub mod error; | ||
pub mod http; | ||
pub mod model; | ||
pub mod utils; |
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.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.