Fix Periodic Methods

This commit is contained in:
Fennel 2020-04-24 17:47:35 -04:00 committed by Astrid
parent c41f2c7c9b
commit 2fd07c9ec9

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using System.Net.WebSockets;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using App.Metrics; using App.Metrics;
@ -162,7 +163,11 @@ namespace PluralKit.Bot
{ {
// Change bot status // Change bot status
var totalGuilds = _client.ShardClients.Values.Sum(c => c.Guilds.Count); var totalGuilds = _client.ShardClients.Values.Sum(c => c.Guilds.Count);
await _client.UpdateStatusAsync(new DiscordActivity($"pk;help | in {totalGuilds} servers")); try // DiscordClient may throw an exception if an update is attempted while reconnecting (e.g just after OP 7 received)
{
await _client.UpdateStatusAsync(new DiscordActivity($"pk;help | in {totalGuilds} servers"));
}
catch (WebSocketException) { }
// Run webhook rate limit GC every 10 minutes // Run webhook rate limit GC every 10 minutes
if (_periodicUpdateCount++ % 10 == 0) if (_periodicUpdateCount++ % 10 == 0)
@ -176,9 +181,9 @@ namespace PluralKit.Bot
await Task.WhenAll(((IMetricsRoot) _metrics).ReportRunner.RunAllAsync()); await Task.WhenAll(((IMetricsRoot) _metrics).ReportRunner.RunAllAsync());
} }
/*private Task ShardReady(DiscordSocketClient shardClient) private Task ShardReady(DiscordClient shardClient)
{ {
_logger.Information("Shard {Shard} connected to {ChannelCount} channels in {GuildCount} guilds", shardClient.ShardId, shardClient.Guilds.Sum(g => g.Channels.Count), shardClient.Guilds.Count); _logger.Information("Shard {Shard} connected to {ChannelCount} channels in {GuildCount} guilds", shardClient.ShardId, shardClient.Guilds.Sum(g => g.Value.Channels.Count), shardClient.Guilds.Count);
if (shardClient.ShardId == 0) if (shardClient.ShardId == 0)
{ {
@ -190,7 +195,7 @@ namespace PluralKit.Bot
} }
return Task.CompletedTask; return Task.CompletedTask;
}*/ }
private Task HandleEvent(Func<PKEventHandler, Task> handler) private Task HandleEvent(Func<PKEventHandler, Task> handler)
{ {