Some logging fix
This commit is contained in:
parent
8c8aad8ae2
commit
c39d65dffd
66
src/NadekoBot/Services/Discord/SocketMessageEventWrapper.cs
Normal file
66
src/NadekoBot/Services/Discord/SocketMessageEventWrapper.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using Discord;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Discord
|
||||||
|
{
|
||||||
|
public class ReactionEventWrapper : IDisposable
|
||||||
|
{
|
||||||
|
public SocketMessage Message { get; }
|
||||||
|
public event Action<SocketReaction> OnReactionAdded = delegate { };
|
||||||
|
public event Action<SocketReaction> OnReactionRemoved = delegate { };
|
||||||
|
public event Action OnReactionsCleared = delegate { };
|
||||||
|
|
||||||
|
public ReactionEventWrapper(SocketMessage msg)
|
||||||
|
{
|
||||||
|
if (msg == null)
|
||||||
|
throw new ArgumentNullException(nameof(msg));
|
||||||
|
Message = msg;
|
||||||
|
|
||||||
|
msg.Discord.ReactionAdded += Discord_ReactionAdded;
|
||||||
|
msg.Discord.ReactionRemoved += Discord_ReactionRemoved;
|
||||||
|
msg.Discord.ReactionsCleared += Discord_ReactionsCleared;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task Discord_ReactionsCleared(ulong messageId, Optional<SocketUserMessage> reaction)
|
||||||
|
{
|
||||||
|
if (messageId == Message.Id)
|
||||||
|
OnReactionsCleared?.Invoke();
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task Discord_ReactionRemoved(ulong messageId, Optional<SocketUserMessage> arg2, SocketReaction reaction)
|
||||||
|
{
|
||||||
|
if (messageId == Message.Id)
|
||||||
|
OnReactionRemoved?.Invoke(reaction);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task Discord_ReactionAdded(ulong messageId, Optional<SocketUserMessage> message, SocketReaction reaction)
|
||||||
|
{
|
||||||
|
if(messageId == Message.Id)
|
||||||
|
OnReactionAdded?.Invoke(reaction);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UnsubAll()
|
||||||
|
{
|
||||||
|
Message.Discord.ReactionAdded -= Discord_ReactionAdded;
|
||||||
|
Message.Discord.ReactionRemoved -= Discord_ReactionRemoved;
|
||||||
|
Message.Discord.ReactionsCleared -= Discord_ReactionsCleared;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool disposing = false;
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
return;
|
||||||
|
disposing = true;
|
||||||
|
UnsubAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -65,7 +65,9 @@ namespace NadekoBot
|
|||||||
client.ChannelUpdated += (arg1, arg2) => { ChannelUpdated(arg1, arg2); return Task.CompletedTask; };
|
client.ChannelUpdated += (arg1, arg2) => { ChannelUpdated(arg1, arg2); return Task.CompletedTask; };
|
||||||
|
|
||||||
_log.Info($"Shard #{i} initialized.");
|
_log.Info($"Shard #{i} initialized.");
|
||||||
|
#if GLOBAL_NADEKO
|
||||||
client.Log += Client_Log;
|
client.Log += Client_Log;
|
||||||
|
#endif
|
||||||
var j = i;
|
var j = i;
|
||||||
client.Disconnected += (ex) =>
|
client.Disconnected += (ex) =>
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user