Skip to content

Commit 243c5b2

Browse files
authored
Split GuildThread from GuildChannel (#3026)
1 parent bd4d91d commit 243c5b2

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

+1243
-1067
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ to-arraystring = "0.2.0"
4949
extract_map = { version = "0.2.0", features = ["serde", "iter_mut"] }
5050
aformat = "0.1.3"
5151
bytes = "1.5.0"
52+
ref-cast = "1.0.23"
5253
# Optional dependencies
5354
foldhash = { version = "0.1.4", optional = true }
5455
chrono = { version = "0.4.31", default-features = false, features = ["clock", "serde"], optional = true }

examples/e12_parallel_loops/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use chrono::offset::Utc;
55
use serenity::async_trait;
66
use serenity::builder::{CreateEmbed, CreateMessage};
77
use serenity::gateway::ActivityData;
8-
use serenity::model::id::ChannelId;
8+
use serenity::model::id::GenericChannelId;
99
use serenity::prelude::*;
1010

1111
struct Handler {
@@ -93,7 +93,7 @@ async fn log_system_load(ctx: &Context) {
9393
false,
9494
);
9595
let builder = CreateMessage::new().embed(embed);
96-
let message = ChannelId::new(381926291785383946).send_message(&ctx.http, builder).await;
96+
let message = GenericChannelId::new(381926291785383946).send_message(&ctx.http, builder).await;
9797
if let Err(why) = message {
9898
eprintln!("Error sending message: {why:?}");
9999
};

examples/testing/src/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ async fn message(ctx: &Context, msg: &Message) -> Result<(), serenity::Error> {
8787
model_type_sizes::print_ranking();
8888
} else if msg.content == "auditlog" {
8989
// Test special characters in audit log reason
90-
msg.channel_id
90+
channel_id
91+
.expect_channel()
9192
.edit(
9293
&ctx.http,
9394
EditChannel::new().name("new-channel-name").audit_log_reason("hello\nworld\n🙂"),
@@ -155,6 +156,7 @@ async fn message(ctx: &Context, msg: &Message) -> Result<(), serenity::Error> {
155156
guild_id.ban(&ctx.http, user_id, 0, None).await?;
156157
} else if msg.content == "createtags" {
157158
channel_id
159+
.expect_channel()
158160
.edit(
159161
&ctx.http,
160162
EditChannel::new().available_tags(vec![
@@ -165,9 +167,10 @@ async fn message(ctx: &Context, msg: &Message) -> Result<(), serenity::Error> {
165167
.await?;
166168
} else if msg.content == "assigntags" {
167169
let forum_id = msg.guild_channel(&ctx).await?.parent_id.unwrap();
168-
let forum = forum_id.to_guild_channel(&ctx, msg.guild_id).await?;
170+
let forum = forum_id.widen().to_guild_channel(&ctx, msg.guild_id).await?;
169171
channel_id
170-
.edit_thread(
172+
.expect_thread()
173+
.edit(
171174
&ctx.http,
172175
EditThread::new()
173176
.applied_tags(forum.available_tags.iter().map(|t| t.id).collect::<Vec<_>>()),
@@ -199,7 +202,7 @@ async fn message(ctx: &Context, msg: &Message) -> Result<(), serenity::Error> {
199202
msg.author.id.dm(&ctx.http, builder).await?;
200203
} else if let Some(channel) = msg.content.strip_prefix("movetorootandback") {
201204
let mut channel = {
202-
let channel_id = channel.trim().parse::<ChannelId>().unwrap();
205+
let channel_id = channel.trim().parse::<GenericChannelId>().unwrap();
203206
channel_id.to_guild_channel(&ctx, msg.guild_id).await.unwrap()
204207
};
205208

examples/testing/src/model_type_sizes.rs

Lines changed: 5 additions & 2 deletions
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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ impl ParseAction {
2424
}
2525
}
2626

27-
/// A builder to manage the allowed mentions on a message, used by the [`ChannelId::send_message`]
28-
/// and [`ChannelId::edit_message`] methods.
27+
/// A builder to manage the allowed mentions on a message.
2928
///
3029
/// # Examples
3130
///

src/builder/create_components.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
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
}

0 commit comments

Comments
 (0)