Some logging fix

This commit is contained in:
Kwoth 2017-01-07 00:00:55 +01:00
parent 8c8aad8ae2
commit c39d65dffd
2 changed files with 68 additions and 0 deletions

View 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();
}
}
}

View File

@ -65,7 +65,9 @@ namespace NadekoBot
client.ChannelUpdated += (arg1, arg2) => { ChannelUpdated(arg1, arg2); return Task.CompletedTask; };
_log.Info($"Shard #{i} initialized.");
#if GLOBAL_NADEKO
client.Log += Client_Log;
#endif
var j = i;
client.Disconnected += (ex) =>
{