From cb7fb76b91f0673319b690a5736e43639017f078 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Wed, 24 Aug 2016 15:39:37 +0200 Subject: [PATCH] cleanup --- .../Modules/Searches/Commands/CalcCommand.cs | 23 +---- .../Modules/Searches/Commands/EvalCommand.cs | 86 ------------------- .../Database/Repositories/Extensions.cs | 3 +- src/NadekoBot/Services/Impl/BotCredentials.cs | 1 - src/NadekoBot/project.json | 2 +- src/NadekoBot/project.lock.json | 3 +- 6 files changed, 6 insertions(+), 112 deletions(-) delete mode 100644 src/NadekoBot/Modules/Searches/Commands/EvalCommand.cs diff --git a/src/NadekoBot/Modules/Searches/Commands/CalcCommand.cs b/src/NadekoBot/Modules/Searches/Commands/CalcCommand.cs index 3353a9ec..16457743 100644 --- a/src/NadekoBot/Modules/Searches/Commands/CalcCommand.cs +++ b/src/NadekoBot/Modules/Searches/Commands/CalcCommand.cs @@ -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); diff --git a/src/NadekoBot/Modules/Searches/Commands/EvalCommand.cs b/src/NadekoBot/Modules/Searches/Commands/EvalCommand.cs deleted file mode 100644 index 5c8e45ad..00000000 --- a/src/NadekoBot/Modules/Searches/Commands/EvalCommand.cs +++ /dev/null @@ -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 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; -// } -// } - - -// } -//} diff --git a/src/NadekoBot/Services/Database/Repositories/Extensions.cs b/src/NadekoBot/Services/Database/Repositories/Extensions.cs index 0eff5d4e..ae1587bb 100644 --- a/src/NadekoBot/Services/Database/Repositories/Extensions.cs +++ b/src/NadekoBot/Services/Database/Repositories/Extensions.cs @@ -34,8 +34,7 @@ namespace NadekoBot.Services.Database.Repositories // Return the local object if it exists. return entry.Entity; } - - // TODO: Build the real LINQ Expression + // set.Where(x => x.Id == keyValues[0]); var parameter = Expression.Parameter(typeof(TEntity), "x"); var query = set.Where((Expression>) diff --git a/src/NadekoBot/Services/Impl/BotCredentials.cs b/src/NadekoBot/Services/Impl/BotCredentials.cs index 45d3945f..3c19c0be 100644 --- a/src/NadekoBot/Services/Impl/BotCredentials.cs +++ b/src/NadekoBot/Services/Impl/BotCredentials.cs @@ -8,7 +8,6 @@ using NLog; namespace NadekoBot.Services.Impl { - //todo load creds public class BotCredentials : IBotCredentials { private Logger _log; diff --git a/src/NadekoBot/project.json b/src/NadekoBot/project.json index ce45b94b..5d2ba911 100644 --- a/src/NadekoBot/project.json +++ b/src/NadekoBot/project.json @@ -20,7 +20,7 @@ "Microsoft.Extensions.PlatformAbstractions": "1.0.0", "Newtonsoft.Json": "9.0.1", "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", "Google.Apis.YouTube.v3": "1.15.0.582", "Google.Apis.Urlshortener.v1": "1.15.0.138", diff --git a/src/NadekoBot/project.lock.json b/src/NadekoBot/project.lock.json index bc325dbc..f5ea0aac 100644 --- a/src/NadekoBot/project.lock.json +++ b/src/NadekoBot/project.lock.json @@ -9003,8 +9003,7 @@ "projectFileDependencyGroups": { "": [ "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.YouTube.v3 >= 1.15.0.582", "Microsoft.EntityFrameworkCore >= 1.0.0",