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)] [RequireContext(ContextType.Guild)]
public static async Task Calculate(IMessage msg, [Remainder] string expression) public static async Task Calculate(IMessage msg, [Remainder] string expression)
{ {
try try
{ {
var expr = new NCalc.Expression(expression, NCalc.EvaluateOptions.IgnoreCase); var expr = new NCalc.Expression(expression, NCalc.EvaluateOptions.IgnoreCase);
expr.EvaluateParameter += Expr_EvaluateParameter; expr.EvaluateParameter += Expr_EvaluateParameter;
expr.EvaluateFunction += Expr_EvaluateFunction;
var result = expr.Evaluate(); var result = expr.Evaluate();
await msg.Reply(string.Format("Your expression evaluated to: {0}", expr.Error ?? result)); 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} "); 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) private static void Expr_EvaluateParameter(string name, NCalc.ParameterArgs args)
@ -52,14 +38,12 @@ namespace NadekoBot.Modules.Searches
break; break;
case "e": args.Result = Math.E; case "e": args.Result = Math.E;
break; break;
} }
} }
[Command("calcOperations")] [LocalizedCommand, LocalizedDescription, LocalizedSummary]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task calcOperations(IMessage msg) public async Task CalcOperations(IMessage msg)
{ {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
var selection = typeof(Math).GetTypeInfo().GetMethods().Except(typeof(object).GetTypeInfo().GetMethods()).Select(x => 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)) + ")"; name += " (" + string.Join(", ", x.GetParameters().Select(y => y.IsOptional ? $"[{y.ParameterType.Name + " " + y.Name }]" : y.ParameterType.Name + " " + y.Name)) + ")";
} }
return name; return name;
}); });
foreach (var method in selection) builder.AppendLine(method); 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;
// }
// }
// }
//}

View File

@ -35,7 +35,6 @@ namespace NadekoBot.Services.Database.Repositories
return entry.Entity; return entry.Entity;
} }
// TODO: Build the real LINQ Expression
// set.Where(x => x.Id == keyValues[0]); // set.Where(x => x.Id == keyValues[0]);
var parameter = Expression.Parameter(typeof(TEntity), "x"); var parameter = Expression.Parameter(typeof(TEntity), "x");
var query = set.Where((Expression<Func<TEntity, bool>>) var query = set.Where((Expression<Func<TEntity, bool>>)

View File

@ -8,7 +8,6 @@ using NLog;
namespace NadekoBot.Services.Impl namespace NadekoBot.Services.Impl
{ {
//todo load creds
public class BotCredentials : IBotCredentials public class BotCredentials : IBotCredentials
{ {
private Logger _log; private Logger _log;

View File

@ -20,7 +20,7 @@
"Microsoft.Extensions.PlatformAbstractions": "1.0.0", "Microsoft.Extensions.PlatformAbstractions": "1.0.0",
"Newtonsoft.Json": "9.0.1", "Newtonsoft.Json": "9.0.1",
"Microsoft.Extensions.DependencyInjection": "1.0.0", "Microsoft.Extensions.DependencyInjection": "1.0.0",
"Discord.Net.Commands": "1.0.0-dev-*", "Discord.Net.Commands": "1.0.0-dev",
"System.Resources.ResourceWriter": "4.0.0-beta-22816", "System.Resources.ResourceWriter": "4.0.0-beta-22816",
"Google.Apis.YouTube.v3": "1.15.0.582", "Google.Apis.YouTube.v3": "1.15.0.582",
"Google.Apis.Urlshortener.v1": "1.15.0.138", "Google.Apis.Urlshortener.v1": "1.15.0.138",

View File

@ -9003,8 +9003,7 @@
"projectFileDependencyGroups": { "projectFileDependencyGroups": {
"": [ "": [
"CoreCLR-NCalc >= 2.1.0", "CoreCLR-NCalc >= 2.1.0",
"Discord.Net >= 1.0.0-dev-*", "Discord.Net.Commands >= 1.0.0-dev",
"Discord.Net.Commands >= 1.0.0-dev-*",
"Google.Apis.Urlshortener.v1 >= 1.15.0.138", "Google.Apis.Urlshortener.v1 >= 1.15.0.138",
"Google.Apis.YouTube.v3 >= 1.15.0.582", "Google.Apis.YouTube.v3 >= 1.15.0.582",
"Microsoft.EntityFrameworkCore >= 1.0.0", "Microsoft.EntityFrameworkCore >= 1.0.0",