-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
29 deletions.
There are no files selected for viewing
33 changes: 32 additions & 1 deletion
33
DisCatSharp/Entities/Guild/AuditLog/ChangeSet/ChannelOverwriteCreateChangeSet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,39 @@ | ||
namespace DisCatSharp.Entities.Guild.AuditLog; | ||
using System; | ||
using System.Linq; | ||
|
||
using DisCatSharp.Enums; | ||
|
||
namespace DisCatSharp.Entities.Guild.AuditLog; | ||
|
||
/// <summary> | ||
/// Represents a change set for adding a permission overwrite to a channel. | ||
/// </summary> | ||
public class ChannelOverwriteCreateChangeSet : AuditLogChangeSet | ||
{ | ||
/// <inheritdoc cref="AuditLogChangeSet.ValidFor" /> | ||
public new AuditLogActionType ValidFor = AuditLogActionType.ChannelOverwriteCreate; | ||
|
||
public bool AllowChanged => this.AllowBefore is not null || this.AllowAfter is not null; | ||
public Permissions? AllowBefore => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "allow")?.OldValue; | ||
public Permissions? AllowAfter => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "allow")?.NewValue; | ||
|
||
public bool DenyChanged => this.DenyBefore is not null || this.DenyAfter is not null; | ||
public Permissions? DenyBefore => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "deny")?.OldValue; | ||
public Permissions? DenyAfter => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "deny")?.NewValue; | ||
|
||
public override string ChangeDescription | ||
{ | ||
get | ||
{ | ||
var description = $"{this.UserId} executed {this.GetType().Name.Replace("ChangeSet", string.Empty)} for {this.Options!.OverwrittenEntityType} with id{this.Options.OverwrittenEntityId} {(this.Options.OverwrittenEntityType == OverwriteType.Role ? $" and name {this.Options.RoleName}" : string.Empty)} with reason {this.Reason ?? $"No reason given".Italic()}\n"; | ||
|
||
if (this.AllowChanged) | ||
description += this.AllowAfter is not null ? $"- Set Allowed Permissions to {this.AllowAfter}\n" : "- Unset Allowed Permissions\n"; | ||
|
||
if (this.DenyChanged) | ||
description += this.DenyAfter is not null ? $"- Set Denied Permissions to {this.DenyAfter}\n" : "- Unset Denied Permissions\n"; | ||
|
||
return description; | ||
} | ||
} | ||
} |
32 changes: 31 additions & 1 deletion
32
DisCatSharp/Entities/Guild/AuditLog/ChangeSet/ChannelOverwriteDeleteChangeSet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
namespace DisCatSharp.Entities.Guild.AuditLog; | ||
using System.Linq; | ||
|
||
using DisCatSharp.Enums; | ||
|
||
namespace DisCatSharp.Entities.Guild.AuditLog; | ||
|
||
/// <summary> | ||
/// Represents a change set for deleting a permission overwrite from a channel. | ||
/// </summary> | ||
public class ChannelOverwriteDeleteChangeSet : AuditLogChangeSet | ||
{ | ||
/// <inheritdoc cref="AuditLogChangeSet.ValidFor" /> | ||
public new AuditLogActionType ValidFor = AuditLogActionType.ChannelOverwriteDelete; | ||
|
||
public bool AllowChanged => this.AllowBefore is not null || this.AllowAfter is not null; | ||
public Permissions? AllowBefore => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "allow")?.OldValue; | ||
public Permissions? AllowAfter => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "allow")?.NewValue; | ||
|
||
public bool DenyChanged => this.DenyBefore is not null || this.DenyAfter is not null; | ||
public Permissions? DenyBefore => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "deny")?.OldValue; | ||
public Permissions? DenyAfter => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "deny")?.NewValue; | ||
|
||
public override string ChangeDescription | ||
{ | ||
get | ||
{ | ||
var description = $"{this.UserId} executed {this.GetType().Name.Replace("ChangeSet", string.Empty)} for {this.Options!.OverwrittenEntityType} with id{this.Options.OverwrittenEntityId} {(this.Options.OverwrittenEntityType == OverwriteType.Role ? $" and name {this.Options.RoleName}" : string.Empty)} with reason {this.Reason ?? $"No reason given".Italic()}\n"; | ||
|
||
if (this.AllowChanged) | ||
description += this.AllowAfter is not null ? $"- Set Allowed Permissions to {this.AllowAfter}\n" : "- Unset Allowed Permissions\n"; | ||
|
||
if (this.DenyChanged) | ||
description += this.DenyAfter is not null ? $"- Set Denied Permissions to {this.DenyAfter}\n" : "- Unset Denied Permissions\n"; | ||
|
||
return description; | ||
} | ||
} | ||
} |
32 changes: 31 additions & 1 deletion
32
DisCatSharp/Entities/Guild/AuditLog/ChangeSet/ChannelOverwriteUpdateChangeSet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
namespace DisCatSharp.Entities.Guild.AuditLog; | ||
using System.Linq; | ||
|
||
using DisCatSharp.Enums; | ||
|
||
namespace DisCatSharp.Entities.Guild.AuditLog; | ||
|
||
/// <summary> | ||
/// Represents a change set for updating a permission overwrite for a channel. | ||
/// </summary> | ||
public class ChannelOverwriteUpdateChangeSet : AuditLogChangeSet | ||
{ | ||
/// <inheritdoc cref="AuditLogChangeSet.ValidFor" /> | ||
public new AuditLogActionType ValidFor = AuditLogActionType.ChannelOverwriteUpdate; | ||
|
||
public bool AllowChanged => this.AllowBefore is not null || this.AllowAfter is not null; | ||
public Permissions? AllowBefore => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "allow")?.OldValue; | ||
public Permissions? AllowAfter => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "allow")?.NewValue; | ||
|
||
public bool DenyChanged => this.DenyBefore is not null || this.DenyAfter is not null; | ||
public Permissions? DenyBefore => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "deny")?.OldValue; | ||
public Permissions? DenyAfter => (Permissions?)this.Changes.FirstOrDefault(x => x.Key == "deny")?.NewValue; | ||
|
||
public override string ChangeDescription | ||
{ | ||
get | ||
{ | ||
var description = $"{this.UserId} executed {this.GetType().Name.Replace("ChangeSet", string.Empty)} for {this.Options!.OverwrittenEntityType} with id{this.Options.OverwrittenEntityId} {(this.Options.OverwrittenEntityType == OverwriteType.Role ? $" and name {this.Options.RoleName}" : string.Empty)} with reason {this.Reason ?? $"No reason given".Italic()}\n"; | ||
|
||
if (this.AllowChanged) | ||
description += this.AllowAfter is not null ? $"- Set Allowed Permissions to {this.AllowAfter}\n" : "- Unset Allowed Permissions\n"; | ||
|
||
if (this.DenyChanged) | ||
description += this.DenyAfter is not null ? $"- Set Denied Permissions to {this.DenyAfter}\n" : "- Unset Denied Permissions\n"; | ||
|
||
return description; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters