Merge pull request #1012 from 13xforever/vnext

Maintenance
This commit is contained in:
Ilya
2026-01-09 22:45:24 +05:00
committed by GitHub
10 changed files with 67 additions and 14 deletions

View File

@@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.1" />
<PackageReference Include="Octokit" Version="14.0.0" />
<PackageReference Include="SharpCompress" Version="0.42.1" />
<PackageReference Include="SharpCompress" Version="0.44.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CompatApiClient\CompatApiClient.csproj" />

View File

@@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LTRData.DiscUtils.OpticalDisk" Version="1.0.72" />
<PackageReference Include="LTRData.DiscUtils.OpticalDisk" Version="1.0.73" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageReference Include="System.IO.Hashing" Version="10.0.1" />
</ItemGroup>

View File

@@ -64,7 +64,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.1" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="19.225.1" />
<PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="19.225.2" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="Nerdbank.Streams" Version="2.13.16" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
@@ -72,7 +72,7 @@
<PackageReference Include="NLog.Extensions.Logging" Version="6.1.0" />
<PackageReference Include="NReco.Text.AhoCorasickDoubleArrayTrie" Version="1.1.1" />
<PackageReference Include="Result.Net" Version="1.7.0" />
<PackageReference Include="SharpCompress" Version="0.42.1" />
<PackageReference Include="SharpCompress" Version="0.44.0" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.7" />
<PackageReference Include="TesseractCSharp" Version="1.0.5" />
</ItemGroup>

View File

@@ -29,24 +29,34 @@ public static class AntiSpamMessageHandler
return false;
}
if (msg.Content is not { Length: >0 })
return true;
if (MessageCache.TryGetValue(author.Id, out var item)
&& item is (DiscordMessage { Content.Length: >0 } lastMessage, bool isWarned)
&& lastMessage.Content == msg.Content
&& item is (DiscordMessage lastMessage, bool isWarned)
&& SameContent(lastMessage, msg)
&& lastMessage.ChannelId != msg.ChannelId)
{
var removedSpam = false;
try
{
await msg.DeleteAsync("spam").ConfigureAwait(false);
removedSpam = true;
var newMsgContent = "<???>";
if (msg.Content is { Length: > 0 })
{
newMsgContent = msg.Content;
}
else if (msg is { Attachments.Count: > 0 })
{
foreach (var att in msg.Attachments)
newMsgContent += $"📎 {att.FileName}\n";
newMsgContent = newMsgContent.TrimEnd();
}
Config.Log.Debug($"""
Removed spam message from user {author.Username} ({author.Id}) in #{msg.Channel?.Name}:
{msg.Content.Trim()}
{newMsgContent.Trim()}
"""
);
removedSpam = true;
}
catch (Exception e)
{
@@ -71,4 +81,19 @@ public static class AntiSpamMessageHandler
MessageCache.Set(author.Id, (msg, false), DefaultExpiration);
return true;
}
private static bool SameContent(DiscordMessage msg1, DiscordMessage msg2)
{
if (msg1 is { Content.Length: > 0 }
&& msg2 is { Content.Length: > 0 }
&& msg1.Content == msg2.Content)
return true;
if (msg1 is { Attachments.Count: > 0 }
&& msg2 is { Attachments.Count: > 0 }
&& msg1.Attachments.SequenceEqual(msg2.Attachments, DiscordAttachmentComparer.Instance))
return true;
return false;
}
}

View File

@@ -184,6 +184,7 @@ internal partial class LogParser
["SYS: Title was set from"] = TitleWasSet(),
["SYS: Path:"] = DigitalPathSys(),
["SYS: Boot path:"] = BootPathInBodySys(),
["SYS: Disc:"] = DiscMountSys(),
["Elf path:"] = ElfPath(),
["VFS: Mounted path \"/dev_bdvd\""] = VfsMountPath(),
["Invalid or unsupported file format:"] = InvalidFileFormat(),

View File

@@ -248,6 +248,8 @@ internal partial class LogParser
private static partial Regex DigitalPathSys();
[GeneratedRegex(@"Boot path: (?<ldr_boot_path_full>.*(?<ldr_boot_path>/dev_hdd0/game/(?<ldr_boot_path_serial>[^/\r\n]+)).*|[^\r\n]*)\r?$", DefaultOptions)]
private static partial Regex BootPathInBodySys();
[GeneratedRegex(@"SYS: Disc: /(?<vfs_disc_mount>\w+)/\r?$", DefaultOptions)]
private static partial Regex DiscMountSys();
[GeneratedRegex(@"Elf path: (?<host_root_in_boot>/host_root/)?(?<elf_boot_path_full>(?<elf_boot_path>/dev_hdd0/game/(?<elf_boot_path_serial>[^/\r\n]+)/USRDIR/EBOOT\.BIN|.*?))\r?$", DefaultOptions)]
private static partial Regex ElfPath();
[GeneratedRegex(@"Mounted path ""/dev_bdvd"" to ""(?<mounted_dev_bdvd>[^""]+)""", DefaultOptions)]

View File

@@ -0,0 +1,20 @@
namespace CompatBot.Utils;
internal class DiscordAttachmentComparer : IEqualityComparer<DiscordAttachment>
{
bool IEqualityComparer<DiscordAttachment>.Equals(DiscordAttachment? x, DiscordAttachment? y)
{
if (x is null && y is null)
return true;
if (x is null || y is null)
return false;
return x.FileName == y.FileName && x.FileSize == y.FileSize;
}
int IEqualityComparer<DiscordAttachment>.GetHashCode(DiscordAttachment obj)
=> HashCode.Combine((obj.FileName ?? "").GetHashCode(), obj.FileSize.GetHashCode());
public static DiscordAttachmentComparer Instance { get; } = new DiscordAttachmentComparer();
}

View File

@@ -256,7 +256,7 @@ public static class DiscordClientExtensions
Title = infraction,
Color = GetColor(severity),
}.AddField("Violator", author is null ? message.Author.Mention : GetMentionWithNickname(author), true)
.AddField("Channel", message.Channel.IsPrivate ? "Bot's DM" : message.Channel.Mention, true);
.AddField("Channel", message.Channel.IsPrivate ? "Bot's DM" : message.JumpLink.ToString(), true);
if (filterId is not null)
result.AddField("Filter #", filterId.ToString(), true);
result.AddField("Content of the offending item", content.Trim(EmbedPager.MaxFieldLength));

View File

@@ -116,7 +116,12 @@ internal static partial class LogParserResult
notes.Add("❌ Disc version of the game inside the `/dev_hdd0/game/` directory");
if (serial is {Length: >0} && isElf)
notes.Add($"⚠️ Retail game booted directly through `{Path.GetFileName(elfBootPath)}`, which is not recommended");
if (items["mounted_dev_bdvd"] is { Length: > 0 } mountedBdvd
if (items["vfs_disc_mount"] is "vfsv0_virtual_iso_overlay_fs_dev")
{
notes.Add(" Booted from ISO");
}
else if (items["mounted_dev_bdvd"] is { Length: > 0 } mountedBdvd
&& items["os_type"] is {Length: >0} osType
&& mountedBdvd.Split('/', StringSplitOptions.RemoveEmptyEntries) is {Length: <3} segments
&& (osType is "Windows" && segments is [[_, ':']] // D:/

View File

@@ -10,7 +10,7 @@
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.0.1">
<PackageReference Include="NUnit3TestAdapter" Version="6.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>