Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Dec 5, 2023
1 parent e58fe58 commit 97a9f68
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 113 deletions.
11 changes: 3 additions & 8 deletions src/gateway/bridge/shard_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use crate::model::gateway::GatewayIntents;
/// impl RawEventHandler for Handler {}
///
/// # let http: Arc<Http> = unimplemented!();
/// let ws_url = Arc::new(Mutex::new(http.get_gateway().await?.url));
/// let ws_url = Arc::from(http.get_gateway().await?.url);
/// let data = Arc::new(RwLock::new(TypeMap::new()));
/// let event_handler = Arc::new(Handler) as Arc<dyn EventHandler>;
/// let framework = Arc::new(StandardFramework::new()) as Arc<dyn Framework + 'static>;
Expand All @@ -75,12 +75,6 @@ use crate::model::gateway::GatewayIntents;
/// event_handlers: vec![event_handler],
/// raw_event_handlers: vec![],
/// framework: Arc::new(OnceLock::from(framework)),
/// // the shard index to start initiating from
/// shard_index: 0,
/// // the number of shards to initiate (this initiates 0, 1, and 2)
/// shard_init: 3,
/// // the total number of shards in use
/// shard_total: 5,
/// # #[cfg(feature = "voice")]
/// # voice_manager: None,
/// ws_url,
Expand Down Expand Up @@ -195,12 +189,13 @@ impl ShardManager {
/// Restarting a shard by ID:
///
/// ```rust,no_run
/// use serenity::model::gateway::ShardInfo;
/// use serenity::model::id::ShardId;
/// use serenity::prelude::*;
///
/// # async fn run(client: Client) {
/// // restart shard ID 7
/// client.shard_manager.restart(ShardId(7)).await;
/// client.shard_manager.restart(ShardInfo::new(ShardId(7), 10)).await;
/// # }
/// ```
///
Expand Down
87 changes: 14 additions & 73 deletions src/gateway/bridge/shard_messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,17 @@ impl ShardMessenger {
/// parameter:
///
/// ```rust,no_run
/// # use tokio::sync::Mutex;
/// # use serenity::model::gateway::{GatewayIntents, ShardInfo};
/// # use serenity::model::id::ShardId;
/// # use serenity::gateway::{ChunkGuildFilter, Shard};
/// # use std::sync::Arc;
/// #
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// # let mutex = Arc::new(Mutex::new("".to_string()));
/// #
/// # let shard_info = ShardInfo {
/// # id: ShardId(0),
/// # total: 1,
/// # };
/// # let mut shard = Shard::new(mutex.clone(), "", shard_info, GatewayIntents::all(), None).await?;
/// #
/// # async fn run(mut shard: Shard) -> Result<(), Box<dyn std::error::Error>> {
/// use serenity::model::id::GuildId;
///
/// shard.chunk_guild(GuildId::new(81384788765712384), Some(2000), false, ChunkGuildFilter::None, None);
/// shard.chunk_guild(
/// GuildId::new(81384788765712384),
/// Some(2000),
/// false,
/// ChunkGuildFilter::None,
/// None,
/// );
/// # Ok(())
/// # }
/// ```
Expand All @@ -84,22 +77,8 @@ impl ShardMessenger {
/// and a nonce of `"request"`:
///
/// ```rust,no_run
/// # use tokio::sync::Mutex;
/// # use serenity::model::gateway::{GatewayIntents, ShardInfo};
/// # use serenity::model::id::ShardId;
/// # use serenity::gateway::{ChunkGuildFilter, Shard};
/// # use std::sync::Arc;
/// #
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// # let mutex = Arc::new(Mutex::new("".to_string()));
/// #
/// # let shard_info = ShardInfo {
/// # id: ShardId(0),
/// # total: 1,
/// # };
/// #
/// # let mut shard = Shard::new(mutex.clone(), "", shard_info, GatewayIntents::all(), None).await?;;
/// #
/// # async fn run(mut shard: Shard) -> Result<(), Box<dyn std::error::Error>> {
/// use serenity::model::id::GuildId;
///
/// shard.chunk_guild(
Expand Down Expand Up @@ -138,21 +117,8 @@ impl ShardMessenger {
/// Setting the current activity to playing `"Heroes of the Storm"`:
///
/// ```rust,no_run
/// # use tokio::sync::Mutex;
/// # use serenity::gateway::{Shard};
/// # use serenity::model::id::ShardId;
/// # use serenity::model::gateway::{GatewayIntents, ShardInfo};
/// # use std::sync::Arc;
/// #
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// # let mutex = Arc::new(Mutex::new("".to_string()));
/// #
/// # let shard_info = ShardInfo {
/// # id: ShardId(0),
/// # total: 1,
/// # };
/// #
/// # let mut shard = Shard::new(mutex.clone(), "", shard_info, GatewayIntents::all(), None).await?;
/// # use serenity::gateway::Shard;
/// # async fn run(mut shard: Shard) -> Result<(), Box<dyn std::error::Error>> {
/// use serenity::gateway::ActivityData;
///
/// shard.set_activity(Some(ActivityData::playing("Heroes of the Storm")));
Expand All @@ -172,20 +138,8 @@ impl ShardMessenger {
/// Set the current user as playing `"Heroes of the Storm"` and being online:
///
/// ```rust,ignore
/// # use tokio::sync::Mutex;
/// # use serenity::gateway::Shard;
/// # use std::sync::Arc;
/// #
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// # let mutex = Arc::new(Mutex::new("".to_string()));
/// #
/// # let shard_info = ShardInfo {
/// # id: 0,
/// # total: 1,
/// # };
/// #
/// # let mut shard = Shard::new(mutex.clone(), "", shard_info, None).await?;
/// #
/// # async fn run(shard: Shard) -> Result<(), Box<dyn std::error::Error>> {
/// use serenity::gateway::ActivityData;
/// use serenity::model::user::OnlineStatus;
///
Expand Down Expand Up @@ -214,21 +168,8 @@ impl ShardMessenger {
/// Setting the current online status for the shard to [`DoNotDisturb`].
///
/// ```rust,no_run
/// # use tokio::sync::Mutex;
/// # use serenity::gateway::{Shard};
/// # use serenity::model::id::ShardId;
/// # use serenity::model::gateway::{GatewayIntents, ShardInfo};
/// # use std::sync::Arc;
/// #
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// # let mutex = Arc::new(Mutex::new("".to_string()));
/// # let shard_info = ShardInfo {
/// # id: ShardId(0),
/// # total: 1,
/// # };
/// #
/// # let mut shard = Shard::new(mutex.clone(), "", shard_info, GatewayIntents::all(), None).await?;
/// #
/// # use serenity::gateway::Shard;
/// # async fn run(mut shard: Shard) -> Result<(), Box<dyn std::error::Error>> {
/// use serenity::model::user::OnlineStatus;
///
/// shard.set_status(OnlineStatus::DoNotDisturb);
Expand Down
43 changes: 12 additions & 31 deletions src/gateway/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Shard {
/// };
///
/// // retrieve the gateway response, which contains the URL to connect to
/// let gateway = Arc::new(Mutex::new(http.get_gateway().await?.url));
/// let gateway = Arc::from(http.get_gateway().await?.url);
/// let shard = Shard::new(gateway, &token, shard_info, GatewayIntents::all(), None).await?;
///
/// // at this point, you can create a `loop`, and receive events and match
Expand Down Expand Up @@ -593,24 +593,19 @@ impl Shard {
/// specifying a query parameter:
///
/// ```rust,no_run
/// # use tokio::sync::Mutex;
/// # use serenity::gateway::{ChunkGuildFilter, Shard};
/// # use serenity::model::gateway::{GatewayIntents, ShardInfo};
/// # use serenity::model::id::ShardId;
/// # use std::sync::Arc;
/// #
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// # let mutex = Arc::new(Mutex::new("".to_string()));
/// # let shard_info = ShardInfo {
/// # id: ShardId(0),
/// # total: 1,
/// # };
/// #
/// # let mut shard = Shard::new(mutex.clone(), "", shard_info, GatewayIntents::all(), None).await?;
/// #
/// # async fn run(shard: Shard) -> Result<(), Box<dyn std::error::Error>> {
/// use serenity::model::id::GuildId;
///
/// shard.chunk_guild(GuildId::new(81384788765712384), Some(2000), false, ChunkGuildFilter::None, None).await?;
/// shard
/// .chunk_guild(

Check failure on line 601 in src/gateway/shard.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

cannot borrow `shard` as mutable, as it is not declared as mutable

Check failure on line 601 in src/gateway/shard.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

cannot borrow `shard` as mutable, as it is not declared as mutable

Check failure on line 601 in src/gateway/shard.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

cannot borrow `shard` as mutable, as it is not declared as mutable

Check failure on line 601 in src/gateway/shard.rs

View workflow job for this annotation

GitHub Actions / Test (Windows)

cannot borrow `shard` as mutable, as it is not declared as mutable

Check failure on line 601 in src/gateway/shard.rs

View workflow job for this annotation

GitHub Actions / Test (native-tls)

cannot borrow `shard` as mutable, as it is not declared as mutable

Check failure on line 601 in src/gateway/shard.rs

View workflow job for this annotation

GitHub Actions / Test (macOS)

cannot borrow `shard` as mutable, as it is not declared as mutable

Check failure on line 601 in src/gateway/shard.rs

View workflow job for this annotation

GitHub Actions / Test (no cache)

cannot borrow `shard` as mutable, as it is not declared as mutable

Check failure on line 601 in src/gateway/shard.rs

View workflow job for this annotation

GitHub Actions / Test (unstable Discord API features)

cannot borrow `shard` as mutable, as it is not declared as mutable

Check failure on line 601 in src/gateway/shard.rs

View workflow job for this annotation

GitHub Actions / Test (simd-json)

cannot borrow `shard` as mutable, as it is not declared as mutable
/// GuildId::new(81384788765712384),
/// Some(2000),
/// false,
/// ChunkGuildFilter::None,
/// None,
/// )
/// .await?;
/// # Ok(())
/// # }
/// ```
Expand All @@ -619,22 +614,8 @@ impl Shard {
/// `"do"` and a nonce of `"request"`:
///
/// ```rust,no_run
/// # use tokio::sync::Mutex;
/// # use serenity::model::gateway::{GatewayIntents, ShardInfo};
/// # use serenity::gateway::{ChunkGuildFilter, Shard};
/// # use serenity::model::id::ShardId;
/// # use std::error::Error;
/// # use std::sync::Arc;
/// #
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// # let mutex = Arc::new(Mutex::new("".to_string()));
/// #
/// # let shard_info = ShardInfo {
/// # id: ShardId(0),
/// # total: 1,
/// # };
/// # let mut shard = Shard::new(mutex.clone(), "", shard_info, GatewayIntents::all(), None).await?;
/// #
/// # async fn run(shard: Shard) -> Result<(), Box<dyn std::error::Error>> {
/// use serenity::model::id::GuildId;
///
/// shard
Expand Down
2 changes: 1 addition & 1 deletion src/model/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ pub struct ShardInfo {

impl ShardInfo {
#[must_use]
pub(crate) fn new(id: ShardId, total: u32) -> Self {
pub fn new(id: ShardId, total: u32) -> Self {
Self {
id,
total,
Expand Down

0 comments on commit 97a9f68

Please sign in to comment.