Skip to content

Commit c54867f

Browse files
NeKzorfoxbot
authored andcommitted
feature: update audit log models (#1373)
* Fix bugs * Add missing properties * Add missing properties to ChannelInfo Remove UserLimit property * Add missing properties to GuildInfo Change ContentFilterLevel of type int? to ExplicitContentFilter of type ExplicitContentFilterLevel? * Remove AvatarHash from MemberInfo * Add missing doc comments * Make ExplicitContentFilter public * Add ChannelId property to overwrite audits * Update doc comments based on feedback
1 parent 606dac3 commit c54867f

12 files changed

+233
-42
lines changed

src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelCreateAuditLogData.cs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ namespace Discord.Rest
1111
/// </summary>
1212
public class ChannelCreateAuditLogData : IAuditLogData
1313
{
14-
private ChannelCreateAuditLogData(ulong id, string name, ChannelType type, IReadOnlyCollection<Overwrite> overwrites)
14+
private ChannelCreateAuditLogData(ulong id, string name, ChannelType type, int? rateLimit, bool? nsfw, int? bitrate, IReadOnlyCollection<Overwrite> overwrites)
1515
{
1616
ChannelId = id;
1717
ChannelName = name;
1818
ChannelType = type;
19+
SlowModeInterval = rateLimit;
20+
IsNsfw = nsfw;
21+
Bitrate = bitrate;
1922
Overwrites = overwrites;
2023
}
2124

@@ -27,9 +30,15 @@ internal static ChannelCreateAuditLogData Create(BaseDiscordClient discord, Mode
2730
var overwritesModel = changes.FirstOrDefault(x => x.ChangedProperty == "permission_overwrites");
2831
var typeModel = changes.FirstOrDefault(x => x.ChangedProperty == "type");
2932
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name");
33+
var rateLimitPerUserModel = changes.FirstOrDefault(x => x.ChangedProperty == "rate_limit_per_user");
34+
var nsfwModel = changes.FirstOrDefault(x => x.ChangedProperty == "nsfw");
35+
var bitrateModel = changes.FirstOrDefault(x => x.ChangedProperty == "bitrate");
3036

3137
var type = typeModel.NewValue.ToObject<ChannelType>(discord.ApiClient.Serializer);
3238
var name = nameModel.NewValue.ToObject<string>(discord.ApiClient.Serializer);
39+
int? rateLimitPerUser = rateLimitPerUserModel?.NewValue?.ToObject<int>(discord.ApiClient.Serializer);
40+
bool? nsfw = nsfwModel?.NewValue?.ToObject<bool>(discord.ApiClient.Serializer);
41+
int? bitrate = bitrateModel?.NewValue?.ToObject<int>(discord.ApiClient.Serializer);
3342

3443
foreach (var overwrite in overwritesModel.NewValue)
3544
{
@@ -41,7 +50,7 @@ internal static ChannelCreateAuditLogData Create(BaseDiscordClient discord, Mode
4150
overwrites.Add(new Overwrite(id, permType, new OverwritePermissions(allow, deny)));
4251
}
4352

44-
return new ChannelCreateAuditLogData(entry.TargetId.Value, name, type, overwrites.ToReadOnlyCollection());
53+
return new ChannelCreateAuditLogData(entry.TargetId.Value, name, type, rateLimitPerUser, nsfw, bitrate, overwrites.ToReadOnlyCollection());
4554
}
4655

4756
/// <summary>
@@ -66,6 +75,32 @@ internal static ChannelCreateAuditLogData Create(BaseDiscordClient discord, Mode
6675
/// </returns>
6776
public ChannelType ChannelType { get; }
6877
/// <summary>
78+
/// Gets the current slow-mode delay of the created channel.
79+
/// </summary>
80+
/// <returns>
81+
/// An <see cref="Int32"/> representing the time in seconds required before the user can send another
82+
/// message; <c>0</c> if disabled.
83+
/// <c>null</c> if this is not mentioned in this entry.
84+
/// </returns>
85+
public int? SlowModeInterval { get; }
86+
/// <summary>
87+
/// Gets the value that indicates whether the created channel is NSFW.
88+
/// </summary>
89+
/// <returns>
90+
/// <c>true</c> if the created channel has the NSFW flag enabled; otherwise <c>false</c>.
91+
/// <c>null</c> if this is not mentioned in this entry.
92+
/// </returns>
93+
public bool? IsNsfw { get; }
94+
/// <summary>
95+
/// Gets the bit-rate that the clients in the created voice channel are requested to use.
96+
/// </summary>
97+
/// <returns>
98+
/// An <see cref="Int32"/> representing the bit-rate (bps) that the created voice channel defines and requests the
99+
/// client(s) to use.
100+
/// <c>null</c> if this is not mentioned in this entry.
101+
/// </returns>
102+
public int? Bitrate { get; }
103+
/// <summary>
69104
/// Gets a collection of permission overwrites that was assigned to the created channel.
70105
/// </summary>
71106
/// <returns>

src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelDeleteAuditLogData.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ namespace Discord.Rest
1111
/// </summary>
1212
public class ChannelDeleteAuditLogData : IAuditLogData
1313
{
14-
private ChannelDeleteAuditLogData(ulong id, string name, ChannelType type, IReadOnlyCollection<Overwrite> overwrites)
14+
private ChannelDeleteAuditLogData(ulong id, string name, ChannelType type, int? rateLimit, bool? nsfw, int? bitrate, IReadOnlyCollection<Overwrite> overwrites)
1515
{
1616
ChannelId = id;
1717
ChannelName = name;
1818
ChannelType = type;
19+
SlowModeInterval = rateLimit;
20+
IsNsfw = nsfw;
21+
Bitrate = bitrate;
1922
Overwrites = overwrites;
2023
}
2124

@@ -26,15 +29,21 @@ internal static ChannelDeleteAuditLogData Create(BaseDiscordClient discord, Mode
2629
var overwritesModel = changes.FirstOrDefault(x => x.ChangedProperty == "permission_overwrites");
2730
var typeModel = changes.FirstOrDefault(x => x.ChangedProperty == "type");
2831
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name");
32+
var rateLimitPerUserModel = changes.FirstOrDefault(x => x.ChangedProperty == "rate_limit_per_user");
33+
var nsfwModel = changes.FirstOrDefault(x => x.ChangedProperty == "nsfw");
34+
var bitrateModel = changes.FirstOrDefault(x => x.ChangedProperty == "bitrate");
2935

3036
var overwrites = overwritesModel.OldValue.ToObject<API.Overwrite[]>(discord.ApiClient.Serializer)
3137
.Select(x => new Overwrite(x.TargetId, x.TargetType, new OverwritePermissions(x.Allow, x.Deny)))
3238
.ToList();
3339
var type = typeModel.OldValue.ToObject<ChannelType>(discord.ApiClient.Serializer);
3440
var name = nameModel.OldValue.ToObject<string>(discord.ApiClient.Serializer);
41+
int? rateLimitPerUser = rateLimitPerUserModel?.OldValue?.ToObject<int>(discord.ApiClient.Serializer);
42+
bool? nsfw = nsfwModel?.OldValue?.ToObject<bool>(discord.ApiClient.Serializer);
43+
int? bitrate = bitrateModel?.OldValue?.ToObject<int>(discord.ApiClient.Serializer);
3544
var id = entry.TargetId.Value;
3645

37-
return new ChannelDeleteAuditLogData(id, name, type, overwrites.ToReadOnlyCollection());
46+
return new ChannelDeleteAuditLogData(id, name, type, rateLimitPerUser, nsfw, bitrate, overwrites.ToReadOnlyCollection());
3847
}
3948

4049
/// <summary>
@@ -59,6 +68,31 @@ internal static ChannelDeleteAuditLogData Create(BaseDiscordClient discord, Mode
5968
/// </returns>
6069
public ChannelType ChannelType { get; }
6170
/// <summary>
71+
/// Gets the slow-mode delay of the deleted channel.
72+
/// </summary>
73+
/// <returns>
74+
/// An <see cref="Int32"/> representing the time in seconds required before the user can send another
75+
/// message; <c>0</c> if disabled.
76+
/// <c>null</c> if this is not mentioned in this entry.
77+
/// </returns>
78+
public int? SlowModeInterval { get; }
79+
/// <summary>
80+
/// Gets the value that indicates whether the deleted channel was NSFW.
81+
/// </summary>
82+
/// <returns>
83+
/// <c>true</c> if this channel had the NSFW flag enabled; otherwise <c>false</c>.
84+
/// <c>null</c> if this is not mentioned in this entry.
85+
/// </returns>
86+
public bool? IsNsfw { get; }
87+
/// <summary>
88+
/// Gets the bit-rate of this channel if applicable.
89+
/// </summary>
90+
/// <returns>
91+
/// An <see cref="Int32"/> representing the bit-rate set of the voice channel.
92+
/// <c>null</c> if this is not mentioned in this entry.
93+
/// </returns>
94+
public int? Bitrate { get; }
95+
/// <summary>
6296
/// Gets a collection of permission overwrites that was assigned to the deleted channel.
6397
/// </summary>
6498
/// <returns>

src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelInfo.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ namespace Discord.Rest
55
/// </summary>
66
public struct ChannelInfo
77
{
8-
internal ChannelInfo(string name, string topic, int? bitrate, int? limit)
8+
internal ChannelInfo(string name, string topic, int? rateLimit, bool? nsfw, int? bitrate)
99
{
1010
Name = name;
1111
Topic = topic;
12+
SlowModeInterval = rateLimit;
13+
IsNsfw = nsfw;
1214
Bitrate = bitrate;
13-
UserLimit = limit;
1415
}
1516

1617
/// <summary>
@@ -28,20 +29,29 @@ internal ChannelInfo(string name, string topic, int? bitrate, int? limit)
2829
/// </returns>
2930
public string Topic { get; }
3031
/// <summary>
31-
/// Gets the bit-rate of this channel if applicable.
32+
/// Gets the current slow-mode delay of this channel.
3233
/// </summary>
3334
/// <returns>
34-
/// An <see cref="System.Int32"/> representing the bit-rate set for the voice channel; <c>null</c> if not
35-
/// applicable.
35+
/// An <see cref="Int32"/> representing the time in seconds required before the user can send another
36+
/// message; <c>0</c> if disabled.
37+
/// <c>null</c> if this is not mentioned in this entry.
3638
/// </returns>
37-
public int? Bitrate { get; }
39+
public int? SlowModeInterval { get; }
40+
/// <summary>
41+
/// Gets the value that indicates whether this channel is NSFW.
42+
/// </summary>
43+
/// <returns>
44+
/// <c>true</c> if this channel has the NSFW flag enabled; otherwise <c>false</c>.
45+
/// <c>null</c> if this is not mentioned in this entry.
46+
/// </returns>
47+
public bool? IsNsfw { get; }
3848
/// <summary>
39-
/// Gets the number of users allowed to be in this channel if applicable.
49+
/// Gets the bit-rate of this channel if applicable.
4050
/// </summary>
4151
/// <returns>
42-
/// An <see cref="System.Int32" /> representing the number of users allowed to be in this voice channel;
43-
/// <c>null</c> if not applicable.
52+
/// An <see cref="Int32"/> representing the bit-rate set for the voice channel;
53+
/// <c>null</c> if this is not mentioned in this entry.
4454
/// </returns>
45-
public int? UserLimit { get; }
55+
public int? Bitrate { get; }
4656
}
4757
}

src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/ChannelUpdateAuditLogData.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@ internal static ChannelUpdateAuditLogData Create(BaseDiscordClient discord, Mode
2323

2424
var nameModel = changes.FirstOrDefault(x => x.ChangedProperty == "name");
2525
var topicModel = changes.FirstOrDefault(x => x.ChangedProperty == "topic");
26+
var rateLimitPerUserModel = changes.FirstOrDefault(x => x.ChangedProperty == "rate_limit_per_user");
27+
var nsfwModel = changes.FirstOrDefault(x => x.ChangedProperty == "nsfw");
2628
var bitrateModel = changes.FirstOrDefault(x => x.ChangedProperty == "bitrate");
27-
var userLimitModel = changes.FirstOrDefault(x => x.ChangedProperty == "user_limit");
2829

2930
string oldName = nameModel?.OldValue?.ToObject<string>(discord.ApiClient.Serializer),
3031
newName = nameModel?.NewValue?.ToObject<string>(discord.ApiClient.Serializer);
3132
string oldTopic = topicModel?.OldValue?.ToObject<string>(discord.ApiClient.Serializer),
3233
newTopic = topicModel?.NewValue?.ToObject<string>(discord.ApiClient.Serializer);
34+
int? oldRateLimitPerUser = rateLimitPerUserModel?.OldValue?.ToObject<int>(discord.ApiClient.Serializer),
35+
newRateLimitPerUser = rateLimitPerUserModel?.NewValue?.ToObject<int>(discord.ApiClient.Serializer);
36+
bool? oldNsfw = nsfwModel?.OldValue?.ToObject<bool>(discord.ApiClient.Serializer),
37+
newNsfw = nsfwModel?.NewValue?.ToObject<bool>(discord.ApiClient.Serializer);
3338
int? oldBitrate = bitrateModel?.OldValue?.ToObject<int>(discord.ApiClient.Serializer),
3439
newBitrate = bitrateModel?.NewValue?.ToObject<int>(discord.ApiClient.Serializer);
35-
int? oldLimit = userLimitModel?.OldValue?.ToObject<int>(discord.ApiClient.Serializer),
36-
newLimit = userLimitModel?.NewValue?.ToObject<int>(discord.ApiClient.Serializer);
3740

38-
var before = new ChannelInfo(oldName, oldTopic, oldBitrate, oldLimit);
39-
var after = new ChannelInfo(newName, newTopic, newBitrate, newLimit);
41+
var before = new ChannelInfo(oldName, oldTopic, oldRateLimitPerUser, oldNsfw, oldBitrate);
42+
var after = new ChannelInfo(newName, newTopic, newRateLimitPerUser, newNsfw, newBitrate);
4043

4144
return new ChannelUpdateAuditLogData(entry.TargetId.Value, before, after);
4245
}

src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/GuildInfo.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ public struct GuildInfo
77
{
88
internal GuildInfo(int? afkTimeout, DefaultMessageNotifications? defaultNotifs,
99
ulong? afkChannel, string name, string region, string icon,
10-
VerificationLevel? verification, IUser owner, MfaLevel? mfa, int? filter)
10+
VerificationLevel? verification, IUser owner, MfaLevel? mfa, ExplicitContentFilterLevel? filter,
11+
ulong? systemChannel, ulong? widgetChannel, bool? widget)
1112
{
1213
AfkTimeout = afkTimeout;
1314
DefaultMessageNotifications = defaultNotifs;
@@ -18,7 +19,10 @@ internal GuildInfo(int? afkTimeout, DefaultMessageNotifications? defaultNotifs,
1819
VerificationLevel = verification;
1920
Owner = owner;
2021
MfaLevel = mfa;
21-
ContentFilterLevel = filter;
22+
ExplicitContentFilter = filter;
23+
SystemChannelId = systemChannel;
24+
EmbedChannelId = widgetChannel;
25+
IsEmbeddable = widget;
2226
}
2327

2428
/// <summary>
@@ -28,11 +32,16 @@ internal GuildInfo(int? afkTimeout, DefaultMessageNotifications? defaultNotifs,
2832
/// <returns>
2933
/// An <see cref="int"/> representing the amount of time in seconds for a user to be marked as inactive
3034
/// and moved into the AFK voice channel.
35+
/// <c>null</c> if this is not mentioned in this entry.
3136
/// </returns>
3237
public int? AfkTimeout { get; }
3338
/// <summary>
3439
/// Gets the default message notifications for users who haven't explicitly set their notification settings.
3540
/// </summary>
41+
/// <returns>
42+
/// The default message notifications setting of this guild.
43+
/// <c>null</c> if this is not mentioned in this entry.
44+
/// </returns>
3645
public DefaultMessageNotifications? DefaultMessageNotifications { get; }
3746
/// <summary>
3847
/// Gets the ID of the AFK voice channel for this guild.
@@ -65,6 +74,7 @@ internal GuildInfo(int? afkTimeout, DefaultMessageNotifications? defaultNotifs,
6574
/// </summary>
6675
/// <returns>
6776
/// The level of requirements.
77+
/// <c>null</c> if this is not mentioned in this entry.
6878
/// </returns>
6979
public VerificationLevel? VerificationLevel { get; }
7080
/// <summary>
@@ -80,8 +90,39 @@ internal GuildInfo(int? afkTimeout, DefaultMessageNotifications? defaultNotifs,
8090
/// </summary>
8191
/// <returns>
8292
/// The level of MFA requirement.
93+
/// <c>null</c> if this is not mentioned in this entry.
8394
/// </returns>
8495
public MfaLevel? MfaLevel { get; }
85-
public int? ContentFilterLevel { get; }
96+
/// <summary>
97+
/// Gets the level of content filtering applied to user's content in a Guild.
98+
/// </summary>
99+
/// <returns>
100+
/// The level of explicit content filtering.
101+
/// </returns>
102+
public ExplicitContentFilterLevel? ExplicitContentFilter { get; }
103+
/// <summary>
104+
/// Gets the ID of the channel where system messages are sent.
105+
/// </summary>
106+
/// <returns>
107+
/// A <see cref="ulong"/> representing the snowflake identifier of the channel where system
108+
/// messages are sent; <c>null</c> if none is set.
109+
/// </returns>
110+
public ulong? SystemChannelId { get; }
111+
/// <summary>
112+
/// Gets the ID of the widget embed channel of this guild.
113+
/// </summary>
114+
/// <returns>
115+
/// A <see cref="ulong"/> representing the snowflake identifier of the embedded channel found within the
116+
/// widget settings of this guild; <c>null</c> if none is set.
117+
/// </returns>
118+
public ulong? EmbedChannelId { get; }
119+
/// <summary>
120+
/// Gets a value that indicates whether this guild is embeddable (i.e. can use widget).
121+
/// </summary>
122+
/// <returns>
123+
/// <c>true</c> if this guild can be embedded via widgets; otherwise <c>false</c>.
124+
/// <c>null</c> if this is not mentioned in this entry.
125+
/// </returns>
126+
public bool? IsEmbeddable { get; }
86127
}
87128
}

0 commit comments

Comments
 (0)