Browse Source

Remove TODOs, add WebhookType enum for future use

WebhookType is a future-use type, as currently audit logs are the only
thing which may return it.
pull/1055/head
FiniteReality 7 years ago
parent
commit
59d2489ba1
4 changed files with 27 additions and 10 deletions
  1. +14
    -0
      src/Discord.Net.Core/Entities/Webhooks/WebhookType.cs
  2. +3
    -4
      src/Discord.Net.Rest/API/Common/AuditLogOptions.cs
  3. +5
    -3
      src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/WebhookCreateAuditLogData.cs
  4. +5
    -3
      src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/WebhookDeleteAuditLogData.cs

+ 14
- 0
src/Discord.Net.Core/Entities/Webhooks/WebhookType.cs View File

@@ -0,0 +1,14 @@
namespace Discord
{
/// <summary>
/// Represents the type of a webhook.
/// </summary>
/// <remarks>
/// This type is currently unused, and is only returned in audit log responses.
/// </remarks>
public enum WebhookType
{
/// <summary> An incoming webhook </summary>
Incoming = 1
}
}

+ 3
- 4
src/Discord.Net.Rest/API/Common/AuditLogOptions.cs View File

@@ -2,20 +2,19 @@


namespace Discord.API namespace Discord.API
{ {
//TODO: Complete this with all possible values for options
internal class AuditLogOptions internal class AuditLogOptions
{ {
//Message delete //Message delete
[JsonProperty("count")] [JsonProperty("count")]
public int? MessageDeleteCount { get; set; } //TODO: what type of int? (returned as string)
public int? MessageDeleteCount { get; set; }
[JsonProperty("channel_id")] [JsonProperty("channel_id")]
public ulong? MessageDeleteChannelId { get; set; } public ulong? MessageDeleteChannelId { get; set; }


//Prune //Prune
[JsonProperty("delete_member_days")] [JsonProperty("delete_member_days")]
public int? PruneDeleteMemberDays { get; set; } //TODO: what type of int? (returned as string)
public int? PruneDeleteMemberDays { get; set; }
[JsonProperty("members_removed")] [JsonProperty("members_removed")]
public int? PruneMembersRemoved { get; set; } //TODO: what type of int? (returned as string)
public int? PruneMembersRemoved { get; set; }


//Overwrite Update //Overwrite Update
[JsonProperty("role_name")] [JsonProperty("role_name")]


+ 5
- 3
src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/WebhookCreateAuditLogData.cs View File

@@ -7,10 +7,11 @@ namespace Discord.Rest
{ {
public class WebhookCreateAuditLogData : IAuditLogData public class WebhookCreateAuditLogData : IAuditLogData
{ {
private WebhookCreateAuditLogData(IWebhook webhook, string name, ulong channelId)
private WebhookCreateAuditLogData(IWebhook webhook, WebhookType type, string name, ulong channelId)
{ {
Webhook = webhook; Webhook = webhook;
Name = name; Name = name;
Type = type;
ChannelId = channelId; ChannelId = channelId;
} }


@@ -23,19 +24,20 @@ namespace Discord.Rest
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name"); var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name");


var channelId = channelIdModel.NewValue.ToObject<ulong>(); var channelId = channelIdModel.NewValue.ToObject<ulong>();
var type = typeModel.NewValue.ToObject<int>(); //TODO: what on *earth* is this for
var type = typeModel.NewValue.ToObject<WebhookType>();
var name = nameModel.NewValue.ToObject<string>(); var name = nameModel.NewValue.ToObject<string>();


var webhookInfo = log.Webhooks?.FirstOrDefault(x => x.Id == entry.TargetId); var webhookInfo = log.Webhooks?.FirstOrDefault(x => x.Id == entry.TargetId);
var webhook = RestWebhook.Create(discord, (IGuild)null, webhookInfo); var webhook = RestWebhook.Create(discord, (IGuild)null, webhookInfo);


return new WebhookCreateAuditLogData(webhook, name, channelId);
return new WebhookCreateAuditLogData(webhook, type, name, channelId);
} }


//Corresponds to the *current* data //Corresponds to the *current* data
public IWebhook Webhook { get; } public IWebhook Webhook { get; }


//Corresponds to the *audit log* data //Corresponds to the *audit log* data
public WebhookType Type { get; }
public string Name { get; } public string Name { get; }
public ulong ChannelId { get; } public ulong ChannelId { get; }
} }


+ 5
- 3
src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/WebhookDeleteAuditLogData.cs View File

@@ -11,11 +11,12 @@ namespace Discord.Rest
{ {
public class WebhookDeleteAuditLogData : IAuditLogData public class WebhookDeleteAuditLogData : IAuditLogData
{ {
private WebhookDeleteAuditLogData(ulong id, ulong channel, string name, string avatar)
private WebhookDeleteAuditLogData(ulong id, ulong channel, WebhookType type, string name, string avatar)
{ {
WebhookId = id; WebhookId = id;
ChannelId = channel; ChannelId = channel;
Name = name; Name = name;
Type = type;
Avatar = avatar; Avatar = avatar;
} }


@@ -29,15 +30,16 @@ namespace Discord.Rest
var avatarHashModel = changes.FirstOrDefault(x => x.ChangedProperty == "avatar_hash"); var avatarHashModel = changes.FirstOrDefault(x => x.ChangedProperty == "avatar_hash");


var channelId = channelIdModel.OldValue.ToObject<ulong>(); var channelId = channelIdModel.OldValue.ToObject<ulong>();
var type = typeModel.OldValue.ToObject<int>(); //TODO: what on *earth* is this for
var type = typeModel.OldValue.ToObject<WebhookType>();
var name = nameModel.OldValue.ToObject<string>(); var name = nameModel.OldValue.ToObject<string>();
var avatarHash = avatarHashModel?.OldValue?.ToObject<string>(); var avatarHash = avatarHashModel?.OldValue?.ToObject<string>();


return new WebhookDeleteAuditLogData(entry.TargetId.Value, channelId, name, avatarHash);
return new WebhookDeleteAuditLogData(entry.TargetId.Value, channelId, type, name, avatarHash);
} }


public ulong WebhookId { get; } public ulong WebhookId { get; }
public ulong ChannelId { get; } public ulong ChannelId { get; }
public WebhookType Type { get; }
public string Name { get; } public string Name { get; }
public string Avatar { get; } public string Avatar { get; }
} }


Loading…
Cancel
Save