Browse Source

Stage instance audit logs as well as thread audit log type

pull/1923/head
quin lynch 3 years ago
parent
commit
a20b2b6ee7
8 changed files with 223 additions and 3 deletions
  1. +12
    -0
      src/Discord.Net.Core/Entities/AuditLogs/ActionType.cs
  2. +7
    -1
      src/Discord.Net.Rest/API/Common/AuditLog.cs
  3. +1
    -1
      src/Discord.Net.Rest/API/Common/AuditLogEntry.cs
  4. +2
    -1
      src/Discord.Net.Rest/Entities/AuditLogs/AuditLogHelper.cs
  5. +36
    -0
      src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInfo.cs
  6. +55
    -0
      src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceCreateAuditLogData.cs
  7. +55
    -0
      src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceDeleteAuditLogData.cs
  8. +55
    -0
      src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceUpdatedAuditLogData.cs

+ 12
- 0
src/Discord.Net.Core/Entities/AuditLogs/ActionType.cs View File

@@ -180,5 +180,17 @@ namespace Discord
/// A sticker was deleted. /// A sticker was deleted.
/// </summary> /// </summary>
StickerDeleted = 92, StickerDeleted = 92,
/// <summary>
/// A thread was created.
/// </summary>
ThreadCreate = 110,
/// <summary>
/// A thread was updated.
/// </summary>
ThreadUpdate = 111,
/// <summary>
/// A thread was deleted.
/// </summary>
ThreadDelete = 112
} }
} }

+ 7
- 1
src/Discord.Net.Rest/API/Common/AuditLog.cs View File

@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;


namespace Discord.API namespace Discord.API
{ {
@@ -7,6 +7,12 @@ namespace Discord.API
[JsonProperty("webhooks")] [JsonProperty("webhooks")]
public Webhook[] Webhooks { get; set; } public Webhook[] Webhooks { get; set; }


[JsonProperty("threads")]
public Channel[] Threads { get; set; }

[JsonProperty("integrations")]
public Integration[] Integrations { get; set; }

[JsonProperty("users")] [JsonProperty("users")]
public User[] Users { get; set; } public User[] Users { get; set; }




+ 1
- 1
src/Discord.Net.Rest/API/Common/AuditLogEntry.cs View File

@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;


namespace Discord.API namespace Discord.API
{ {


+ 2
- 1
src/Discord.Net.Rest/Entities/AuditLogs/AuditLogHelper.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;


using Model = Discord.API.AuditLog; using Model = Discord.API.AuditLog;
@@ -51,6 +51,7 @@ namespace Discord.Rest
[ActionType.MessageBulkDeleted] = MessageBulkDeleteAuditLogData.Create, [ActionType.MessageBulkDeleted] = MessageBulkDeleteAuditLogData.Create,
[ActionType.MessagePinned] = MessagePinAuditLogData.Create, [ActionType.MessagePinned] = MessagePinAuditLogData.Create,
[ActionType.MessageUnpinned] = MessageUnpinAuditLogData.Create, [ActionType.MessageUnpinned] = MessageUnpinAuditLogData.Create,

}; };


public static IAuditLogData CreateData(BaseDiscordClient discord, Model log, EntryModel entry) public static IAuditLogData CreateData(BaseDiscordClient discord, Model log, EntryModel entry)


+ 36
- 0
src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInfo.cs View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discord.Rest
{
/// <summary>
/// Represents information for a stage.
/// </summary>
public class StageInfo
{
/// <summary>
/// Gets the topic of the stage channel.
/// </summary>
public string Topic { get; }

/// <summary>
/// Gets the privacy level of the stage channel.
/// </summary>
public StagePrivacyLevel? PrivacyLevel { get; }

/// <summary>
/// Gets the user who started the stage channel.
/// </summary>
public IUser User { get; }

internal StageInfo(IUser user, StagePrivacyLevel? level, string topic)
{
this.Topic = topic;
this.PrivacyLevel = level;
this.User = user;
}
}
}

+ 55
- 0
src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceCreateAuditLogData.cs View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Model = Discord.API.AuditLog;
using EntryModel = Discord.API.AuditLogEntry;

namespace Discord.Rest
{
/// <summary>
/// Contains a piece of audit log data related to a stage going live.
/// </summary>
public class StageInstanceCreateAuditLogData : IAuditLogData
{
/// <summary>
/// Gets the topic of the stage channel.
/// </summary>
public string Topic { get; }

/// <summary>
/// Gets the privacy level of the stage channel.
/// </summary>
public StagePrivacyLevel PrivacyLevel { get; }

/// <summary>
/// Gets the user who started the stage channel.
/// </summary>
public IUser User { get; }

/// <summary>
/// Gets the Id of the stage channel.
/// </summary>
public ulong StageChannelId { get; }

internal StageInstanceCreateAuditLogData(string topic, StagePrivacyLevel privacyLevel, IUser user, ulong channelId)
{
Topic = topic;
PrivacyLevel = privacyLevel;
User = user;
StageChannelId = channelId;
}

internal static StageInstanceCreateAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
{
var topic = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "topic").NewValue.ToObject<string>(discord.ApiClient.Serializer);
var privacyLevel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "privacy_level").NewValue.ToObject<StagePrivacyLevel>(discord.ApiClient.Serializer);
var user = log.Users.FirstOrDefault(x => x.Id == entry.UserId);
var channelId = entry.Options.ChannelId;

return new StageInstanceCreateAuditLogData(topic, privacyLevel, RestUser.Create(discord, user), channelId ?? 0);
}
}
}

+ 55
- 0
src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceDeleteAuditLogData.cs View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Model = Discord.API.AuditLog;
using EntryModel = Discord.API.AuditLogEntry;

namespace Discord.Rest
{
/// <summary>
/// Contains a piece of audit log data related to a stage instance deleted.
/// </summary>
public class StageInstanceDeleteAuditLogData
{
/// <summary>
/// Gets the topic of the stage channel.
/// </summary>
public string Topic { get; }

/// <summary>
/// Gets the privacy level of the stage channel.
/// </summary>
public StagePrivacyLevel PrivacyLevel { get; }

/// <summary>
/// Gets the user who started the stage channel.
/// </summary>
public IUser User { get; }

/// <summary>
/// Gets the Id of the stage channel.
/// </summary>
public ulong StageChannelId { get; }

internal StageInstanceDeleteAuditLogData(string topic, StagePrivacyLevel privacyLevel, IUser user, ulong channelId)
{
Topic = topic;
PrivacyLevel = privacyLevel;
User = user;
StageChannelId = channelId;
}

internal static StageInstanceDeleteAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
{
var topic = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "topic").OldValue.ToObject<string>(discord.ApiClient.Serializer);
var privacyLevel = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "privacy_level").OldValue.ToObject<StagePrivacyLevel>(discord.ApiClient.Serializer);
var user = log.Users.FirstOrDefault(x => x.Id == entry.UserId);
var channelId = entry.Options.ChannelId;

return new StageInstanceDeleteAuditLogData(topic, privacyLevel, RestUser.Create(discord, user), channelId ?? 0);
}
}
}

+ 55
- 0
src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/StageInstanceUpdatedAuditLogData.cs View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model = Discord.API.AuditLog;
using EntryModel = Discord.API.AuditLogEntry;

namespace Discord.Rest
{
/// <summary>
/// Contains a piece of audit log data related to a stage instance update.
/// </summary>
public class StageInstanceUpdatedAuditLogData
{
/// <summary>
/// Gets the Id of the stage channel.
/// </summary>
public ulong StageChannelId { get; }

/// <summary>
/// Gets the stage information before the changes.
/// </summary>
public StageInfo Before { get; }

/// <summary>
/// Gets the stage information after the changes.
/// </summary>
public StageInfo After { get; }

internal StageInstanceUpdatedAuditLogData(ulong channelId, StageInfo before, StageInfo after)
{
StageChannelId = channelId;
Before = before;
After = after;
}

internal static StageInstanceUpdatedAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry)
{
var channelId = entry.Options.ChannelId.Value;

var topic = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "topic");
var privacy = entry.Changes.FirstOrDefault(x => x.ChangedProperty == "privacy");

var user = RestUser.Create(discord, log.Users.FirstOrDefault(x => x.Id == entry.UserId));

var oldTopic = topic?.OldValue.ToObject<string>();
var newTopic = topic?.NewValue.ToObject<string>();
var oldPrivacy = privacy?.OldValue.ToObject<StagePrivacyLevel>();
var newPrivacy = privacy?.NewValue.ToObject<StagePrivacyLevel>();

return new StageInstanceUpdatedAuditLogData(channelId, new StageInfo(user, oldPrivacy, oldTopic), new StageInfo(user, newPrivacy, newTopic));
}
}
}

Loading…
Cancel
Save