Repository: serenity-rs/serenity (language: rust)

Issue:
`(Partial)Guild(Id)::audit_logs` takes in raw action type IDs instead of the `Action` enum
Currently, [`serenity::model::Guild::audit_logs`](https://docs.rs/serenity/0.11.6/serenity/model/guild/struct.Guild.html#method.audit_logs) (as well as the equivalent methods in `GuildId` and `PartialGuildId`) take an `Option<u8>` for the optional action type field. This is incredibly bad for multiple reasons, such as allowing the user to easily and mistakenly specify incorrect type IDs, and requiring a comment explaining the magic number in many cases.

Since Serenity already has an [`Action` enum](https://docs.rs/serenity/latest/serenity/model/prelude/enum.Action.html) that models this action type very clearly, we should definitely refactor the `audit_log` methods to use this enum in 0.12.x.


Discussion / hints:

Fix patch:
diff --git a/src/http/client.rs b/src/http/client.rs
index 43b0e9a46a6..50b30c6c86f 100644
--- a/src/http/client.rs
+++ b/src/http/client.rs
@@ -2576,14 +2576,14 @@ impl Http {
     pub async fn get_audit_logs(
         &self,
         guild_id: GuildId,
-        action_type: Option<u8>,
+        action_type: Option<audit_log::Action>,
         user_id: Option<UserId>,
-        before: Option<u64>,
+        before: Option<AuditLogEntryId>,
         limit: Option<u8>,
     ) -> Result<AuditLogs> {
         let mut params = vec![];
         if let Some(action_type) = action_type {
-            params.push(("action_type", action_type.to_string()));
+            params.push(("action_type", action_type.num().to_string()));
         }
         if let Some(before) = before {
             params.push(("before", before.to_string()));
diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs
index df1dd806f40..9ea1e9d4a4c 100644
--- a/src/model/guild/guild_id.rs
+++ b/src/model/guild/guild_id.rs
@@ -287,14 +287,12 @@ impl GuildId {
     pub async fn audit_logs(
         self,
         http: impl AsRef<Http>,
-        action_type: Option<u8>,
+        action_type: Option<audit_log::Action>,
         user_id: Option<UserId>,
         before: Option<AuditLogEntryId>,
         limit: Option<u8>,
     ) -> Result<AuditLogs> {
-        http.as_ref()
-            .get_audit_logs(self, action_type, user_id, before.map(AuditLogEntryId::get), limit)
-            .await
+        http.as_ref().get_audit_logs(self, action_type, user_id, before, limit).await
     }
 
     /// Gets all of the guild's channels over the REST API.
diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs
index 311e222a52a..033c585efb2 100644
--- a/src/model/guild/mod.rs
+++ b/src/model/guild/mod.rs
@@ -590,7 +590,7 @@ impl Guild {
     pub async fn audit_logs(
         &self,
         http: impl AsRef<Http>,
-        action_type: Option<u8>,
+        action_type: Option<audit_log::Action>,
         user_id: Option<UserId>,
         before: Option<AuditLogEntryId>,
         limit: Option<u8>,
diff --git a/src/model/guild/partial_guild.rs b/src/model/guild/partial_guild.rs
index dad1201a0b1..1d578bdc168 100644
--- a/src/model/guild/partial_guild.rs
+++ b/src/model/guild/partial_guild.rs
@@ -358,7 +358,7 @@ impl PartialGuild {
     pub async fn audit_logs(
         &self,
         http: impl AsRef<Http>,
-        action_type: Option<u8>,
+        action_type: Option<audit_log::Action>,
         user_id: Option<UserId>,
         before: Option<AuditLogEntryId>,
         limit: Option<u8>,


Test patch: