Skip to content

Commit 0506c3b

Browse files
committed
Split GuildThread from GuildChannel
1 parent 099315f commit 0506c3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1228
-1057
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ to-arraystring = "0.2.0"
3939
extract_map = { version = "0.1.0", features = ["serde", "iter_mut"] }
4040
aformat = "0.1.3"
4141
bytes = "1.5.0"
42+
ref-cast = "1.0.23"
4243
# Optional dependencies
4344
fxhash = { version = "0.2.1", optional = true }
4445
chrono = { version = "0.4.31", default-features = false, features = ["clock", "serde"], optional = true }

examples/e12_parallel_loops/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serenity::builder::{CreateEmbed, CreateMessage};
88
use serenity::gateway::ActivityData;
99
use serenity::model::channel::Message;
1010
use serenity::model::gateway::Ready;
11-
use serenity::model::id::{ChannelId, GuildId};
11+
use serenity::model::id::{GenericChannelId, GuildId};
1212
use serenity::prelude::*;
1313

1414
struct Handler {
@@ -85,7 +85,7 @@ async fn log_system_load(ctx: &Context) {
8585
false,
8686
);
8787
let builder = CreateMessage::new().embed(embed);
88-
let message = ChannelId::new(381926291785383946).send_message(&ctx.http, builder).await;
88+
let message = GenericChannelId::new(381926291785383946).send_message(&ctx.http, builder).await;
8989
if let Err(why) = message {
9090
eprintln!("Error sending message: {why:?}");
9191
};

examples/testing/src/main.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ async fn message(ctx: &Context, msg: Message) -> Result<(), serenity::Error> {
8585
model_type_sizes::print_ranking();
8686
} else if msg.content == "auditlog" {
8787
// Test special characters in audit log reason
88-
msg.channel_id
88+
channel_id
89+
.expect_channel()
8990
.edit(
9091
&ctx.http,
9192
EditChannel::new().name("new-channel-name").audit_log_reason("hello\nworld\n🙂"),
@@ -153,6 +154,7 @@ async fn message(ctx: &Context, msg: Message) -> Result<(), serenity::Error> {
153154
guild_id.ban(&ctx.http, user_id, 0, None).await?;
154155
} else if msg.content == "createtags" {
155156
channel_id
157+
.expect_channel()
156158
.edit(
157159
&ctx.http,
158160
EditChannel::new().available_tags(vec![
@@ -163,9 +165,10 @@ async fn message(ctx: &Context, msg: Message) -> Result<(), serenity::Error> {
163165
.await?;
164166
} else if msg.content == "assigntags" {
165167
let forum_id = msg.guild_channel(&ctx).await?.parent_id.unwrap();
166-
let forum = forum_id.to_guild_channel(&ctx, msg.guild_id).await?;
168+
let forum = forum_id.widen().to_guild_channel(&ctx, msg.guild_id).await?;
167169
channel_id
168-
.edit_thread(
170+
.expect_thread()
171+
.edit(
169172
&ctx.http,
170173
EditThread::new()
171174
.applied_tags(forum.available_tags.iter().map(|t| t.id).collect::<Vec<_>>()),
@@ -197,7 +200,7 @@ async fn message(ctx: &Context, msg: Message) -> Result<(), serenity::Error> {
197200
msg.author.id.dm(&ctx.http, builder).await?;
198201
} else if let Some(channel) = msg.content.strip_prefix("movetorootandback") {
199202
let mut channel = {
200-
let channel_id = channel.trim().parse::<ChannelId>().unwrap();
203+
let channel_id = channel.trim().parse::<GenericChannelId>().unwrap();
201204
channel_id.to_guild_channel(&ctx, msg.guild_id).await.unwrap()
202205
};
203206

examples/testing/src/model_type_sizes.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub fn print_ranking() {
6565
("GuildBanAddEvent", std::mem::size_of::<GuildBanAddEvent>()),
6666
("GuildBanRemoveEvent", std::mem::size_of::<GuildBanRemoveEvent>()),
6767
("GuildChannel", std::mem::size_of::<GuildChannel>()),
68+
("GuildThread", std::mem::size_of::<GuildThread>()),
6869
("GuildCreateEvent", std::mem::size_of::<GuildCreateEvent>()),
6970
("GuildDeleteEvent", std::mem::size_of::<GuildDeleteEvent>()),
7071
("GuildEmojisUpdateEvent", std::mem::size_of::<GuildEmojisUpdateEvent>()),
@@ -131,10 +132,12 @@ pub fn print_ranking() {
131132
("ModalInteraction", std::mem::size_of::<ModalInteraction>()),
132133
("ModalInteractionData", std::mem::size_of::<ModalInteractionData>()),
133134
("AuditLogEntryOptions", std::mem::size_of::<AuditLogEntryOptions>()),
134-
("PartialChannel", std::mem::size_of::<PartialChannel>()),
135+
("GenericInteractionChannel", std::mem::size_of::<GenericInteractionChannel>()),
136+
("InteractionChannel", std::mem::size_of::<InteractionChannel>()),
137+
("InteractionGuildThread", std::mem::size_of::<InteractionGuildThread>()),
135138
("PartialCurrentApplicationInfo", std::mem::size_of::<PartialCurrentApplicationInfo>()),
136139
("PartialGuild", std::mem::size_of::<PartialGuild>()),
137-
("PartialGuildChannel", std::mem::size_of::<PartialGuildChannel>()),
140+
("PartialGuildThread", std::mem::size_of::<PartialGuildThread>()),
138141
("PartialMember", std::mem::size_of::<PartialMember>()),
139142
("PermissionOverwrite", std::mem::size_of::<PermissionOverwrite>()),
140143
("Permissions", std::mem::size_of::<Permissions>()),

src/builder/create_allowed_mentions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ impl ParseAction {
2828
}
2929
}
3030

31-
/// A builder to manage the allowed mentions on a message, used by the [`ChannelId::send_message`]
32-
/// and [`ChannelId::edit_message`] methods.
31+
/// A builder to manage the allowed mentions on a message.
3332
///
3433
/// # Examples
3534
///

src/builder/create_components.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub enum CreateSelectMenuKind<'a> {
224224
},
225225
Channel {
226226
channel_types: Option<Cow<'a, [ChannelType]>>,
227-
default_channels: Option<Cow<'a, [ChannelId]>>,
227+
default_channels: Option<Cow<'a, [GenericChannelId]>>,
228228
},
229229
}
230230

src/builder/create_embed.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,11 @@ impl<'a> CreateEmbed<'a> {
185185

186186
/// Same as calling [`Self::image`] with "attachment://filename.(jpg, png)".
187187
///
188-
/// Note however, you have to be sure you set an attachment (with [`ChannelId::send_files`])
189-
/// with the provided filename. Or else this won't work.
188+
/// Remember to set an attachment with the provided filename via [`CreateAttachment`]
190189
///
191190
/// Refer [`Self::image`] for rules on naming local attachments.
192191
///
193-
/// [`ChannelId::send_files`]: crate::model::id::ChannelId::send_files
192+
/// [`CreateAttachment`]: crate::builder::CreateAttachment
194193
pub fn attachment(self, filename: impl Into<String>) -> Self {
195194
let mut filename = filename.into();
196195
filename.insert_str(0, "attachment://");

src/builder/create_message.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::internal::prelude::*;
1616
use crate::model::prelude::*;
1717

1818
/// A builder to specify the contents of an send message request, primarily meant for use
19-
/// through [`ChannelId::send_message`].
19+
/// through [`GenericChannelId::send_message`].
2020
///
2121
/// There are three situations where different field requirements are present:
2222
///
@@ -27,21 +27,21 @@ use crate::model::prelude::*;
2727
/// required.
2828
///
2929
/// Note that if you only need to send the content of a message, without specifying other fields,
30-
/// then [`ChannelId::say`] may be a more preferable option.
30+
/// then [`GenericChannelId::say`] may be a more preferable option.
3131
///
3232
/// # Examples
3333
///
3434
/// Sending a message with a content of `"test"` and applying text-to-speech:
3535
///
3636
/// ```rust,no_run
3737
/// use serenity::builder::{CreateEmbed, CreateMessage};
38-
/// use serenity::model::id::ChannelId;
38+
/// use serenity::model::id::GenericChannelId;
3939
/// # use serenity::http::Http;
4040
/// # use std::sync::Arc;
4141
/// #
4242
/// # async fn run() {
4343
/// # let http: Arc<Http> = unimplemented!();
44-
/// # let channel_id = ChannelId::new(7);
44+
/// # let channel_id = GenericChannelId::new(7);
4545
/// let embed = CreateEmbed::new().title("This is an embed").description("With a description");
4646
/// let builder = CreateMessage::new().content("test").tts(true).embed(embed);
4747
/// let _ = channel_id.send_message(&http, builder).await;
@@ -290,7 +290,7 @@ impl<'a> CreateMessage<'a> {
290290
pub async fn execute(
291291
mut self,
292292
http: &Http,
293-
channel_id: ChannelId,
293+
channel_id: GenericChannelId,
294294
guild_id: Option<GuildId>,
295295
) -> Result<Message> {
296296
self.check_length()?;

src/builder/create_scheduled_event.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ impl<'a> CreateScheduledEvent<'a> {
131131
///
132132
/// [Create Events]: Permissions::CREATE_EVENTS
133133
#[cfg(feature = "http")]
134-
pub async fn execute(self, http: &Http, channel_id: GuildId) -> Result<ScheduledEvent> {
135-
http.create_scheduled_event(channel_id, &self, self.audit_log_reason).await
134+
pub async fn execute(self, http: &Http, guild_id: GuildId) -> Result<ScheduledEvent> {
135+
http.create_scheduled_event(guild_id, &self, self.audit_log_reason).await
136136
}
137137
}
138138

src/builder/edit_channel.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ impl<'a> EditChannel<'a> {
331331
.await?;
332332
}
333333

334-
http.edit_channel(channel_id, &self, self.audit_log_reason).await
334+
http.edit_channel(channel_id.widen(), &self, self.audit_log_reason)
335+
.await?
336+
.guild()
337+
.ok_or(Error::Model(ModelError::InvalidChannelType))
335338
}
336339
}

src/builder/edit_guild_welcome_screen.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ impl<'a> EditGuildWelcomeScreen<'a> {
8282
#[derive(Clone, Debug, Serialize)]
8383
#[must_use]
8484
pub struct CreateGuildWelcomeChannel<'a> {
85-
channel_id: ChannelId,
85+
channel_id: GenericChannelId,
8686
emoji_name: Option<String>,
8787
emoji_id: Option<EmojiId>,
8888
description: Cow<'a, str>,
8989
}
9090

9191
impl<'a> CreateGuildWelcomeChannel<'a> {
92-
pub fn new(channel_id: ChannelId, description: impl Into<Cow<'a, str>>) -> Self {
92+
pub fn new(channel_id: GenericChannelId, description: impl Into<Cow<'a, str>>) -> Self {
9393
Self {
9494
channel_id,
9595
emoji_id: None,
@@ -99,7 +99,7 @@ impl<'a> CreateGuildWelcomeChannel<'a> {
9999
}
100100

101101
/// The Id of the channel to show.
102-
pub fn id(mut self, id: ChannelId) -> Self {
102+
pub fn id(mut self, id: GenericChannelId) -> Self {
103103
self.channel_id = id;
104104
self
105105
}

src/builder/edit_message.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a> EditMessage<'a> {
115115
/// ```rust,no_run
116116
/// # use serenity::all::*;
117117
/// # #[cfg(feature = "collector")]
118-
/// # async fn test(ctx: &Context, channel_id: ChannelId) -> Result<(), Error> {
118+
/// # async fn test(ctx: &Context, channel_id: GenericChannelId) -> Result<(), Error> {
119119
/// use std::time::Duration;
120120
///
121121
/// use futures::StreamExt;
@@ -239,7 +239,7 @@ impl<'a> EditMessage<'a> {
239239
pub async fn execute(
240240
mut self,
241241
cache_http: impl CacheHttp,
242-
channel_id: ChannelId,
242+
channel_id: GenericChannelId,
243243
message_id: MessageId,
244244
user_id: Option<UserId>,
245245
) -> Result<Message> {

src/builder/edit_thread.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,12 @@ impl<'a> EditThread<'a> {
108108
/// # Errors
109109
///
110110
/// Returns [`Error::Http`] if the current user lacks permission.
111+
/// Returns [`ModelError::InvalidChannelType`] if the `ThreadId` is not identifying a thread.
111112
#[cfg(feature = "http")]
112-
pub async fn execute(self, http: &Http, channel_id: ChannelId) -> Result<GuildChannel> {
113-
http.edit_thread(channel_id, &self, self.audit_log_reason).await
113+
pub async fn execute(self, http: &Http, thread_id: ThreadId) -> Result<GuildThread> {
114+
http.edit_channel(thread_id.widen(), &self, self.audit_log_reason)
115+
.await?
116+
.thread()
117+
.ok_or(Error::Model(ModelError::InvalidChannelType))
114118
}
115119
}

src/builder/edit_webhook_message.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct EditWebhookMessage<'a> {
3131
pub(crate) attachments: Option<EditAttachments<'a>>,
3232

3333
#[serde(skip)]
34-
thread_id: Option<ChannelId>,
34+
thread_id: Option<ThreadId>,
3535
}
3636

3737
impl<'a> EditWebhookMessage<'a> {
@@ -55,7 +55,7 @@ impl<'a> EditWebhookMessage<'a> {
5555

5656
/// Edits a message within a given thread. If the provided thread Id doesn't belong to the
5757
/// current webhook, the API will return an error.
58-
pub fn in_thread(mut self, thread_id: ChannelId) -> Self {
58+
pub fn in_thread(mut self, thread_id: ThreadId) -> Self {
5959
self.thread_id = Some(thread_id);
6060
self
6161
}

src/builder/execute_webhook.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub struct ExecuteWebhook<'a> {
7676
attachments: EditAttachments<'a>,
7777

7878
#[serde(skip)]
79-
thread_id: Option<ChannelId>,
79+
thread_id: Option<ThreadId>,
8080
}
8181

8282
impl<'a> ExecuteWebhook<'a> {
@@ -159,19 +159,19 @@ impl<'a> ExecuteWebhook<'a> {
159159
/// ```rust,no_run
160160
/// # use serenity::builder::ExecuteWebhook;
161161
/// # use serenity::http::Http;
162-
/// # use serenity::model::{id::ChannelId, webhook::Webhook};
162+
/// # use serenity::model::{id::ThreadId, webhook::Webhook};
163163
/// #
164164
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
165165
/// # let http: Http = unimplemented!();
166166
/// let url = "https://discord.com/api/webhooks/245037420704169985/ig5AO-wdVWpCBtUUMxmgsWryqgsW3DChbKYOINftJ4DCrUbnkedoYZD0VOH1QLr-S3sV";
167167
/// let mut webhook = Webhook::from_url(&http, url).await?;
168168
///
169-
/// let builder = ExecuteWebhook::new().in_thread(ChannelId::new(12345678)).content("test");
169+
/// let builder = ExecuteWebhook::new().in_thread(ThreadId::new(12345678)).content("test");
170170
/// webhook.execute(&http, false, builder).await?;
171171
/// # Ok(())
172172
/// # }
173173
/// ```
174-
pub fn in_thread(mut self, thread_id: ChannelId) -> Self {
174+
pub fn in_thread(mut self, thread_id: ThreadId) -> Self {
175175
self.thread_id = Some(thread_id);
176176
self
177177
}

src/builder/get_messages.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::model::prelude::*;
2121
/// The other parameter specifies the number of messages to retrieve. This is _optional_, and
2222
/// defaults to 50 if not specified.
2323
///
24-
/// See [`ChannelId::messages`] for more examples.
24+
/// See [`GenericChannelId::messages`] for more examples.
2525
///
2626
/// # Examples
2727
///
@@ -34,10 +34,10 @@ use crate::model::prelude::*;
3434
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
3535
/// # let http: Http = unimplemented!();
3636
/// use serenity::builder::GetMessages;
37-
/// use serenity::model::id::{ChannelId, MessageId};
37+
/// use serenity::model::id::{GenericChannelId, MessageId};
3838
///
3939
/// // you can then pass it into a function which retrieves messages:
40-
/// let channel_id = ChannelId::new(81384788765712384);
40+
/// let channel_id = GenericChannelId::new(81384788765712384);
4141
///
4242
/// let builder = GetMessages::new().after(MessageId::new(158339864557912064)).limit(25);
4343
/// let _messages = channel_id.messages(&http, builder).await?;
@@ -106,7 +106,7 @@ impl GetMessages {
106106
pub async fn execute(
107107
self,
108108
cache_http: impl CacheHttp,
109-
channel_id: ChannelId,
109+
channel_id: GenericChannelId,
110110
) -> Result<Vec<Message>> {
111111
let http = cache_http.http();
112112
let search_filter = self.search_filter.map(Into::into);

0 commit comments

Comments
 (0)