forked from discord-net/Discord.Net
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into docs/faq-n-patches-offline
- Loading branch information
Showing
50 changed files
with
1,575 additions
and
3 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
/// <summary> | ||
/// The action type within a <see cref="IAuditLogEntry"/> | ||
/// </summary> | ||
public enum ActionType | ||
{ | ||
GuildUpdated = 1, | ||
|
||
ChannelCreated = 10, | ||
ChannelUpdated = 11, | ||
ChannelDeleted = 12, | ||
|
||
OverwriteCreated = 13, | ||
OverwriteUpdated = 14, | ||
OverwriteDeleted = 15, | ||
|
||
Kick = 20, | ||
Prune = 21, | ||
Ban = 22, | ||
Unban = 23, | ||
|
||
MemberUpdated = 24, | ||
MemberRoleUpdated = 25, | ||
|
||
RoleCreated = 30, | ||
RoleUpdated = 31, | ||
RoleDeleted = 32, | ||
|
||
InviteCreated = 40, | ||
InviteUpdated = 41, | ||
InviteDeleted = 42, | ||
|
||
WebhookCreated = 50, | ||
WebhookUpdated = 51, | ||
WebhookDeleted = 52, | ||
|
||
EmojiCreated = 60, | ||
EmojiUpdated = 61, | ||
EmojiDeleted = 62, | ||
|
||
MessageDeleted = 72 | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
/// <summary> | ||
/// Represents data applied to an <see cref="IAuditLogEntry"/> | ||
/// </summary> | ||
public interface IAuditLogData | ||
{ } | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Discord | ||
{ | ||
/// <summary> | ||
/// Represents an entry in an audit log | ||
/// </summary> | ||
public interface IAuditLogEntry : IEntity<ulong> | ||
{ | ||
/// <summary> | ||
/// The action which occured to create this entry | ||
/// </summary> | ||
ActionType Action { get; } | ||
|
||
/// <summary> | ||
/// The data for this entry. May be <see cref="null"/> if no data was available. | ||
/// </summary> | ||
IAuditLogData Data { get; } | ||
|
||
/// <summary> | ||
/// The user responsible for causing the changes | ||
/// </summary> | ||
IUser User { get; } | ||
|
||
/// <summary> | ||
/// The reason behind the change. May be <see cref="null"/> if no reason was provided. | ||
/// </summary> | ||
string Reason { get; } | ||
} | ||
} |
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
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
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
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 |
---|---|---|
@@ -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 | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Discord.API | ||
{ | ||
internal class AuditLog | ||
{ | ||
[JsonProperty("webhooks")] | ||
public Webhook[] Webhooks { get; set; } | ||
|
||
[JsonProperty("users")] | ||
public User[] Users { get; set; } | ||
|
||
[JsonProperty("audit_log_entries")] | ||
public AuditLogEntry[] Entries { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Discord.API | ||
{ | ||
internal class AuditLogChange | ||
{ | ||
[JsonProperty("key")] | ||
public string ChangedProperty { get; set; } | ||
|
||
[JsonProperty("new_value")] | ||
public JToken NewValue { get; set; } | ||
|
||
[JsonProperty("old_value")] | ||
public JToken OldValue { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Discord.API | ||
{ | ||
internal class AuditLogEntry | ||
{ | ||
[JsonProperty("target_id")] | ||
public ulong? TargetId { get; set; } | ||
[JsonProperty("user_id")] | ||
public ulong UserId { get; set; } | ||
|
||
[JsonProperty("changes")] | ||
public AuditLogChange[] Changes { get; set; } | ||
[JsonProperty("options")] | ||
public AuditLogOptions Options { get; set; } | ||
|
||
[JsonProperty("id")] | ||
public ulong Id { get; set; } | ||
|
||
[JsonProperty("action_type")] | ||
public ActionType Action { get; set; } | ||
|
||
[JsonProperty("reason")] | ||
public string Reason { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace Discord.API | ||
{ | ||
internal class AuditLogOptions | ||
{ | ||
//Message delete | ||
[JsonProperty("count")] | ||
public int? MessageDeleteCount { get; set; } | ||
[JsonProperty("channel_id")] | ||
public ulong? MessageDeleteChannelId { get; set; } | ||
|
||
//Prune | ||
[JsonProperty("delete_member_days")] | ||
public int? PruneDeleteMemberDays { get; set; } | ||
[JsonProperty("members_removed")] | ||
public int? PruneMembersRemoved { get; set; } | ||
|
||
//Overwrite Update | ||
[JsonProperty("role_name")] | ||
public string OverwriteRoleName { get; set; } | ||
[JsonProperty("type")] | ||
public string OverwriteType { get; set; } | ||
[JsonProperty("id")] | ||
public ulong? OverwriteTargetId { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Discord.API.Rest | ||
{ | ||
class GetAuditLogsParams | ||
{ | ||
public Optional<int> Limit { get; set; } | ||
public Optional<ulong> BeforeEntryId { get; set; } | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Model = Discord.API.AuditLog; | ||
using EntryModel = Discord.API.AuditLogEntry; | ||
|
||
namespace Discord.Rest | ||
{ | ||
internal static class AuditLogHelper | ||
{ | ||
private static readonly Dictionary<ActionType, Func<BaseDiscordClient, Model, EntryModel, IAuditLogData>> CreateMapping | ||
= new Dictionary<ActionType, Func<BaseDiscordClient, Model, EntryModel, IAuditLogData>>() | ||
{ | ||
[ActionType.GuildUpdated] = GuildUpdateAuditLogData.Create, | ||
|
||
[ActionType.ChannelCreated] = ChannelCreateAuditLogData.Create, | ||
[ActionType.ChannelUpdated] = ChannelUpdateAuditLogData.Create, | ||
[ActionType.ChannelDeleted] = ChannelDeleteAuditLogData.Create, | ||
|
||
[ActionType.OverwriteCreated] = OverwriteCreateAuditLogData.Create, | ||
[ActionType.OverwriteUpdated] = OverwriteUpdateAuditLogData.Create, | ||
[ActionType.OverwriteDeleted] = OverwriteDeleteAuditLogData.Create, | ||
|
||
[ActionType.Kick] = KickAuditLogData.Create, | ||
[ActionType.Prune] = PruneAuditLogData.Create, | ||
[ActionType.Ban] = BanAuditLogData.Create, | ||
[ActionType.Unban] = UnbanAuditLogData.Create, | ||
[ActionType.MemberUpdated] = MemberUpdateAuditLogData.Create, | ||
[ActionType.MemberRoleUpdated] = MemberRoleAuditLogData.Create, | ||
|
||
[ActionType.RoleCreated] = RoleCreateAuditLogData.Create, | ||
[ActionType.RoleUpdated] = RoleUpdateAuditLogData.Create, | ||
[ActionType.RoleDeleted] = RoleDeleteAuditLogData.Create, | ||
|
||
[ActionType.InviteCreated] = InviteCreateAuditLogData.Create, | ||
[ActionType.InviteUpdated] = InviteUpdateAuditLogData.Create, | ||
[ActionType.InviteDeleted] = InviteDeleteAuditLogData.Create, | ||
|
||
[ActionType.WebhookCreated] = WebhookCreateAuditLogData.Create, | ||
[ActionType.WebhookUpdated] = WebhookUpdateAuditLogData.Create, | ||
[ActionType.WebhookDeleted] = WebhookDeleteAuditLogData.Create, | ||
|
||
[ActionType.EmojiCreated] = EmoteCreateAuditLogData.Create, | ||
[ActionType.EmojiUpdated] = EmoteUpdateAuditLogData.Create, | ||
[ActionType.EmojiDeleted] = EmoteDeleteAuditLogData.Create, | ||
|
||
[ActionType.MessageDeleted] = MessageDeleteAuditLogData.Create, | ||
}; | ||
|
||
public static IAuditLogData CreateData(BaseDiscordClient discord, Model log, EntryModel entry) | ||
{ | ||
if (CreateMapping.TryGetValue(entry.Action, out var func)) | ||
return func(discord, log, entry); | ||
|
||
return null; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Discord.Net.Rest/Entities/AuditLogs/DataTypes/BanAuditLogData.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Linq; | ||
|
||
using Model = Discord.API.AuditLog; | ||
using EntryModel = Discord.API.AuditLogEntry; | ||
|
||
namespace Discord.Rest | ||
{ | ||
public class BanAuditLogData : IAuditLogData | ||
{ | ||
private BanAuditLogData(IUser user) | ||
{ | ||
Target = user; | ||
} | ||
|
||
internal static BanAuditLogData Create(BaseDiscordClient discord, Model log, EntryModel entry) | ||
{ | ||
var userInfo = log.Users.FirstOrDefault(x => x.Id == entry.TargetId); | ||
return new BanAuditLogData(RestUser.Create(discord, userInfo)); | ||
} | ||
|
||
public IUser Target { get; } | ||
} | ||
} |
Oops, something went wrong.