Skip to content

Commit

Permalink
Perform some misc TODO cleanups (#3050)
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev authored Nov 18, 2024
1 parent 4a96fe1 commit 2e12663
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 54 deletions.
4 changes: 2 additions & 2 deletions examples/testing/src/model_type_sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn print_ranking() {
("MessageUpdateEvent", std::mem::size_of::<MessageUpdateEvent>()),
("ModalInteraction", std::mem::size_of::<ModalInteraction>()),
("ModalInteractionData", std::mem::size_of::<ModalInteractionData>()),
("Options", std::mem::size_of::<Options>()),
("AuditLogEntryOptions", std::mem::size_of::<AuditLogEntryOptions>()),
("PartialChannel", std::mem::size_of::<PartialChannel>()),
("PartialCurrentApplicationInfo", std::mem::size_of::<PartialCurrentApplicationInfo>()),
("PartialGuild", std::mem::size_of::<PartialGuild>()),
Expand All @@ -156,7 +156,7 @@ pub fn print_ranking() {
("Role", std::mem::size_of::<Role>()),
("RoleId", std::mem::size_of::<RoleId>()),
("RoleTags", std::mem::size_of::<RoleTags>()),
("Rule", std::mem::size_of::<Rule>()),
("AutoModRule", std::mem::size_of::<AutoModRule>()),
("RuleId", std::mem::size_of::<RuleId>()),
("ScheduledEvent", std::mem::size_of::<ScheduledEvent>()),
("ScheduledEventId", std::mem::size_of::<ScheduledEventId>()),
Expand Down
8 changes: 5 additions & 3 deletions src/builder/edit_automod_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ impl<'a> EditAutoModRule<'a> {
self
}

/// Creates or edits an AutoMod [`Rule`] in a guild. Providing a [`RuleId`] will edit that
/// corresponding rule, otherwise a new rule will be created.
/// Creates or edits an [`AutoModRule`] in a guild.
///
/// Providing a [`RuleId`] will edit that corresponding rule, otherwise a new rule will be
/// created.
///
/// **Note**: Requires the [Manage Guild] permission.
///
Expand All @@ -111,7 +113,7 @@ impl<'a> EditAutoModRule<'a> {
http: &Http,
guild_id: GuildId,
rule_id: Option<RuleId>,
) -> Result<Rule> {
) -> Result<AutoModRule> {
match rule_id {
Some(id) => http.edit_automod_rule(guild_id, id, &self, self.audit_log_reason).await,
// Automod Rule creation has required fields, whereas modifying a rule does not.
Expand Down
6 changes: 3 additions & 3 deletions src/gateway/client/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ event_handler! {
/// Dispatched when an auto moderation rule was created.
///
/// Provides said rule's data.
AutoModRuleCreate { rule: Rule } => async fn auto_moderation_rule_create(&self, ctx: Context);
AutoModRuleCreate { rule: AutoModRule } => async fn auto_moderation_rule_create(&self, ctx: Context);

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

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

/// Dispatched when an auto moderation rule was triggered and an action was executed.
///
Expand Down
14 changes: 8 additions & 6 deletions src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2500,7 +2500,7 @@ impl Http {
}

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

/// Retrieves an auto moderation rule in a guild.
pub async fn get_automod_rule(&self, guild_id: GuildId, rule_id: RuleId) -> Result<Rule> {
pub async fn get_automod_rule(
&self,
guild_id: GuildId,
rule_id: RuleId,
) -> Result<AutoModRule> {
self.fire(Request {
body: None,
multipart: None,
Expand All @@ -2536,7 +2540,7 @@ impl Http {
guild_id: GuildId,
map: &impl serde::Serialize,
audit_log_reason: Option<&str>,
) -> Result<Rule> {
) -> Result<AutoModRule> {
let body = to_vec(map)?;

self.fire(Request {
Expand All @@ -2559,7 +2563,7 @@ impl Http {
rule_id: RuleId,
map: &impl serde::Serialize,
audit_log_reason: Option<&str>,
) -> Result<Rule> {
) -> Result<AutoModRule> {
let body = to_vec(map)?;

self.fire(Request {
Expand Down Expand Up @@ -3309,8 +3313,6 @@ impl Http {
}

/// Gets a guild widget information.
// TODO: according to Discord, this returns different data; namely https://discord.com/developers/docs/resources/guild#guild-widget-object-guild-widget-structure.
// Should investigate if this endpoint actually works
pub async fn get_guild_widget(&self, guild_id: GuildId) -> Result<GuildWidget> {
self.fire(Request {
body: None,
Expand Down
17 changes: 0 additions & 17 deletions src/model/channel/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ pub struct Message {
/// The Id of the [`Guild`] that the message was sent in. This value will only be present if
/// this message was received over the gateway, therefore **do not use this to check if message
/// is in DMs**, it is not a reliable method.
// TODO: maybe introduce an `enum MessageLocation { Dm, Guild(GuildId) }` and store
// `Option<MessageLocation` here. Instead of None being ambiguous (is it in DMs? Or do we just
// not know because HTTP retrieved Messages don't have guild ID?), we'd set
// Some(MessageLocation::Dm) in gateway and None in HTTP.
pub guild_id: Option<GuildId>,
/// A partial amount of data about the user's member data
///
Expand Down Expand Up @@ -874,19 +870,6 @@ impl From<&Message> for MessageReference {
}
}

impl From<(ChannelId, MessageId)> for MessageReference {
// TODO(next): Remove this
fn from(pair: (ChannelId, MessageId)) -> Self {
Self {
kind: MessageReferenceKind::default(),
message_id: Some(pair.1),
channel_id: pair.0,
guild_id: None,
fail_if_not_exists: None,
}
}
}

/// [Discord docs](https://discord.com/developers/docs/resources/channel#channel-mention-object).
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
14 changes: 7 additions & 7 deletions src/model/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct CommandPermissionsUpdateEvent {
#[serde(transparent)]
#[non_exhaustive]
pub struct AutoModRuleCreateEvent {
pub rule: Rule,
pub rule: AutoModRule,
}

/// Requires [`GatewayIntents::AUTO_MODERATION_CONFIGURATION`].
Expand All @@ -48,7 +48,7 @@ pub struct AutoModRuleCreateEvent {
#[serde(transparent)]
#[non_exhaustive]
pub struct AutoModRuleUpdateEvent {
pub rule: Rule,
pub rule: AutoModRule,
}

/// Requires [`GatewayIntents::AUTO_MODERATION_CONFIGURATION`].
Expand All @@ -59,7 +59,7 @@ pub struct AutoModRuleUpdateEvent {
#[serde(transparent)]
#[non_exhaustive]
pub struct AutoModRuleDeleteEvent {
pub rule: Rule,
pub rule: AutoModRule,
}

/// Requires [`GatewayIntents::AUTO_MODERATION_EXECUTION`].
Expand Down Expand Up @@ -1138,31 +1138,31 @@ pub enum Event {
/// [`EventHandler::command_permissions_update`]: crate::gateway::client::EventHandler::command_permissions_update
#[serde(rename = "APPLICATION_COMMAND_PERMISSIONS_UPDATE")]
CommandPermissionsUpdate(CommandPermissionsUpdateEvent),
/// A [`Rule`] was created.
/// A [`AutoModRule`] was created.
///
/// Fires the [`EventHandler::auto_moderation_rule_create`] event.
///
/// [`EventHandler::auto_moderation_rule_create`]:
/// crate::gateway::client::EventHandler::auto_moderation_rule_create
#[serde(rename = "AUTO_MODERATION_RULE_CREATE")]
AutoModRuleCreate(AutoModRuleCreateEvent),
/// A [`Rule`] has been updated.
/// A [`AutoModRule`] has been updated.
///
/// Fires the [`EventHandler::auto_moderation_rule_update`] event.
///
/// [`EventHandler::auto_moderation_rule_update`]:
/// crate::gateway::client::EventHandler::auto_moderation_rule_update
#[serde(rename = "AUTO_MODERATION_RULE_UPDATE")]
AutoModRuleUpdate(AutoModRuleUpdateEvent),
/// A [`Rule`] was deleted.
/// A [`AutoModRule`] was deleted.
///
/// Fires the [`EventHandler::auto_moderation_rule_delete`] event.
///
/// [`EventHandler::auto_moderation_rule_delete`]:
/// crate::gateway::client::EventHandler::auto_moderation_rule_delete
#[serde(rename = "AUTO_MODERATION_RULE_DELETE")]
AutoModRuleDelete(AutoModRuleDeleteEvent),
/// A [`Rule`] was triggered and an action was executed.
/// A [`AutoModRule`] was triggered and an action was executed.
///
/// Fires the [`EventHandler::auto_moderation_action_execution`] event.
///
Expand Down
7 changes: 3 additions & 4 deletions src/model/guild/audit_log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub struct AuditLogs {
#[serde(rename = "audit_log_entries")]
pub entries: FixedArray<AuditLogEntry>,
/// List of auto moderation rules referenced in the audit log.
pub auto_moderation_rules: FixedArray<Rule>,
pub auto_moderation_rules: FixedArray<AutoModRule>,
/// List of application commands referenced in the audit log.
pub application_commands: FixedArray<Command>,
/// List of guild scheduled events referenced in the audit log.
Expand Down Expand Up @@ -388,15 +388,14 @@ pub struct AuditLogEntry {
/// The id of this entry.
pub id: AuditLogEntryId,
/// Some optional data associated with this entry.
pub options: Option<Options>,
pub options: Option<AuditLogEntryOptions>,
}

/// [Discord docs](https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info).
// TODO: should be renamed to a less ambiguous name
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Debug, Deserialize, Serialize, Clone)]
#[non_exhaustive]
pub struct Options {
pub struct AuditLogEntryOptions {
/// Name of the Auto Moderation rule that was triggered.
pub auto_moderation_rule_name: Option<FixedString>,
/// Trigger type of the Auto Moderation rule that was triggered.
Expand Down
3 changes: 1 addition & 2 deletions src/model/guild/automod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ use crate::model::prelude::*;
/// Configured auto moderation rule.
///
/// [Discord docs](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object).
// TODO: should be renamed to a less ambiguous name
#[cfg_attr(feature = "typesize", derive(typesize::derive::TypeSize))]
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[non_exhaustive]
pub struct Rule {
pub struct AutoModRule {
/// ID of the rule.
pub id: RuleId,
/// ID of the guild this rule belongs to.
Expand Down
18 changes: 9 additions & 9 deletions src/model/guild/guild_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use crate::model::prelude::*;

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

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

/// Creates an auto moderation [`Rule`] in the guild.
/// Creates an [`AutoModRule`] in the guild.
///
/// **Note**: Requires the [Manage Guild] permission.
///
Expand Down Expand Up @@ -107,11 +107,11 @@ impl GuildId {
self,
http: &Http,
builder: EditAutoModRule<'_>,
) -> Result<Rule> {
) -> Result<AutoModRule> {
builder.execute(http, self, None).await
}

/// Edit an auto moderation [`Rule`], given its Id.
/// Edit an [`AutoModRule`], given its Id.
///
/// **Note**: Requires the [Manage Guild] permission.
///
Expand All @@ -125,11 +125,11 @@ impl GuildId {
http: &Http,
rule_id: RuleId,
builder: EditAutoModRule<'_>,
) -> Result<Rule> {
) -> Result<AutoModRule> {
builder.execute(http, self, Some(rule_id)).await
}

/// Deletes an auto moderation [`Rule`] from the guild.
/// Deletes an [`AutoModRule`] from the guild.
///
/// **Note**: Requires the [Manage Guild] permission.
///
Expand Down
2 changes: 1 addition & 1 deletion src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub mod prelude {
Action,
ActionExecution,
ActionType,
AutoModRule,
KeywordPresetType,
Rule,
Trigger,
TriggerMetadata,
TriggerType,
Expand Down

0 comments on commit 2e12663

Please sign in to comment.