feature: Add INVITE_CREATE and INVITE_DELETE events (#1491)
* Add invite events (create and delete) * Removed unused using * Fixing IInviteMetadata properties * Add two new fields to the gateway event * Better event summary and remarks * Change how to assign to target variable Co-Authored-By: Joe4evr <jii.geugten@gmail.com> * Applying suggested changes to TargetUserType * Renaming NotDefined to Undefined * Fixing xml docs * Changed the summary style format Co-authored-by: Joe4evr <jii.geugten@gmail.com>
This commit is contained in:
@@ -1688,6 +1688,64 @@ namespace Discord.WebSocket
|
||||
}
|
||||
break;
|
||||
|
||||
//Invites
|
||||
case "INVITE_CREATE":
|
||||
{
|
||||
await _gatewayLogger.DebugAsync("Received Dispatch (INVITE_CREATE)").ConfigureAwait(false);
|
||||
|
||||
var data = (payload as JToken).ToObject<API.Gateway.InviteCreateEvent>(_serializer);
|
||||
if (State.GetChannel(data.ChannelId) is SocketGuildChannel channel)
|
||||
{
|
||||
var guild = channel.Guild;
|
||||
if (!guild.IsSynced)
|
||||
{
|
||||
await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
SocketGuildUser inviter = data.Inviter.IsSpecified
|
||||
? (guild.GetUser(data.Inviter.Value.Id) ?? guild.AddOrUpdateUser(data.Inviter.Value))
|
||||
: null;
|
||||
|
||||
SocketUser target = data.TargetUser.IsSpecified
|
||||
? (guild.GetUser(data.TargetUser.Value.Id) ?? (SocketUser)SocketUnknownUser.Create(this, State, data.TargetUser.Value))
|
||||
: null;
|
||||
|
||||
var invite = SocketInvite.Create(this, guild, channel, inviter, target, data);
|
||||
|
||||
await TimedInvokeAsync(_inviteCreatedEvent, nameof(InviteCreated), invite).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "INVITE_DELETE":
|
||||
{
|
||||
await _gatewayLogger.DebugAsync("Received Dispatch (INVITE_DELETE)").ConfigureAwait(false);
|
||||
|
||||
var data = (payload as JToken).ToObject<API.Gateway.InviteDeleteEvent>(_serializer);
|
||||
if (State.GetChannel(data.ChannelId) is SocketGuildChannel channel)
|
||||
{
|
||||
var guild = channel.Guild;
|
||||
if (!guild.IsSynced)
|
||||
{
|
||||
await UnsyncedGuildAsync(type, guild.Id).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await TimedInvokeAsync(_inviteDeletedEvent, nameof(InviteDeleted), channel, data.Code).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
//Ignored (User only)
|
||||
case "CHANNEL_PINS_ACK":
|
||||
await _gatewayLogger.DebugAsync("Ignored Dispatch (CHANNEL_PINS_ACK)").ConfigureAwait(false);
|
||||
|
||||
Reference in New Issue
Block a user