Fix: Integration model from GuildIntegration and added INTEGRATION gateway events (#2168)
* fix integration models; add integration events * fix description on IGUILD for integration * fix typo in integration documentation * fix documentation in connection visibility * removed public identitiers from app and connection * Removed REST endpoints that are not part of the API. * Added documentation for rest integrations * added optional types * Fixed rest interaction field with not being IsSpecified
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Gateway
|
||||
{
|
||||
internal class IntegrationDeletedEvent
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public ulong Id { get; set; }
|
||||
[JsonProperty("guild_id")]
|
||||
public ulong GuildId { get; set; }
|
||||
[JsonProperty("application_id")]
|
||||
public Optional<ulong> ApplicationID { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -415,6 +415,32 @@ namespace Discord.WebSocket
|
||||
|
||||
#endregion
|
||||
|
||||
#region Integrations
|
||||
/// <summary> Fired when an integration is created. </summary>
|
||||
public event Func<IIntegration, Task> IntegrationCreated
|
||||
{
|
||||
add { _integrationCreated.Add(value); }
|
||||
remove { _integrationCreated.Remove(value); }
|
||||
}
|
||||
internal readonly AsyncEvent<Func<IIntegration, Task>> _integrationCreated = new AsyncEvent<Func<IIntegration, Task>>();
|
||||
|
||||
/// <summary> Fired when an integration is updated. </summary>
|
||||
public event Func<IIntegration, Task> IntegrationUpdated
|
||||
{
|
||||
add { _integrationUpdated.Add(value); }
|
||||
remove { _integrationUpdated.Remove(value); }
|
||||
}
|
||||
internal readonly AsyncEvent<Func<IIntegration, Task>> _integrationUpdated = new AsyncEvent<Func<IIntegration, Task>>();
|
||||
|
||||
/// <summary> Fired when an integration is deleted. </summary>
|
||||
public event Func<IGuild, ulong, Optional<ulong>, Task> IntegrationDeleted
|
||||
{
|
||||
add { _integrationDeleted.Add(value); }
|
||||
remove { _integrationDeleted.Remove(value); }
|
||||
}
|
||||
internal readonly AsyncEvent<Func<IGuild, ulong, Optional<ulong>, Task>> _integrationDeleted = new AsyncEvent<Func<IGuild, ulong, Optional<ulong>, Task>>();
|
||||
#endregion
|
||||
|
||||
#region Users
|
||||
/// <summary> Fired when a user joins a guild. </summary>
|
||||
public event Func<SocketGuildUser, Task> UserJoined
|
||||
|
||||
@@ -2017,6 +2017,92 @@ namespace Discord.WebSocket
|
||||
break;
|
||||
#endregion
|
||||
|
||||
#region Integrations
|
||||
case "INTEGRATION_CREATE":
|
||||
{
|
||||
await _gatewayLogger.DebugAsync("Received Dispatch (INTEGRATION_CREATE)").ConfigureAwait(false);
|
||||
|
||||
var data = (payload as JToken).ToObject<Integration>(_serializer);
|
||||
|
||||
// Integrations from Gateway should always have guild IDs specified.
|
||||
if (!data.GuildId.IsSpecified)
|
||||
return;
|
||||
|
||||
var guild = State.GetGuild(data.GuildId.Value);
|
||||
|
||||
if (guild != null)
|
||||
{
|
||||
if (!guild.IsSynced)
|
||||
{
|
||||
await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await TimedInvokeAsync(_integrationCreated, nameof(IntegrationCreated), RestIntegration.Create(this, guild, data)).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await UnknownGuildAsync(type, data.GuildId.Value).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "INTEGRATION_UPDATE":
|
||||
{
|
||||
await _gatewayLogger.DebugAsync("Received Dispatch (INTEGRATION_UPDATE)").ConfigureAwait(false);
|
||||
|
||||
var data = (payload as JToken).ToObject<Integration>(_serializer);
|
||||
|
||||
// Integrations from Gateway should always have guild IDs specified.
|
||||
if (!data.GuildId.IsSpecified)
|
||||
return;
|
||||
|
||||
var guild = State.GetGuild(data.GuildId.Value);
|
||||
|
||||
if (guild != null)
|
||||
{
|
||||
if (!guild.IsSynced)
|
||||
{
|
||||
await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await TimedInvokeAsync(_integrationUpdated, nameof(IntegrationUpdated), RestIntegration.Create(this, guild, data)).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await UnknownGuildAsync(type, data.GuildId.Value).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "INTEGRATION_DELETE":
|
||||
{
|
||||
await _gatewayLogger.DebugAsync("Received Dispatch (INTEGRATION_DELETE)").ConfigureAwait(false);
|
||||
|
||||
var data = (payload as JToken).ToObject<IntegrationDeletedEvent>(_serializer);
|
||||
|
||||
var guild = State.GetGuild(data.GuildId);
|
||||
|
||||
if (guild != null)
|
||||
{
|
||||
if (!guild.IsSynced)
|
||||
{
|
||||
await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await TimedInvokeAsync(_integrationDeleted, nameof(IntegrationDeleted), guild, data.Id, data.ApplicationID).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await UnknownGuildAsync(type, data.GuildId).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endregion
|
||||
|
||||
#region Users
|
||||
case "USER_UPDATE":
|
||||
{
|
||||
|
||||
@@ -847,10 +847,10 @@ namespace Discord.WebSocket
|
||||
#endregion
|
||||
|
||||
#region Integrations
|
||||
public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null)
|
||||
public Task<IReadOnlyCollection<RestIntegration>> GetIntegrationsAsync(RequestOptions options = null)
|
||||
=> GuildHelper.GetIntegrationsAsync(this, Discord, options);
|
||||
public Task<RestGuildIntegration> CreateIntegrationAsync(ulong id, string type, RequestOptions options = null)
|
||||
=> GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options);
|
||||
public Task DeleteIntegrationAsync(ulong id, RequestOptions options = null)
|
||||
=> GuildHelper.DeleteIntegrationAsync(this, Discord, id, options);
|
||||
#endregion
|
||||
|
||||
#region Interactions
|
||||
@@ -1888,11 +1888,11 @@ namespace Discord.WebSocket
|
||||
=> await GetVoiceRegionsAsync(options).ConfigureAwait(false);
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options)
|
||||
async Task<IReadOnlyCollection<IIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options)
|
||||
=> await GetIntegrationsAsync(options).ConfigureAwait(false);
|
||||
/// <inheritdoc />
|
||||
async Task<IGuildIntegration> IGuild.CreateIntegrationAsync(ulong id, string type, RequestOptions options)
|
||||
=> await CreateIntegrationAsync(id, type, options).ConfigureAwait(false);
|
||||
async Task IGuild.DeleteIntegrationAsync(ulong id, RequestOptions options)
|
||||
=> await DeleteIntegrationAsync(id, options).ConfigureAwait(false);
|
||||
|
||||
/// <inheritdoc />
|
||||
async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync(RequestOptions options)
|
||||
|
||||
Reference in New Issue
Block a user