fix some misc stuff and add more diagnostics

This commit is contained in:
13xforever
2025-03-26 09:33:29 +05:00
parent ff37ba74aa
commit ae75774d79
4 changed files with 13 additions and 5 deletions

View File

@@ -22,8 +22,10 @@ internal static class BotStatus
}
.AddField("Current Uptime", Config.Uptime.Elapsed.AsShortTimespan(), true)
.AddField("Discord Latency", $"{latency.TotalMilliseconds:0.0} ms", true);
if (!string.IsNullOrEmpty(Config.AzureComputerVisionKey))
if (Config.AzureComputerVisionKey is {Length: >0})
embed.AddField("Max OCR Queue", MediaScreenshotMonitor.MaxQueueLength.ToString(), true);
else
embed.AddField("Max OCR Queue", "-", true);
var osInfo = RuntimeInformation.OSDescription;
if (Environment.OSVersion.Platform is PlatformID.Unix or PlatformID.MacOSX)
osInfo = RuntimeInformation.RuntimeIdentifier;

View File

@@ -66,6 +66,7 @@ internal static class Explain
memStream.Seek(0, SeekOrigin.Begin);
explainMsg.AddFile(result.explanation.AttachmentFilename!, memStream);
await ctx.RespondAsync(explainMsg).ConfigureAwait(false);
StatsStorage.IncExplainStat(term);
}
[Command("add"), RequiresBotModRole]

View File

@@ -21,7 +21,7 @@ internal static class MemoryCacheExtensions
var coherentState = stateField?.GetValue(memoryCache);
if (coherentState is null)
{
Config.Log.Error($"Looks like {nameof(MemoryCache)} internals have changed");
Config.Log.Error($"Looks like {nameof(MemoryCache)} internals have changed in {nameof(coherentState)}");
return [];
}
@@ -34,7 +34,7 @@ internal static class MemoryCacheExtensions
.FirstOrDefault(fi => fi.Name == "_nonStringEntries");
if (stringField is null || nonStringField is null)
{
Config.Log.Error($"Looks like {nameof(MemoryCache)} internals have changed");
Config.Log.Error($"Looks like {nameof(MemoryCache)} internals have changed in {nameof(stringField)}");
return [];
}
@@ -54,7 +54,7 @@ internal static class MemoryCacheExtensions
var coherentState = stateField?.GetValue(memoryCache);
if (coherentState is null)
{
Config.Log.Error($"Looks like {nameof(MemoryCache)} internals have changed");
Config.Log.Error($"Looks like {nameof(MemoryCache)} internals have changed in {nameof(coherentState)}");
return new();
}
@@ -64,7 +64,7 @@ internal static class MemoryCacheExtensions
var cacheEntries = (IDictionary?)field?.GetValue(coherentState);
if (cacheEntries is null)
{
Config.Log.Error($"Looks like {nameof(MemoryCache)} internals have changed");
Config.Log.Error($"Looks like {nameof(MemoryCache)} internals have changed in {cacheEntries}");
return new(0);
}

View File

@@ -16,10 +16,13 @@ public class MemoryCacheExtensionTests
const string testVal = "vale13";
cache.Set(13, testVal);
cache.Set("bob", 69);
Assert.Multiple(() =>
{
Assert.That(cache.TryGetValue(13, out string? expectedVal), Is.True);
Assert.That(expectedVal, Is.EqualTo(testVal));
Assert.That(cache.TryGetValue("bob", out int? expectedValInt), Is.True);
Assert.That(expectedValInt, Is.EqualTo(69));
}
);
Assert.That(cache.GetCacheKeys<int>(), Has.Count.EqualTo(1));
@@ -32,6 +35,8 @@ public class MemoryCacheExtensionTests
Assert.That(cache.GetCacheKeys<int>(), Is.Empty);
cache.Set(13, "val13");
cache.Set("bob", 69);
Assert.That(cache.GetCacheKeys<int>(), Has.Count.EqualTo(1));
Assert.That(cache.GetCacheKeys<string>(), Has.Count.EqualTo(1));
}
}