Skip to content

Commit 2e12663

Browse files
authored
Perform some misc TODO cleanups (#3050)
1 parent 4a96fe1 commit 2e12663

File tree

10 files changed

+39
-54
lines changed

10 files changed

+39
-54
lines changed

examples/testing/src/model_type_sizes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn print_ranking() {
130130
("MessageUpdateEvent", std::mem::size_of::<MessageUpdateEvent>()),
131131
("ModalInteraction", std::mem::size_of::<ModalInteraction>()),
132132
("ModalInteractionData", std::mem::size_of::<ModalInteractionData>()),
133-
("Options", std::mem::size_of::<Options>()),
133+
("AuditLogEntryOptions", std::mem::size_of::<AuditLogEntryOptions>()),
134134
("PartialChannel", std::mem::size_of::<PartialChannel>()),
135135
("PartialCurrentApplicationInfo", std::mem::size_of::<PartialCurrentApplicationInfo>()),
136136
("PartialGuild", std::mem::size_of::<PartialGuild>()),
@@ -156,7 +156,7 @@ pub fn print_ranking() {
156156
("Role", std::mem::size_of::<Role>()),
157157
("RoleId", std::mem::size_of::<RoleId>()),
158158
("RoleTags", std::mem::size_of::<RoleTags>()),
159-
("Rule", std::mem::size_of::<Rule>()),
159+
("AutoModRule", std::mem::size_of::<AutoModRule>()),
160160
("RuleId", std::mem::size_of::<RuleId>()),
161161
("ScheduledEvent", std::mem::size_of::<ScheduledEvent>()),
162162
("ScheduledEventId", std::mem::size_of::<ScheduledEventId>()),

src/builder/edit_automod_rule.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ impl<'a> EditAutoModRule<'a> {
9595
self
9696
}
9797

98-
/// Creates or edits an AutoMod [`Rule`] in a guild. Providing a [`RuleId`] will edit that
99-
/// corresponding rule, otherwise a new rule will be created.
98+
/// Creates or edits an [`AutoModRule`] in a guild.
99+
///
100+
/// Providing a [`RuleId`] will edit that corresponding rule, otherwise a new rule will be
101+
/// created.
100102
///
101103
/// **Note**: Requires the [Manage Guild] permission.
102104
///
@@ -111,7 +113,7 @@ impl<'a> EditAutoModRule<'a> {
111113
http: &Http,
112114
guild_id: GuildId,
113115
rule_id: Option<RuleId>,
114-
) -> Result<Rule> {
116+
) -> Result<AutoModRule> {
115117
match rule_id {
116118
Some(id) => http.edit_automod_rule(guild_id, id, &self, self.audit_log_reason).await,
117119
// Automod Rule creation has required fields, whereas modifying a rule does not.

src/gateway/client/event_handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ event_handler! {
109109
/// Dispatched when an auto moderation rule was created.
110110
///
111111
/// Provides said rule's data.
112-
AutoModRuleCreate { rule: Rule } => async fn auto_moderation_rule_create(&self, ctx: Context);
112+
AutoModRuleCreate { rule: AutoModRule } => async fn auto_moderation_rule_create(&self, ctx: Context);
113113

114114
/// Dispatched when an auto moderation rule was updated.
115115
///
116116
/// Provides said rule's data.
117-
AutoModRuleUpdate { rule: Rule } => async fn auto_moderation_rule_update(&self, ctx: Context);
117+
AutoModRuleUpdate { rule: AutoModRule } => async fn auto_moderation_rule_update(&self, ctx: Context);
118118

119119
/// Dispatched when an auto moderation rule was deleted.
120120
///
121121
/// Provides said rule's data.
122-
AutoModRuleDelete { rule: Rule } => async fn auto_moderation_rule_delete(&self, ctx: Context);
122+
AutoModRuleDelete { rule: AutoModRule } => async fn auto_moderation_rule_delete(&self, ctx: Context);
123123

124124
/// Dispatched when an auto moderation rule was triggered and an action was executed.
125125
///

src/http/client.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,7 @@ impl Http {
25002500
}
25012501

25022502
/// Retrieves all auto moderation rules in a guild.
2503-
pub async fn get_automod_rules(&self, guild_id: GuildId) -> Result<Vec<Rule>> {
2503+
pub async fn get_automod_rules(&self, guild_id: GuildId) -> Result<Vec<AutoModRule>> {
25042504
self.fire(Request {
25052505
body: None,
25062506
multipart: None,
@@ -2515,7 +2515,11 @@ impl Http {
25152515
}
25162516

25172517
/// Retrieves an auto moderation rule in a guild.
2518-
pub async fn get_automod_rule(&self, guild_id: GuildId, rule_id: RuleId) -> Result<Rule> {
2518+
pub async fn get_automod_rule(
2519+
&self,
2520+
guild_id: GuildId,
2521+
rule_id: RuleId,
2522+
) -> Result<AutoModRule> {
25192523
self.fire(Request {
25202524
body: None,
25212525
multipart: None,
@@ -2536,7 +2540,7 @@ impl Http {
25362540
guild_id: GuildId,
25372541
map: &impl serde::Serialize,
25382542
audit_log_reason: Option<&str>,
2539-
) -> Result<Rule> {
2543+
) -> Result<AutoModRule> {
25402544
let body = to_vec(map)?;
25412545

25422546
self.fire(Request {
@@ -2559,7 +2563,7 @@ impl Http {
25592563
rule_id: RuleId,
25602564
map: &impl serde::Serialize,
25612565
audit_log_reason: Option<&str>,
2562-
) -> Result<Rule> {
2566+
) -> Result<AutoModRule> {
25632567
let body = to_vec(map)?;
25642568

25652569
self.fire(Request {
@@ -3309,8 +3313,6 @@ impl Http {
33093313
}
33103314

33113315
/// Gets a guild widget information.
3312-
// TODO: according to Discord, this returns different data; namely https://discord.com/developers/docs/resources/guild#guild-widget-object-guild-widget-structure.
3313-
// Should investigate if this endpoint actually works
33143316
pub async fn get_guild_widget(&self, guild_id: GuildId) -> Result<GuildWidget> {
33153317
self.fire(Request {
33163318
body: None,

src/model/channel/message.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,6 @@ pub struct Message {
130130
/// The Id of the [`Guild`] that the message was sent in. This value will only be present if
131131
/// this message was received over the gateway, therefore **do not use this to check if message
132132
/// is in DMs**, it is not a reliable method.
133-
// TODO: maybe introduce an `enum MessageLocation { Dm, Guild(GuildId) }` and store
134-
// `Option<MessageLocation` here. Instead of None being ambiguous (is it in DMs? Or do we just
135-
// not know because HTTP retrieved Messages don't have guild ID?), we'd set
136-
// Some(MessageLocation::Dm) in gateway and None in HTTP.
137133
pub guild_id: Option<GuildId>,
138134
/// A partial amount of data about the user's member data
139135
///
@@ -874,19 +870,6 @@ impl From<&Message> for MessageReference {
874870
}
875871
}
876872

877-
impl From<(ChannelId, MessageId)> for MessageReference {
878-
// TODO(next): Remove this
879-
fn from(pair: (ChannelId, MessageId)) -> Self {
880-
Self {
881-
kind: MessageReferenceKind::default(),
882-
message_id: Some(pair.1),
883-
channel_id: pair.0,
884-
guild_id: None,
885-
fail_if_not_exists: None,
886-
}
887-
}
888-
}
889-
890873
/// [Discord docs](https://discord.com/developers/docs/resources/channel#channel-mention-object).
891874
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
892875
#[derive(Clone, Debug, Deserialize, Serialize)]

src/model/event.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct CommandPermissionsUpdateEvent {
3737
#[serde(transparent)]
3838
#[non_exhaustive]
3939
pub struct AutoModRuleCreateEvent {
40-
pub rule: Rule,
40+
pub rule: AutoModRule,
4141
}
4242

4343
/// Requires [`GatewayIntents::AUTO_MODERATION_CONFIGURATION`].
@@ -48,7 +48,7 @@ pub struct AutoModRuleCreateEvent {
4848
#[serde(transparent)]
4949
#[non_exhaustive]
5050
pub struct AutoModRuleUpdateEvent {
51-
pub rule: Rule,
51+
pub rule: AutoModRule,
5252
}
5353

5454
/// Requires [`GatewayIntents::AUTO_MODERATION_CONFIGURATION`].
@@ -59,7 +59,7 @@ pub struct AutoModRuleUpdateEvent {
5959
#[serde(transparent)]
6060
#[non_exhaustive]
6161
pub struct AutoModRuleDeleteEvent {
62-
pub rule: Rule,
62+
pub rule: AutoModRule,
6363
}
6464

6565
/// Requires [`GatewayIntents::AUTO_MODERATION_EXECUTION`].
@@ -1138,31 +1138,31 @@ pub enum Event {
11381138
/// [`EventHandler::command_permissions_update`]: crate::gateway::client::EventHandler::command_permissions_update
11391139
#[serde(rename = "APPLICATION_COMMAND_PERMISSIONS_UPDATE")]
11401140
CommandPermissionsUpdate(CommandPermissionsUpdateEvent),
1141-
/// A [`Rule`] was created.
1141+
/// A [`AutoModRule`] was created.
11421142
///
11431143
/// Fires the [`EventHandler::auto_moderation_rule_create`] event.
11441144
///
11451145
/// [`EventHandler::auto_moderation_rule_create`]:
11461146
/// crate::gateway::client::EventHandler::auto_moderation_rule_create
11471147
#[serde(rename = "AUTO_MODERATION_RULE_CREATE")]
11481148
AutoModRuleCreate(AutoModRuleCreateEvent),
1149-
/// A [`Rule`] has been updated.
1149+
/// A [`AutoModRule`] has been updated.
11501150
///
11511151
/// Fires the [`EventHandler::auto_moderation_rule_update`] event.
11521152
///
11531153
/// [`EventHandler::auto_moderation_rule_update`]:
11541154
/// crate::gateway::client::EventHandler::auto_moderation_rule_update
11551155
#[serde(rename = "AUTO_MODERATION_RULE_UPDATE")]
11561156
AutoModRuleUpdate(AutoModRuleUpdateEvent),
1157-
/// A [`Rule`] was deleted.
1157+
/// A [`AutoModRule`] was deleted.
11581158
///
11591159
/// Fires the [`EventHandler::auto_moderation_rule_delete`] event.
11601160
///
11611161
/// [`EventHandler::auto_moderation_rule_delete`]:
11621162
/// crate::gateway::client::EventHandler::auto_moderation_rule_delete
11631163
#[serde(rename = "AUTO_MODERATION_RULE_DELETE")]
11641164
AutoModRuleDelete(AutoModRuleDeleteEvent),
1165-
/// A [`Rule`] was triggered and an action was executed.
1165+
/// A [`AutoModRule`] was triggered and an action was executed.
11661166
///
11671167
/// Fires the [`EventHandler::auto_moderation_action_execution`] event.
11681168
///

src/model/guild/audit_log/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ pub struct AuditLogs {
335335
#[serde(rename = "audit_log_entries")]
336336
pub entries: FixedArray<AuditLogEntry>,
337337
/// List of auto moderation rules referenced in the audit log.
338-
pub auto_moderation_rules: FixedArray<Rule>,
338+
pub auto_moderation_rules: FixedArray<AutoModRule>,
339339
/// List of application commands referenced in the audit log.
340340
pub application_commands: FixedArray<Command>,
341341
/// List of guild scheduled events referenced in the audit log.
@@ -388,15 +388,14 @@ pub struct AuditLogEntry {
388388
/// The id of this entry.
389389
pub id: AuditLogEntryId,
390390
/// Some optional data associated with this entry.
391-
pub options: Option<Options>,
391+
pub options: Option<AuditLogEntryOptions>,
392392
}
393393

394394
/// [Discord docs](https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info).
395-
// TODO: should be renamed to a less ambiguous name
396395
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
397396
#[derive(Debug, Deserialize, Serialize, Clone)]
398397
#[non_exhaustive]
399-
pub struct Options {
398+
pub struct AuditLogEntryOptions {
400399
/// Name of the Auto Moderation rule that was triggered.
401400
pub auto_moderation_rule_name: Option<FixedString>,
402401
/// Trigger type of the Auto Moderation rule that was triggered.

src/model/guild/automod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ use crate::model::prelude::*;
1313
/// Configured auto moderation rule.
1414
///
1515
/// [Discord docs](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object).
16-
// TODO: should be renamed to a less ambiguous name
1716
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
1817
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
1918
#[non_exhaustive]
20-
pub struct Rule {
19+
pub struct AutoModRule {
2120
/// ID of the rule.
2221
pub id: RuleId,
2322
/// ID of the guild this rule belongs to.

src/model/guild/guild_id.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::model::prelude::*;
3737

3838
#[cfg(feature = "model")]
3939
impl GuildId {
40-
/// Gets all auto moderation [`Rule`]s of this guild via HTTP.
40+
/// Gets all [`AutoModRule`]s of this guild via HTTP.
4141
///
4242
/// **Note**: Requires the [Manage Guild] permission.
4343
///
@@ -46,11 +46,11 @@ impl GuildId {
4646
/// Returns an [`Error::Http`] if the guild is unavailable.
4747
///
4848
/// [Manage Guild]: Permissions::MANAGE_GUILD
49-
pub async fn automod_rules(self, http: &Http) -> Result<Vec<Rule>> {
49+
pub async fn automod_rules(self, http: &Http) -> Result<Vec<AutoModRule>> {
5050
http.get_automod_rules(self).await
5151
}
5252

53-
/// Gets an auto moderation [`Rule`] of this guild by its ID via HTTP.
53+
/// Gets an [`AutoModRule`] of this guild by its ID via HTTP.
5454
///
5555
/// **Note**: Requires the [Manage Guild] permission.
5656
///
@@ -59,11 +59,11 @@ impl GuildId {
5959
/// Returns an [`Error::Http`] if a rule with the given ID does not exist.
6060
///
6161
/// [Manage Guild]: Permissions::MANAGE_GUILD
62-
pub async fn automod_rule(self, http: &Http, rule_id: RuleId) -> Result<Rule> {
62+
pub async fn automod_rule(self, http: &Http, rule_id: RuleId) -> Result<AutoModRule> {
6363
http.get_automod_rule(self, rule_id).await
6464
}
6565

66-
/// Creates an auto moderation [`Rule`] in the guild.
66+
/// Creates an [`AutoModRule`] in the guild.
6767
///
6868
/// **Note**: Requires the [Manage Guild] permission.
6969
///
@@ -107,11 +107,11 @@ impl GuildId {
107107
self,
108108
http: &Http,
109109
builder: EditAutoModRule<'_>,
110-
) -> Result<Rule> {
110+
) -> Result<AutoModRule> {
111111
builder.execute(http, self, None).await
112112
}
113113

114-
/// Edit an auto moderation [`Rule`], given its Id.
114+
/// Edit an [`AutoModRule`], given its Id.
115115
///
116116
/// **Note**: Requires the [Manage Guild] permission.
117117
///
@@ -125,11 +125,11 @@ impl GuildId {
125125
http: &Http,
126126
rule_id: RuleId,
127127
builder: EditAutoModRule<'_>,
128-
) -> Result<Rule> {
128+
) -> Result<AutoModRule> {
129129
builder.execute(http, self, Some(rule_id)).await
130130
}
131131

132-
/// Deletes an auto moderation [`Rule`] from the guild.
132+
/// Deletes an [`AutoModRule`] from the guild.
133133
///
134134
/// **Note**: Requires the [Manage Guild] permission.
135135
///

src/model/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ pub mod prelude {
7070
Action,
7171
ActionExecution,
7272
ActionType,
73+
AutoModRule,
7374
KeywordPresetType,
74-
Rule,
7575
Trigger,
7676
TriggerMetadata,
7777
TriggerType,

0 commit comments

Comments
 (0)