fix: Gateway events for DMs (#1854)

* Fix MessageUpdate when there's no channel cached

* Fix message events

* Fix cacheable type

* Fix examples

* Revert MessageUpdated
This commit is contained in:
Paulo
2021-05-28 10:09:05 -03:00
committed by GitHub
parent dfaaa21e0e
commit a7ff6ce0ec
5 changed files with 261 additions and 225 deletions

View File

@@ -15,7 +15,7 @@ namespace Discord.Net.Examples.WebSocket
=> client.ReactionAdded += HandleReactionAddedAsync;
public async Task HandleReactionAddedAsync(Cacheable<IUserMessage, ulong> cachedMessage,
ISocketMessageChannel originChannel, SocketReaction reaction)
Cacheable<IMessageChannel, ulong> originChannel, SocketReaction reaction)
{
var message = await cachedMessage.GetOrDownloadAsync();
if (message != null && reaction.User.IsSpecified)
@@ -100,16 +100,17 @@ namespace Discord.Net.Examples.WebSocket
public void HookMessageDeleted(BaseSocketClient client)
=> client.MessageDeleted += HandleMessageDelete;
public Task HandleMessageDelete(Cacheable<IMessage, ulong> cachedMessage, ISocketMessageChannel channel)
public async Task HandleMessageDelete(Cacheable<IMessage, ulong> cachedMessage, Cacheable<IMessageChannel, ulong> cachedChannel)
{
// check if the message exists in cache; if not, we cannot report what was removed
if (!cachedMessage.HasValue) return Task.CompletedTask;
if (!cachedMessage.HasValue) return;
// gets or downloads the channel if it's not in the cache
IMessageChannel channel = await cachedChannel.GetOrDownloadAsync();
var message = cachedMessage.Value;
Console.WriteLine(
$"A message ({message.Id}) from {message.Author} was removed from the channel {channel.Name} ({channel.Id}):"
+ Environment.NewLine
+ message.Content);
return Task.CompletedTask;
}
#endregion