diff --git a/DisCatSharp/Entities/Interaction/DiscordInteraction.cs b/DisCatSharp/Entities/Interaction/DiscordInteraction.cs
index f3b208ede..b26f45fe5 100644
--- a/DisCatSharp/Entities/Interaction/DiscordInteraction.cs
+++ b/DisCatSharp/Entities/Interaction/DiscordInteraction.cs
@@ -1,238 +1,242 @@
// This file is part of the DisCatSharp project, based off DSharpPlus.
//
// Copyright (c) 2021-2023 AITSYS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DisCatSharp.Attributes;
using DisCatSharp.Enums;
using Newtonsoft.Json;
namespace DisCatSharp.Entities;
///
/// Represents an interaction that was invoked.
///
public sealed class DiscordInteraction : SnowflakeObject
{
///
/// Gets the type of interaction invoked.
///
[JsonProperty("type")]
public InteractionType Type { get; internal set; }
///
/// Gets the command data for this interaction.
///
[JsonProperty("data", NullValueHandling = NullValueHandling.Ignore)]
public DiscordInteractionData Data { get; internal set; }
///
/// Gets the Id of the guild that invoked this interaction.
///
[JsonIgnore]
public ulong? GuildId { get; internal set; }
///
/// Gets the guild that invoked this interaction.
///
[JsonIgnore]
public DiscordGuild Guild
=> (this.Discord as DiscordClient).InternalGetCachedGuild(this.GuildId);
///
/// Gets the Id of the channel that invoked this interaction.
///
[JsonIgnore]
public ulong ChannelId { get; internal set; }
///
/// Gets the channel that invoked this interaction.
///
[JsonIgnore]
public DiscordChannel Channel
=> (this.Discord as DiscordClient).InternalGetCachedChannel(this.ChannelId) ?? (DiscordChannel)(this.Discord as DiscordClient).InternalGetCachedThread(this.ChannelId) ?? (this.Guild == null ? new DiscordDmChannel { Id = this.ChannelId, Type = ChannelType.Private, Discord = this.Discord } : new DiscordChannel() { Id = this.ChannelId, Discord = this.Discord });
///
/// Gets the user that invoked this interaction.
/// This can be cast to a if created in a guild.
///
[JsonIgnore]
public DiscordUser User { get; internal set; }
///
/// Gets the continuation token for responding to this interaction.
///
[JsonProperty("token")]
public string Token { get; internal set; }
///
/// Gets the version number for this interaction type.
///
[JsonProperty("version")]
public int Version { get; internal set; }
///
/// Gets the ID of the application that created this interaction.
///
[JsonProperty("application_id")]
public ulong ApplicationId { get; internal set; }
///
/// The message this interaction was created with, if any.
///
[JsonProperty("message")]
internal DiscordMessage Message { get; set; }
///
/// Gets the invoking user locale.
///
[JsonProperty("locale", NullValueHandling = NullValueHandling.Ignore)]
public string Locale { get; internal set; }
///
/// Gets the guild locale if applicable.
///
[JsonProperty("guild_locale", NullValueHandling = NullValueHandling.Ignore)]
public string GuildLocale { get; internal set; }
///
/// Gets the applications permissions.
///
[JsonProperty("app_permissions", NullValueHandling = NullValueHandling.Ignore)]
public Permissions AppPermissions { get; internal set; }
///
/// Gets the entitlements.
/// This is related to premium subscriptions for bots.
/// Can only be used if you have an associated application subscription sku.
/// for more information.
///
[JsonProperty("entitlements", NullValueHandling = NullValueHandling.Ignore), DiscordInExperiment("Currently in closed beta."), Experimental("We provide this type but can't provide support.")]
public List Entitlements { get; internal set; } = new();
///
/// Creates a response to this interaction.
///
/// The type of the response.
/// The data, if any, to send.
public Task CreateResponseAsync(InteractionResponseType type, DiscordInteractionResponseBuilder builder = null)
=> this.Discord.ApiClient.CreateInteractionResponseAsync(this.Id, this.Token, type, builder);
///
/// Creates a modal response to this interaction.
///
/// The data to send.
public Task CreateInteractionModalResponseAsync(DiscordInteractionModalBuilder builder)
=> this.Type != InteractionType.Ping && this.Type != InteractionType.ModalSubmit ? this.Discord.ApiClient.CreateInteractionModalResponseAsync(this.Id, this.Token, InteractionResponseType.Modal, builder) : throw new NotSupportedException("You can't respond to an PING with a modal.");
///
/// Gets the original interaction response.
///
/// The original message that was sent. This does not work on ephemeral messages.
public Task GetOriginalResponseAsync()
=> this.Discord.ApiClient.GetOriginalInteractionResponseAsync(this.Discord.CurrentApplication.Id, this.Token);
///
/// Edits the original interaction response.
///
/// The webhook builder.
/// The edited .
public async Task EditOriginalResponseAsync(DiscordWebhookBuilder builder)
{
builder.Validate(isInteractionResponse: true);
if (builder.KeepAttachmentsInternal.HasValue && builder.KeepAttachmentsInternal.Value)
{
var attachments = this.Discord.ApiClient.GetOriginalInteractionResponseAsync(this.Discord.CurrentApplication.Id, this.Token).Result.Attachments;
if (attachments?.Count > 0)
{
builder.AttachmentsInternal.AddRange(attachments);
}
}
else if (builder.KeepAttachmentsInternal.HasValue)
{
builder.AttachmentsInternal.Clear();
}
return await this.Discord.ApiClient.EditOriginalInteractionResponseAsync(this.Discord.CurrentApplication.Id, this.Token, builder).ConfigureAwait(false);
}
///
/// Deletes the original interaction response.
/// >
public Task DeleteOriginalResponseAsync()
=> this.Discord.ApiClient.DeleteOriginalInteractionResponseAsync(this.Discord.CurrentApplication.Id, this.Token);
///
/// Creates a follow up message to this interaction.
///
/// The webhook builder.
/// The created .
public async Task CreateFollowupMessageAsync(DiscordFollowupMessageBuilder builder)
{
builder.Validate();
return await this.Discord.ApiClient.CreateFollowupMessageAsync(this.Discord.CurrentApplication.Id, this.Token, builder).ConfigureAwait(false);
}
///
/// Gets a follow up message.
///
/// The id of the follow up message.
public Task GetFollowupMessageAsync(ulong messageId)
=> this.Discord.ApiClient.GetFollowupMessageAsync(this.Discord.CurrentApplication.Id, this.Token, messageId);
///
/// Edits a follow up message.
///
/// The id of the follow up message.
/// The webhook builder.
/// The edited .
public async Task EditFollowupMessageAsync(ulong messageId, DiscordWebhookBuilder builder)
{
builder.Validate(isFollowup: true);
if (builder.KeepAttachmentsInternal.HasValue && builder.KeepAttachmentsInternal.Value)
{
var attachments = this.Discord.ApiClient.GetFollowupMessageAsync(this.Discord.CurrentApplication.Id, this.Token, messageId).Result.Attachments;
if (attachments?.Count > 0)
{
builder.AttachmentsInternal.AddRange(attachments);
}
}
else if (builder.KeepAttachmentsInternal.HasValue)
{
builder.AttachmentsInternal.Clear();
}
return await this.Discord.ApiClient.EditFollowupMessageAsync(this.Discord.CurrentApplication.Id, this.Token, messageId, builder).ConfigureAwait(false);
}
///
/// Deletes a follow up message.
///
/// The id of the follow up message.
public Task DeleteFollowupMessageAsync(ulong messageId)
=> this.Discord.ApiClient.DeleteFollowupMessageAsync(this.Discord.CurrentApplication.Id, this.Token, messageId);
+
+ internal DiscordInteraction()
+ : base(new List() { "member", "guild_id", "entitlement_sku_ids", "channel_id", "channel" })
+ { }
}
diff --git a/DisCatSharp/Net/Abstractions/AuditLogAbstractions.cs b/DisCatSharp/Net/Abstractions/AuditLogAbstractions.cs
index a775f6ea7..a424a6d56 100644
--- a/DisCatSharp/Net/Abstractions/AuditLogAbstractions.cs
+++ b/DisCatSharp/Net/Abstractions/AuditLogAbstractions.cs
@@ -1,577 +1,580 @@
// This file is part of the DisCatSharp project, based off DSharpPlus.
//
// Copyright (c) 2021-2023 AITSYS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System.Collections.Generic;
using DisCatSharp.Entities;
using DisCatSharp.Enums;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace DisCatSharp.Net.Abstractions;
///
/// Represents a audit log user.
///
internal sealed class AuditLogUser
{
///
/// Gets or sets the username.
///
[JsonProperty("username")]
public string Username { get; set; }
///
/// Gets or sets the discriminator.
///
[JsonProperty("discriminator")]
public string Discriminator { get; set; }
///
/// Gets or sets the id.
///
[JsonProperty("id")]
public ulong Id { get; set; }
///
/// Gets or sets the avatar hash.
///
[JsonProperty("avatar")]
public string AvatarHash { get; set; }
}
///
/// Represents a audit log webhook.
///
internal sealed class AuditLogWebhook
{
///
/// Gets or sets the name.
///
[JsonProperty("name")]
public string Name { get; set; }
///
/// Gets or sets the channel id.
///
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
///
/// Gets or sets the token.
///
[JsonProperty("token")]
public string Token { get; set; }
///
/// Gets or sets the avatar hash.
///
[JsonProperty("avatar")]
public string AvatarHash { get; set; }
///
/// Gets or sets the guild id.
///
[JsonProperty("guild_id")]
public ulong GuildId { get; set; }
///
/// Gets or sets the id.
///
[JsonProperty("id")]
public ulong Id { get; set; }
}
///
/// Represents a audit log thread metadata.
///
internal sealed class AuditLogThreadMetadata
{
///
/// Gets whether the thread is archived.
///
[JsonProperty("archived")]
public bool Archived { get; set; }
///
/// Gets the threads archive timestamp.
///
[JsonProperty("archive_timestamp", NullValueHandling = NullValueHandling.Ignore)]
public string ArchiveTimestamp { get; set; }
///
/// Gets the threads auto archive duration.
///
[JsonProperty("auto_archive_duration")]
public int AutoArchiveDuration { get; set; }
///
/// Gets whether the thread is locked.
///
[JsonProperty("locked")]
public bool Locked { get; set; }
}
///
/// Represents a audit log thread.
///
internal sealed class AuditLogThread
{
///
/// Gets the thread id.
///
[JsonProperty("id")]
public ulong Id { get; set; }
///
/// Gets the thread guild id.
///
[JsonProperty("guild_id")]
public ulong GuildId { get; set; }
///
/// Gets the thread parent channel id.
///
[JsonProperty("parent_id")]
public ulong ParentId { get; set; }
///
/// Gets the thread owner id.
///
[JsonProperty("owner_id", NullValueHandling = NullValueHandling.Ignore)]
public ulong? OwnerId { get; set; }
///
/// Gets the thread type.
///
[JsonProperty("type")]
public ChannelType Type { get; set; }
///
/// Gets the thread name.
///
[JsonProperty("name")]
public string Name { get; set; }
///
/// Gets the thread last message id.
///
[JsonProperty("last_message_id", NullValueHandling = NullValueHandling.Ignore)]
public ulong? LastMessageId { get; set; }
///
/// Gets the thread metadata.
///
[JsonProperty("thread_metadata")]
public AuditLogThreadMetadata Metadata { get; set; }
///
/// Gets the thread approximate message count.
///
[JsonProperty("message_count", NullValueHandling = NullValueHandling.Ignore)]
public int? MessageCount { get; set; }
///
/// Gets the thread member count.
///
[JsonProperty("member_count", NullValueHandling = NullValueHandling.Ignore)]
public int? MemberCount { get; set; }
///
/// Gets the thread rate limit per user.
///
[JsonProperty("rate_limit_per_user", NullValueHandling = NullValueHandling.Ignore)]
public int? RateLimitPerUser { get; set; }
}
///
/// Represents a audit log scheduled event.
///
internal sealed class AuditLogGuildScheduledEvent
{
///
/// Gets the scheduled event id.
///
[JsonProperty("id")]
public ulong Id { get; set; }
///
/// Gets the scheduled event guild id.
///
[JsonProperty("guild_id")]
public ulong GuildId { get; set; }
///
/// Gets the scheduled event channel id.
///
[JsonProperty("channel_id", NullValueHandling = NullValueHandling.Ignore)]
public ulong ChannelId { get; set; }
///
/// Gets the scheduled event creator id.
///
[JsonProperty("creator_id")]
public ulong CreatorId { get; set; }
///
/// Gets the scheduled event name.
///
[JsonProperty("name")]
public string Name { get; set; }
///
/// Gets the scheduled event description.
///
[JsonProperty("description")]
public string Description { get; set; }
///
/// Gets the scheduled event image.
///
[JsonProperty("image", NullValueHandling = NullValueHandling.Ignore)]
public string Image { get; set; }
///
/// Gets the scheduled event scheduled start time.
///
[JsonProperty("scheduled_start_time")]
public string ScheduledStartTime;
///
/// Gets the scheduled event scheduled end time.
///
[JsonProperty("scheduled_end_time")]
public string ScheduledEndTime { get; set; }
///
/// Gets the scheduled event privacy level.
///
[JsonProperty("privacy_level")]
public ScheduledEventPrivacyLevel PrivacyLevel { get; set; }
///
/// Gets the scheduled event status.
///
[JsonProperty("status")]
public ScheduledEventStatus Status { get; set; }
///
/// Gets the scheduled event entity type.
///
[JsonProperty("entity_type")]
public ScheduledEventEntityType EntityType { get; set; }
///
/// Gets the scheduled event entity id.
///
[JsonProperty("entity_id", NullValueHandling = NullValueHandling.Ignore)]
public ulong EntityId { get; set; }
///
/// Gets the scheduled event entity metadata.
///
[JsonProperty("entity_metadata")]
public AuditLogGuildScheduledEventEntityMetadata EntityMetadata { get; set; }
///
/// Gets the scheduled event sku ids.
///
[JsonProperty("sku_ids")]
public List SkuIds { get; set; }
}
///
/// Represents a audit log scheduled event entity metadata.
///
internal sealed class AuditLogGuildScheduledEventEntityMetadata
{
///
/// Gets the scheduled events external location.
///
[JsonProperty("location")]
public string Location { get; set; }
}
///
/// Represents a audit log integration account.
///
internal sealed class AuditLogIntegrationAccount
{
///
/// Gets the account id.
///
[JsonProperty("id")]
public string Id { get; set; }
///
/// Gets the account name.
///
[JsonProperty("name")]
public string Name { get; set; }
}
///
/// Represents a audit log integration.
///
internal sealed class AuditLogIntegration
{
///
/// Gets the integration id.
///
[JsonProperty("id")]
public ulong Id { get; set; }
///
/// Gets the integration type.
///
[JsonProperty("type")]
public string Type { get; set; }
///
/// Gets the integration name.
///
[JsonProperty("name")]
public string Name { get; set; }
///
/// Gets the integration account.
///
[JsonProperty("account")]
public AuditLogIntegrationAccount Account { get; set; }
}
///
/// Represents a audit log action change.
///
internal sealed class AuditLogActionChange
{
// this can be a string or an array
///
/// Gets or sets the old value.
///
[JsonProperty("old_value")]
public object OldValue { get; set; }
///
/// Gets the old values.
///
[JsonIgnore]
public IReadOnlyList OldValues
=> (this.OldValue as JArray)?.ToObject>();
///
/// Gets the old value ulong.
///
[JsonIgnore]
public ulong OldValueUlong
=> (ulong)this.OldValue;
///
/// Gets the old value string.
///
[JsonIgnore]
public string OldValueString
=> (string)this.OldValue;
// this can be a string or an array
///
/// Gets or sets the new value.
///
[JsonProperty("new_value")]
public object NewValue { get; set; }
///
/// Gets the new values.
///
[JsonIgnore]
public IReadOnlyList NewValues
=> (this.NewValue as JArray)?.ToObject>();
///
/// Gets the new value ulong.
///
[JsonIgnore]
public ulong NewValueUlong
=> (ulong)this.NewValue;
///
/// Gets the new value string.
///
[JsonIgnore]
public string NewValueString
=> (string)this.NewValue;
///
/// Gets or sets the key.
///
[JsonProperty("key")]
public string Key { get; set; }
}
///
/// Represents a audit log action options.
///
internal sealed class AuditLogActionOptions
{
///
/// Gets or sets the type.
///
[JsonProperty("type")]
public object Type { get; set; }
///
/// Gets or sets the id.
///
[JsonProperty("id")]
public ulong Id { get; set; }
///
/// Gets or sets the channel id.
///
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
///
/// Gets or sets the message id.
///
[JsonProperty("message_id")]
public ulong MessageId { get; set; }
///
/// Gets or sets the count.
///
[JsonProperty("count")]
public int Count { get; set; }
///
/// Gets or sets the delete member days.
///
[JsonProperty("delete_member_days")]
public int DeleteMemberDays { get; set; }
///
/// Gets or sets the members removed.
///
[JsonProperty("members_removed")]
public int MembersRemoved { get; set; }
}
///
/// Represents a audit log action.
///
internal sealed class AuditLogAction
{
///
/// Gets or sets the target id.
///
[JsonProperty("target_id")]
public ulong? TargetId { get; set; }
///
/// Gets or sets the user id.
///
[JsonProperty("user_id", NullValueHandling = NullValueHandling.Ignore)]
public ulong UserId { get; set; }
///
/// Gets or sets the id.
///
[JsonProperty("id")]
public ulong Id { get; set; }
///
/// Gets or sets the action type.
///
[JsonProperty("action_type", NullValueHandling = NullValueHandling.Ignore)]
public AuditLogActionType ActionType { get; set; }
///
/// Gets or sets the changes.
///
[JsonProperty("changes")]
public IReadOnlyList Changes { get; set; }
///
/// Gets or sets the options.
///
[JsonProperty("options")]
public AuditLogActionOptions Options { get; set; }
///
/// Gets or sets the reason.
///
[JsonProperty("reason")]
public string Reason { get; set; }
}
///
/// Represents a audit log.
///
internal sealed class AuditLog : ObservableApiObject
{
///
/// Gets or sets the webhooks.
///
[JsonProperty("webhooks")]
public IReadOnlyList Webhooks { get; set; }
///
/// Gets or sets the users.
///
[JsonProperty("users")]
public IReadOnlyList Users { get; set; }
///
/// Gets or sets the entries.
///
[JsonProperty("audit_log_entries")]
public IReadOnlyList Entries { get; set; }
///
/// Gets or sets the scheduled events.
///
[JsonProperty("guild_scheduled_events")]
public IReadOnlyList ScheduledEvents { get; set; }
///
/// Gets or sets the threads.
///
[JsonProperty("threads")]
public IReadOnlyList Threads { get; set; }
///
/// Gets or sets the integrations.
/// Twitch related.
///
[JsonProperty("integrations")]
public IReadOnlyList Integrations { get; set; }
/*
///
/// Gets or sets the application commands.
/// Related to Permissions V2.
///
[JsonProperty("application_commands")]
public IReadOnlyList ApplicationCommands { get; set; }
*/
+ internal AuditLog()
+ : base(new List { "application_commands", "auto_moderation_rules"})
+ { }
}