Support for Twilight 0.16 (#227)

This commit is contained in:
Erk
2025-01-14 08:00:34 +01:00
committed by Kyle Simpson
parent 1c52e6ebc0
commit b46a568fb5
6 changed files with 76 additions and 70 deletions

View File

@@ -8,7 +8,7 @@ use serenity::gateway::ShardRunnerMessage;
#[cfg(feature = "gateway")]
use std::{error::Error, fmt};
#[cfg(feature = "twilight")]
use twilight_gateway::error::SendError;
use twilight_gateway::error::ChannelError;
#[cfg(feature = "gateway")]
#[derive(Debug)]
@@ -48,7 +48,7 @@ pub enum JoinError {
Serenity(Box<TrySendError<ShardRunnerMessage>>),
#[cfg(feature = "twilight")]
/// Twilight-specific WebSocket send error when a message fails to send over websocket.
Twilight(SendError),
Twilight(ChannelError),
}
#[cfg(feature = "gateway")]
@@ -121,8 +121,8 @@ impl From<Box<TrySendError<ShardRunnerMessage>>> for JoinError {
}
#[cfg(all(feature = "twilight", feature = "gateway"))]
impl From<SendError> for JoinError {
fn from(e: SendError) -> Self {
impl From<ChannelError> for JoinError {
fn from(e: ChannelError) -> Self {
JoinError::Twilight(e)
}
}

View File

@@ -29,7 +29,7 @@ use twilight_model::gateway::payload::outgoing::update_voice_state::UpdateVoiceS
#[cfg(feature = "twilight")]
#[derive(Debug)]
pub struct TwilightMap {
map: std::collections::HashMap<u64, MessageSender>,
map: std::collections::HashMap<u32, MessageSender>,
}
#[cfg(feature = "twilight")]
@@ -38,13 +38,13 @@ impl TwilightMap {
///
/// For correctness all shards should be in the map.
#[must_use]
pub fn new(map: std::collections::HashMap<u64, MessageSender>) -> Self {
pub fn new(map: std::collections::HashMap<u32, MessageSender>) -> Self {
TwilightMap { map }
}
/// Get the message sender for `shard_id`.
#[must_use]
pub fn get(&self, shard_id: u64) -> Option<&MessageSender> {
pub fn get(&self, shard_id: u32) -> Option<&MessageSender> {
self.map.get(&shard_id)
}
@@ -90,7 +90,7 @@ impl Sharder {
s.get_or_insert_shard_handle(shard_id as u32),
)),
#[cfg(feature = "twilight")]
Sharder::Twilight(t) => Some(Shard::Twilight(t.clone(), shard_id)),
Sharder::Twilight(t) => Some(Shard::Twilight(t.clone(), shard_id as u32)),
Sharder::Generic(src) => src.get_shard(shard_id).map(Shard::Generic),
}
}
@@ -156,7 +156,7 @@ pub enum Shard {
Serenity(Arc<SerenityShardHandle>),
#[cfg(feature = "twilight")]
/// Handle to a map of twilight command senders.
Twilight(Arc<TwilightMap>, u64),
Twilight(Arc<TwilightMap>, u32),
/// Handle to a generic shard instance.
Generic(#[derivative(Debug = "ignore")] Arc<dyn VoiceUpdate + Send + Sync>),
}