Support "MESSAGE_REACTION_REMOVE_ALL" dispatch
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Discord.API.Gateway
|
||||
{
|
||||
public class RemoveAllReactionsEvent
|
||||
{
|
||||
[JsonProperty("channel_id")]
|
||||
public ulong ChannelId { get; set; }
|
||||
[JsonProperty("message_id")]
|
||||
public ulong MessageId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,12 @@ namespace Discord.WebSocket
|
||||
remove { _reactionRemovedEvent.Remove(value); }
|
||||
}
|
||||
private readonly AsyncEvent<Func<ulong, Optional<SocketUserMessage>, SocketReaction, Task>> _reactionRemovedEvent = new AsyncEvent<Func<ulong, Optional<SocketUserMessage>, SocketReaction, Task>>();
|
||||
public event Func<ulong, Optional<SocketUserMessage>, Task> ReactionsCleared
|
||||
{
|
||||
add { _reactionsClearedEvent.Add(value); }
|
||||
remove { _reactionsClearedEvent.Remove(value); }
|
||||
}
|
||||
private readonly AsyncEvent<Func<ulong, Optional<SocketUserMessage>, Task>> _reactionsClearedEvent = new AsyncEvent<Func<ulong, Optional<SocketUserMessage>, Task>>();
|
||||
|
||||
//Roles
|
||||
public event Func<SocketRole, Task> RoleCreated
|
||||
|
||||
@@ -1306,7 +1306,7 @@ namespace Discord.WebSocket
|
||||
break;
|
||||
case "MESSAGE_REACTION_ADD":
|
||||
{
|
||||
await _gatewayLogger.DebugAsync("Received Disbatch (MESSAGE_REACTION_ADD)").ConfigureAwait(false);
|
||||
await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_REACTION_ADD)").ConfigureAwait(false);
|
||||
|
||||
var data = (payload as JToken).ToObject<GatewayReaction>(_serializer);
|
||||
var channel = State.GetChannel(data.ChannelId) as ISocketMessageChannel;
|
||||
@@ -1333,7 +1333,7 @@ namespace Discord.WebSocket
|
||||
}
|
||||
case "MESSAGE_REACTION_REMOVE":
|
||||
{
|
||||
await _gatewayLogger.DebugAsync("Received Disbatch (MESSAGE_REACTION_REMOVE)").ConfigureAwait(false);
|
||||
await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_REACTION_REMOVE)").ConfigureAwait(false);
|
||||
|
||||
var data = (payload as JToken).ToObject<GatewayReaction>(_serializer);
|
||||
var channel = State.GetChannel(data.ChannelId) as ISocketMessageChannel;
|
||||
@@ -1355,6 +1355,31 @@ namespace Discord.WebSocket
|
||||
await _gatewayLogger.WarningAsync("MESSAGE_REACTION_REMOVE referenced an unknown channel.").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "MESSAGE_REACTION_REMOVE_ALL":
|
||||
{
|
||||
await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_REACTION_REMOVE_ALL)").ConfigureAwait(false);
|
||||
|
||||
var data = (payload as JToken).ToObject<RemoveAllReactionsEvent>(_serializer);
|
||||
var channel = State.GetChannel(data.ChannelId) as ISocketMessageChannel;
|
||||
if (channel != null)
|
||||
{
|
||||
SocketUserMessage cachedMsg = channel.GetCachedMessage(data.MessageId) as SocketUserMessage;
|
||||
if (cachedMsg != null)
|
||||
{
|
||||
cachedMsg.ClearReactions();
|
||||
await _reactionsClearedEvent.InvokeAsync(data.MessageId, cachedMsg).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
await _reactionsClearedEvent.InvokeAsync(data.MessageId, Optional.Create<SocketUserMessage>());
|
||||
}
|
||||
else
|
||||
{
|
||||
await _gatewayLogger.WarningAsync("MESSAGE_REACTION_REMOVE_ALL referenced an unknown channel.").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "MESSAGE_DELETE_BULK":
|
||||
|
||||
@@ -122,6 +122,10 @@ namespace Discord.WebSocket
|
||||
if (_reactions.Contains(reaction))
|
||||
_reactions.Remove(reaction);
|
||||
}
|
||||
internal void ClearReactions()
|
||||
{
|
||||
_reactions.Clear();
|
||||
}
|
||||
|
||||
public Task ModifyAsync(Action<ModifyMessageParams> func, RequestOptions options = null)
|
||||
=> MessageHelper.ModifyAsync(this, Discord, func, options);
|
||||
|
||||
Reference in New Issue
Block a user