mod bridge;
mod error;
mod shard;
mod ws;
use std::fmt;
#[cfg(feature = "http")]
use reqwest::IntoUrl;
use reqwest::Url;
pub use self::bridge::*;
pub use self::error::Error as GatewayError;
pub use self::shard::Shard;
pub use self::ws::WsClient;
#[cfg(feature = "http")]
use crate::internal::prelude::*;
use crate::model::gateway::{Activity, ActivityType};
use crate::model::id::UserId;
use crate::model::user::OnlineStatus;
#[derive(Clone, Debug, Default)]
pub struct PresenceData {
pub activity: Option<ActivityData>,
pub status: OnlineStatus,
}
#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
pub struct ActivityData {
pub name: String,
#[serde(rename = "type")]
pub kind: ActivityType,
pub state: Option<String>,
pub url: Option<Url>,
}
impl ActivityData {
#[must_use]
pub fn playing(name: impl Into<String>) -> Self {
Self {
name: name.into(),
kind: ActivityType::Playing,
state: None,
url: None,
}
}
#[cfg(feature = "http")]
pub fn streaming(name: impl Into<String>, url: impl IntoUrl) -> Result<Self> {
Ok(Self {
name: name.into(),
kind: ActivityType::Streaming,
state: None,
url: Some(url.into_url()?),
})
}
#[must_use]
pub fn listening(name: impl Into<String>) -> Self {
Self {
name: name.into(),
kind: ActivityType::Listening,
state: None,
url: None,
}
}
#[must_use]
pub fn watching(name: impl Into<String>) -> Self {
Self {
name: name.into(),
kind: ActivityType::Watching,
state: None,
url: None,
}
}
#[must_use]
pub fn competing(name: impl Into<String>) -> Self {
Self {
name: name.into(),
kind: ActivityType::Competing,
state: None,
url: None,
}
}
#[must_use]
pub fn custom(state: impl Into<String>) -> Self {
Self {
name: "~".to_string(),
kind: ActivityType::Custom,
state: Some(state.into()),
url: None,
}
}
}
impl From<Activity> for ActivityData {
fn from(activity: Activity) -> Self {
Self {
name: activity.name,
kind: activity.kind,
state: activity.state,
url: activity.url,
}
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
pub enum ConnectionStage {
Connected,
Connecting,
Disconnected,
Handshake,
Identifying,
Resuming,
}
impl ConnectionStage {
#[must_use]
pub fn is_connecting(self) -> bool {
use self::ConnectionStage::{Connecting, Handshake, Identifying, Resuming};
matches!(self, Connecting | Handshake | Identifying | Resuming)
}
}
impl fmt::Display for ConnectionStage {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match *self {
Self::Connected => "connected",
Self::Connecting => "connecting",
Self::Disconnected => "disconnected",
Self::Handshake => "handshaking",
Self::Identifying => "identifying",
Self::Resuming => "resuming",
})
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum ShardAction {
Heartbeat,
Identify,
Reconnect(ReconnectType),
}
#[derive(Debug)]
#[non_exhaustive]
pub enum ReconnectType {
Reidentify,
Resume,
}
#[derive(Clone, Debug)]
pub enum ChunkGuildFilter {
None,
Query(String),
UserIds(Vec<UserId>),
}