This commit is contained in:
Kwoth
2016-08-24 15:39:37 +02:00
parent 576690dc81
commit cb7fb76b91
6 changed files with 6 additions and 112 deletions

View File

@@ -18,14 +18,10 @@ namespace NadekoBot.Modules.Searches
[RequireContext(ContextType.Guild)]
public static async Task Calculate(IMessage msg, [Remainder] string expression)
{
try
{
var expr = new NCalc.Expression(expression, NCalc.EvaluateOptions.IgnoreCase);
expr.EvaluateParameter += Expr_EvaluateParameter;
expr.EvaluateFunction += Expr_EvaluateFunction;
var result = expr.Evaluate();
await msg.Reply(string.Format("Your expression evaluated to: {0}", expr.Error ?? result));
}
@@ -33,16 +29,6 @@ namespace NadekoBot.Modules.Searches
{
await msg.Reply($"Your expression failed to evaluate: {e.Message} ");
}
}
private static void Expr_EvaluateFunction(string name, NCalc.FunctionArgs args)
{
switch (name.ToLowerInvariant())
{
}
}
private static void Expr_EvaluateParameter(string name, NCalc.ParameterArgs args)
@@ -51,15 +37,13 @@ namespace NadekoBot.Modules.Searches
case "pi": args.Result= Math.PI;
break;
case "e": args.Result = Math.E;
break;
break;
}
}
[Command("calcOperations")]
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
[RequireContext(ContextType.Guild)]
public async Task calcOperations(IMessage msg)
public async Task CalcOperations(IMessage msg)
{
StringBuilder builder = new StringBuilder();
var selection = typeof(Math).GetTypeInfo().GetMethods().Except(typeof(object).GetTypeInfo().GetMethods()).Select(x =>
@@ -69,7 +53,6 @@ namespace NadekoBot.Modules.Searches
{
name += " (" + string.Join(", ", x.GetParameters().Select(y => y.IsOptional ? $"[{y.ParameterType.Name + " " + y.Name }]" : y.ParameterType.Name + " " + y.Name)) + ")";
}
return name;
});
foreach (var method in selection) builder.AppendLine(method);

View File

@@ -1,86 +0,0 @@
//using Discord.Commands;
//using Mathos.Parser;
//using NadekoBot.Classes;
//using System;
//using System.Text.RegularExpressions;
//using System.Threading.Tasks;
//todo mathos parser replacement
//namespace NadekoBot.Modules.Searches
//{
// class CalcCommand : DiscordCommand
// {
// public CalcCommand(DiscordModule module) : base(module)
// {
// }
// internal override void Init(CommandGroupBuilder cgb)
// {
// cgb.CreateCommand(Module.Prefix + "calculate")
// .Alias(Module.Prefix + "calc")
// .Description($"Evaluate a mathematical expression. | `{Prefix}calc 1+1`")
// .Parameter("expression", ParameterType.Unparsed)
// .Do(EvalFunc());
// }
// private CustomParser parser = new CustomParser();
// private Func<CommandEventArgs, Task> EvalFunc() => async e =>
// {
// string expression = expression?.Trim();
// if (string.IsNullOrWhiteSpace(expression))
// {
// return;
// }
// string answer = Evaluate(expression);
// if (answer == null)
// {
// await channel.SendMessageAsync($"Expression {expression} failed to evaluate");
// return;
// }
// await channel.SendMessageAsync($"⚙ `{answer}`");
// };
// private string Evaluate(string expression)
// {
// //check for factorial
// expression = Regex.Replace(expression, @"\d+!", x => x.Value + "0");
// try
// {
// string result = parser.Parse(expression).ToString();
// return result;
// }
// catch (OverflowException)
// {
// return $"Overflow error on {expression}";
// }
// catch (FormatException)
// {
// return $"\"{expression}\" was not formatted correctly";
// }
// }
// class CustomParser : MathParser
// {
// public CustomParser() : base()
// {
// OperatorList.Add("!");
// OperatorAction.Add("!", (x, y) => Factorial(x));
// }
// static decimal Factorial(decimal x)
// {
// decimal y = x - 1;
// while (y > 0)
// {
// x = x * y--;
// }
// return x;
// }
// }
// }
//}