mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-10-16 07:59:57 +00:00
Add option to disable connection logging
Was previously disabled by default, now enabled by default.
This commit is contained in:
parent
b0b39bbd0b
commit
0944177897
2 changed files with 22 additions and 12 deletions
|
@ -38,6 +38,11 @@ class Configuration {
|
||||||
/// Amount of time to wait between background task runs within each shard.
|
/// Amount of time to wait between background task runs within each shard.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int BackgroundInterval { get; }
|
public int BackgroundInterval { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether to show common connect/disconnect events and other related messages.
|
||||||
|
/// This is disabled in the public instance, but it's worth keeping enabled in self-hosted bots.
|
||||||
|
/// </summary>
|
||||||
|
public bool LogConnectionStatus { get; }
|
||||||
|
|
||||||
public Configuration() {
|
public Configuration() {
|
||||||
var args = CommandLineParameters.Parse(Environment.GetCommandLineArgs());
|
var args = CommandLineParameters.Parse(Environment.GetCommandLineArgs());
|
||||||
|
@ -89,6 +94,7 @@ class Configuration {
|
||||||
StatusInterval = ReadConfKey<int?>(jc, nameof(StatusInterval), false) ?? 90;
|
StatusInterval = ReadConfKey<int?>(jc, nameof(StatusInterval), false) ?? 90;
|
||||||
MaxConcurrentOperations = ReadConfKey<int?>(jc, nameof(MaxConcurrentOperations), false) ?? 4;
|
MaxConcurrentOperations = ReadConfKey<int?>(jc, nameof(MaxConcurrentOperations), false) ?? 4;
|
||||||
BackgroundInterval = ReadConfKey<int?>(jc, nameof(BackgroundInterval), false) ?? 60;
|
BackgroundInterval = ReadConfKey<int?>(jc, nameof(BackgroundInterval), false) ?? 60;
|
||||||
|
LogConnectionStatus = ReadConfKey<bool?>(jc, nameof(LogConnectionStatus), false) ?? true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static T? ReadConfKey<T>(JObject jc, string key, [DoesNotReturnIf(true)] bool failOnEmpty) {
|
private static T? ReadConfKey<T>(JObject jc, string key, [DoesNotReturnIf(true)] bool failOnEmpty) {
|
||||||
|
|
|
@ -72,23 +72,27 @@ public sealed class ShardInstance : IDisposable {
|
||||||
private Task Client_Log(LogMessage arg) {
|
private Task Client_Log(LogMessage arg) {
|
||||||
// Suppress certain messages
|
// Suppress certain messages
|
||||||
if (arg.Message != null) {
|
if (arg.Message != null) {
|
||||||
switch (arg.Message) {
|
if (!_manager.Config.LogConnectionStatus) {
|
||||||
case "Connecting":
|
switch (arg.Message) {
|
||||||
case "Connected":
|
case "Connecting":
|
||||||
case "Ready":
|
case "Connected":
|
||||||
case "Disconnecting":
|
case "Ready":
|
||||||
case "Disconnected":
|
case "Disconnecting":
|
||||||
case "Resumed previous session":
|
case "Disconnected":
|
||||||
case "Failed to resume previous session":
|
case "Resumed previous session":
|
||||||
case "Serializer Error": // The exception associated with this log appears a lot as of v3.2-ish
|
case "Failed to resume previous session":
|
||||||
return Task.CompletedTask;
|
case "Serializer Error": // The exception associated with this log appears a lot as of v3.2-ish
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Log("Discord.Net", $"{arg.Severity}: {arg.Message}");
|
Log("Discord.Net", $"{arg.Severity}: {arg.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg.Exception != null) {
|
if (arg.Exception != null) {
|
||||||
if (arg.Exception is GatewayReconnectException
|
if (!_manager.Config.LogConnectionStatus) {
|
||||||
|| arg.Exception.Message == "WebSocket connection was closed") return Task.CompletedTask;
|
if (arg.Exception is GatewayReconnectException || arg.Exception.Message == "WebSocket connection was closed")
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
Log("Discord.Net exception", arg.Exception.ToString());
|
Log("Discord.Net exception", arg.Exception.ToString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue