NadekoBot/NadekoBot.Core/Common/ShardCom/ShardComServer.cs

32 lines
830 B
C#
Raw Normal View History

2017-07-17 19:42:36 +00:00
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
2017-07-17 19:42:36 +00:00
using Newtonsoft.Json;
2017-10-09 22:04:02 +00:00
using NadekoBot.Services;
2017-07-17 19:42:36 +00:00
namespace NadekoBot.Common.ShardCom
{
2017-10-09 22:04:02 +00:00
public class ShardComServer
{
2017-10-09 22:04:02 +00:00
private readonly IDataCache _cache;
2017-10-09 22:04:02 +00:00
public ShardComServer(IDataCache cache)
{
2017-10-09 22:04:02 +00:00
_cache = cache;
}
public void Start()
{
2017-10-09 22:04:02 +00:00
var sub = _cache.Redis.GetSubscriber();
sub.SubscribeAsync("shardcoord_send", (ch, data) =>
{
2017-10-09 22:04:02 +00:00
var _ = OnDataReceived(JsonConvert.DeserializeObject<ShardComMessage>(data));
}, StackExchange.Redis.CommandFlags.FireAndForget);
}
public event Func<ShardComMessage, Task> OnDataReceived = delegate { return Task.CompletedTask; };
}
}