Merge pull request #959 from 13xforever/vnext

Maintenance
This commit is contained in:
Haxy 2024-06-26 23:22:29 +01:00 committed by GitHub
commit 4067e294a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 5 deletions

View File

@ -6,7 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.0" />
<PackageReference Include="Octokit" Version="12.0.0" />
<PackageReference Include="Octokit" Version="13.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CompatApiClient\CompatApiClient.csproj" />

View File

@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using CompatBot.Commands.Attributes;
using DSharpPlus.CommandsNext;
@ -12,6 +13,11 @@ namespace CompatBot.Commands;
[Description("Math, here you go Juhn. Use `math help` for syntax help")]
internal sealed class BotMath : BaseCommandModuleCustom
{
static BotMath()
{
License.iConfirmNonCommercialUse("RPCS3");
}
[GroupCommand, Priority(9)]
public async Task Expression(CommandContext ctx, [RemainingText, Description("Math expression")] string expression)
{
@ -35,8 +41,23 @@ internal sealed class BotMath : BaseCommandModuleCustom
""";
try
{
mXparser.resetCancelCurrentCalculationFlag();
var expr = new Expression(expression);
result = expr.calculate().ToString(CultureInfo.InvariantCulture);
const int timeout = 1_000;
var cts = new CancellationTokenSource(timeout);
// ReSharper disable once MethodSupportsCancellation
var delayTask = Task.Delay(timeout);
var calcTask = Task.Run(() => expr.calculate().ToString(CultureInfo.InvariantCulture), cts.Token);
await Task.WhenAny(calcTask, delayTask).ConfigureAwait(false);
if (calcTask.IsCompletedSuccessfully)
{
result = await calcTask;
}
else
{
mXparser.cancelCurrentCalculation();
result = "Calculation took too much time and all operations were cancelled";
}
}
catch (Exception e)
{

View File

@ -326,7 +326,8 @@ internal sealed partial class Warnings: BaseCommandModuleCustom
table.Add(warning.Id.ToString(), "+", issuerName, timestamp, warning.Reason, warning.FullReason);
}
}
var result = new StringBuilder("Warning list for ").Append(userName);
var result = new StringBuilder("Warning list for ").Append(Formatter.Sanitize(userName));
if (!isPrivate && !isWhitelisted && count > maxWarningsInPublicChannel)
result.Append($" (last {showCount} of {count}, full list in DMs)");
result.AppendLine(":").Append(table);

View File

@ -1032,13 +1032,14 @@ internal static partial class LogParserResult
13 => "macOS High Sierra",
14 => "macOS Mojave",
15 => "macOS Catalina",
_ => null,
_ => "Unknown Apple OS",
},
11 => "macOS Big Sur",
12 => "macOS Monterey",
13 => "macOS Ventura",
14 => "macOS Sonoma",
_ => null,
15 => "macOS Sequoia",
_ => "Unknown Apple OS",
};
internal static bool IsAmd(string gpuInfo)