Restructured the project structure back to the way it was, there's no reasonable way to split the modules

This commit is contained in:
Kwoth
2024-04-26 22:26:24 +00:00
parent 6c9c8bf63e
commit e0819f760c
768 changed files with 192 additions and 1047 deletions

View File

@@ -0,0 +1,48 @@
#nullable disable
using NCalc;
using System.Reflection;
namespace NadekoBot.Modules.Utility;
public partial class Utility
{
[Group]
public partial class CalcCommands : NadekoModule
{
[Cmd]
public async Task Calculate([Leftover] string expression)
{
var expr = new Expression(expression, EvaluateOptions.IgnoreCase | EvaluateOptions.NoCache);
expr.EvaluateParameter += Expr_EvaluateParameter;
var result = expr.Evaluate();
if (!expr.HasErrors())
await SendConfirmAsync("⚙ " + GetText(strs.result), result.ToString());
else
await SendErrorAsync("⚙ " + GetText(strs.error), expr.Error);
}
private static void Expr_EvaluateParameter(string name, ParameterArgs args)
{
switch (name.ToLowerInvariant())
{
case "pi":
args.Result = Math.PI;
break;
case "e":
args.Result = Math.E;
break;
}
}
[Cmd]
public async Task CalcOps()
{
var selection = typeof(Math).GetTypeInfo()
.GetMethods()
.DistinctBy(x => x.Name)
.Select(x => x.Name)
.Except(new[] { "ToString", "Equals", "GetHashCode", "GetType" });
await SendConfirmAsync(GetText(strs.calcops(prefix)), string.Join(", ", selection));
}
}
}