Fixed multi-shard bots

This commit is contained in:
Master Kwoth 2017-07-19 09:31:00 +02:00
parent 661d026973
commit 50236d71d5
3 changed files with 7 additions and 8 deletions

View File

@ -30,12 +30,12 @@ namespace NadekoBot.Modules.Utility
private readonly IBotCredentials _creds; private readonly IBotCredentials _creds;
private readonly ShardsCoordinator _shardCoord; private readonly ShardsCoordinator _shardCoord;
public Utility(ShardsCoordinator shardCoord, DiscordSocketClient client, IStatsService stats, IBotCredentials creds) public Utility(NadekoBot nadeko, DiscordSocketClient client, IStatsService stats, IBotCredentials creds)
{ {
_client = client; _client = client;
_stats = stats; _stats = stats;
_creds = creds; _creds = creds;
_shardCoord = shardCoord; _shardCoord = nadeko.ShardCoord;
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -137,7 +137,6 @@ namespace NadekoBot
.AddManual<IEnumerable<GuildConfig>>(AllGuildConfigs) //todo wrap this .AddManual<IEnumerable<GuildConfig>>(AllGuildConfigs) //todo wrap this
.AddManual<NadekoBot>(this) .AddManual<NadekoBot>(this)
.AddManual<IUnitOfWork>(uow) .AddManual<IUnitOfWork>(uow)
.AddManual(ShardCoord)
.LoadFrom(Assembly.GetEntryAssembly()) .LoadFrom(Assembly.GetEntryAssembly())
.Build(); .Build();

View File

@ -44,11 +44,11 @@ namespace NadekoBot.Services.Impl
public int GuildCount => public int GuildCount =>
_sc?.GuildCount ?? _client.Guilds.Count(); _sc?.GuildCount ?? _client.Guilds.Count();
public StatsService(DiscordSocketClient client, CommandHandler cmdHandler, IBotCredentials creds, ShardsCoordinator sc) public StatsService(DiscordSocketClient client, CommandHandler cmdHandler, IBotCredentials creds, NadekoBot nadeko)
{ {
_client = client; _client = client;
_creds = creds; _creds = creds;
_sc = sc; _sc = nadeko.ShardCoord;
_started = DateTime.UtcNow; _started = DateTime.UtcNow;
_client.MessageReceived += _ => Task.FromResult(Interlocked.Increment(ref _messageCounter)); _client.MessageReceived += _ => Task.FromResult(Interlocked.Increment(ref _messageCounter));
@ -130,7 +130,7 @@ namespace NadekoBot.Services.Impl
return Task.CompletedTask; return Task.CompletedTask;
}; };
if (sc != null) if (_sc != null)
{ {
_carbonitexTimer = new Timer(async (state) => _carbonitexTimer = new Timer(async (state) =>
{ {
@ -142,7 +142,7 @@ namespace NadekoBot.Services.Impl
{ {
using (var content = new FormUrlEncodedContent( using (var content = new FormUrlEncodedContent(
new Dictionary<string, string> { new Dictionary<string, string> {
{ "servercount", sc.GuildCount.ToString() }, { "servercount", _sc.GuildCount.ToString() },
{ "key", _creds.CarbonKey }})) { "key", _creds.CarbonKey }}))
{ {
content.Headers.Clear(); content.Headers.Clear();
@ -175,7 +175,7 @@ namespace NadekoBot.Services.Impl
using (var content = new FormUrlEncodedContent( using (var content = new FormUrlEncodedContent(
new Dictionary<string, string> { new Dictionary<string, string> {
{ "id", string.Concat(MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(_creds.ClientId.ToString())).Select(x => x.ToString("X2"))) }, { "id", string.Concat(MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(_creds.ClientId.ToString())).Select(x => x.ToString("X2"))) },
{ "guildCount", sc.GuildCount.ToString() }, { "guildCount", _sc.GuildCount.ToString() },
{ "version", BotVersion }, { "version", BotVersion },
{ "platform", platform }})) { "platform", platform }}))
{ {