more typos and log tags for images

This commit is contained in:
13xforever 2021-02-09 15:52:32 +05:00
parent 2c1b685ae8
commit 029ca500b6
3 changed files with 16 additions and 11 deletions

View File

@ -308,7 +308,9 @@ namespace CompatBot.Commands
.WithContent(description) .WithContent(description)
.WithFile(Path.GetFileNameWithoutExtension(imageUrl) + "_tagged.jpg", resultStream); .WithFile(Path.GetFileNameWithoutExtension(imageUrl) + "_tagged.jpg", resultStream);
var respondMsg = await ctx.RespondAsync(messageBuilder).ConfigureAwait(false); var respondMsg = await ctx.RespondAsync(messageBuilder).ConfigureAwait(false);
await ReactToTagsAsync(respondMsg, result.Objects.Select(o => o.ObjectProperty).Concat(result.Description.Tags)).ConfigureAwait(false); var tags = result.Objects.Select(o => o.ObjectProperty).Concat(result.Description.Tags).Distinct().ToList();
Config.Log.Info($"Tags for image {imageUrl}: {string.Join(", ", tags)}");
await ReactToTagsAsync(respondMsg, tags).ConfigureAwait(false);
} }
else else
{ {

View File

@ -60,7 +60,7 @@ namespace CompatBot.EventHandlers
try try
{ {
var headers = await t.ConfigureAwait(false); var headers = await t.ConfigureAwait(false);
workQueue.Enqueue((evt, new Guid(new Uri(headers.OperationLocation).Segments.Last()))); workQueue.Enqueue((evt, new(new Uri(headers.OperationLocation).Segments.Last())));
workSemaphore.Release(); workSemaphore.Release();
} }
catch (Exception ex) catch (Exception ex)
@ -75,7 +75,7 @@ namespace CompatBot.EventHandlers
if (string.IsNullOrEmpty(Config.AzureComputerVisionKey)) if (string.IsNullOrEmpty(Config.AzureComputerVisionKey))
return; return;
Guid? reEnqueId = null; Guid? reEnqueueId = null;
do do
{ {
await workSemaphore.WaitAsync(Config.Cts.Token).ConfigureAwait(false); await workSemaphore.WaitAsync(Config.Cts.Token).ConfigureAwait(false);
@ -86,10 +86,10 @@ namespace CompatBot.EventHandlers
if (!workQueue.TryDequeue(out var item)) if (!workQueue.TryDequeue(out var item))
continue; continue;
if (item.readOperationId == reEnqueId) if (item.readOperationId == reEnqueueId)
{ {
await Task.Delay(100).ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false);
reEnqueId = null; reEnqueueId = null;
if (Config.Cts.IsCancellationRequested) if (Config.Cts.IsCancellationRequested)
return; return;
} }
@ -103,13 +103,13 @@ namespace CompatBot.EventHandlers
{ {
var cnt = true; var cnt = true;
var prefix = $"[{item.evt.Message.Id % 100:00}]"; var prefix = $"[{item.evt.Message.Id % 100:00}]";
var ocrText = new StringBuilder($"OCR result of message <{item.evt.Message.JumpLink}>:").AppendLine(); var ocrTextBuf = new StringBuilder($"OCR result of message <{item.evt.Message.JumpLink}>:").AppendLine();
Config.Log.Debug($"{prefix} OCR result of message {item.evt.Message.JumpLink}:"); Config.Log.Debug($"{prefix} OCR result of message {item.evt.Message.JumpLink}:");
var duplicates = new HashSet<string>(); var duplicates = new HashSet<string>();
foreach (var r in result.AnalyzeResult.ReadResults) foreach (var r in result.AnalyzeResult.ReadResults)
foreach (var l in r.Lines) foreach (var l in r.Lines)
{ {
ocrText.AppendLine(l.Text.Sanitize()); ocrTextBuf.AppendLine(l.Text.Sanitize());
Config.Log.Debug($"{prefix} {l.Text}"); Config.Log.Debug($"{prefix} {l.Text}");
if (cnt if (cnt
&& await ContentFilter.FindTriggerAsync(FilterContext.Chat, l.Text).ConfigureAwait(false) is Piracystring hit && await ContentFilter.FindTriggerAsync(FilterContext.Chat, l.Text).ConfigureAwait(false) is Piracystring hit
@ -130,11 +130,14 @@ namespace CompatBot.EventHandlers
cnt &= !hit.Actions.HasFlag(FilterAction.RemoveContent) && !hit.Actions.HasFlag(FilterAction.IssueWarning); cnt &= !hit.Actions.HasFlag(FilterAction.RemoveContent) && !hit.Actions.HasFlag(FilterAction.IssueWarning);
} }
} }
if (!cnt) var ocrText = ocrTextBuf.ToString();
var hasVkDiagInfo = ocrText.Contains("Vulkan Diagnostics Tool v")
|| ocrText.Contains("VkDiag Version:");
if (!cnt || hasVkDiagInfo)
try try
{ {
var botSpamCh = await client.GetChannelAsync(Config.ThumbnailSpamId).ConfigureAwait(false); var botSpamCh = await client.GetChannelAsync(Config.ThumbnailSpamId).ConfigureAwait(false);
await botSpamCh.SendAutosplitMessageAsync(ocrText, blockStart: "", blockEnd: "").ConfigureAwait(false); await botSpamCh.SendAutosplitMessageAsync(ocrTextBuf, blockStart: "", blockEnd: "").ConfigureAwait(false);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -145,7 +148,7 @@ namespace CompatBot.EventHandlers
else if (result.Status == OperationStatusCodes.NotStarted || result.Status == OperationStatusCodes.Running) else if (result.Status == OperationStatusCodes.NotStarted || result.Status == OperationStatusCodes.Running)
{ {
workQueue.Enqueue(item); workQueue.Enqueue(item);
reEnqueId ??= item.readOperationId; reEnqueueId ??= item.readOperationId;
workSemaphore.Release(); workSemaphore.Release();
} }
} }

View File

@ -109,7 +109,7 @@ namespace CompatBot
tc.TrackMetric("time-since-last-incoming-message", TimeSinceLastIncomingMessage.ElapsedMilliseconds); tc.TrackMetric("time-since-last-incoming-message", TimeSinceLastIncomingMessage.ElapsedMilliseconds);
tc.TrackMetric("memory-gc-total", gcMemInfo.HeapSizeBytes); tc.TrackMetric("memory-gc-total", gcMemInfo.HeapSizeBytes);
tc.TrackMetric("memory-gc-load", gcMemInfo.MemoryLoadBytes); tc.TrackMetric("memory-gc-load", gcMemInfo.MemoryLoadBytes);
tc.TrackMetric("memory-gc-commited", gcMemInfo.TotalCommittedBytes); tc.TrackMetric("memory-gc-committed", gcMemInfo.TotalCommittedBytes);
tc.TrackMetric("memory-process-private", process.PrivateMemorySize64); tc.TrackMetric("memory-process-private", process.PrivateMemorySize64);
tc.TrackMetric("memory-process-ws", process.WorkingSet64); tc.TrackMetric("memory-process-ws", process.WorkingSet64);
tc.TrackMetric("github-limit-remaining", GithubClient.Client.RateLimitRemaining); tc.TrackMetric("github-limit-remaining", GithubClient.Client.RateLimitRemaining);