Kwoth's changes
This commit is contained in:
parent
338cb6d24b
commit
fa0918806e
@ -15,9 +15,9 @@ namespace NadekoBot.Modules.Searches.Commands
|
|||||||
|
|
||||||
internal override void Init(CommandGroupBuilder cgb)
|
internal override void Init(CommandGroupBuilder cgb)
|
||||||
{
|
{
|
||||||
cgb.CreateCommand(Module.Prefix + "evaluate")
|
cgb.CreateCommand(Module.Prefix + "calculate")
|
||||||
.Alias(Module.Prefix + "eval")
|
.Alias(Module.Prefix + "calc")
|
||||||
.Description("Evaluate a mathematical expression")
|
.Description("Evaluate a mathematical expression.\n**Usage**: ~calc 1+1")
|
||||||
.Parameter("expression", ParameterType.Unparsed)
|
.Parameter("expression", ParameterType.Unparsed)
|
||||||
.Do(EvalFunc());
|
.Do(EvalFunc());
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ namespace NadekoBot.Modules.Searches.Commands
|
|||||||
await e.Channel.SendMessage("Must give expression");
|
await e.Channel.SendMessage("Must give expression");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
string answer = evaluate(expression);
|
string answer = Evaluate(expression);
|
||||||
if (answer == null)
|
if (answer == null)
|
||||||
{
|
{
|
||||||
await e.Channel.SendMessage($"Expression {expression} failed to evaluate");
|
await e.Channel.SendMessage($"Expression {expression} failed to evaluate");
|
||||||
@ -41,7 +41,7 @@ namespace NadekoBot.Modules.Searches.Commands
|
|||||||
await e.Channel.SendMessage($"`result: {answer}`");
|
await e.Channel.SendMessage($"`result: {answer}`");
|
||||||
};
|
};
|
||||||
|
|
||||||
private string evaluate(string expression)
|
private string Evaluate(string expression)
|
||||||
{
|
{
|
||||||
//check for factorial
|
//check for factorial
|
||||||
expression = Regex.Replace(expression, @"\d+!", x => x.Value + "0");
|
expression = Regex.Replace(expression, @"\d+!", x => x.Value + "0");
|
||||||
@ -67,12 +67,10 @@ namespace NadekoBot.Modules.Searches.Commands
|
|||||||
public CustomParser() : base()
|
public CustomParser() : base()
|
||||||
{
|
{
|
||||||
OperatorList.Add("!");
|
OperatorList.Add("!");
|
||||||
OperatorList.Add("_");
|
OperatorAction.Add("!", (x, y) => Factorial(x));
|
||||||
OperatorAction.Add("!", (x, y) => factorial(x));
|
|
||||||
OperatorAction.Add("_", (x, y) => 10.130M);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static decimal factorial(decimal x)
|
static decimal Factorial(decimal x)
|
||||||
{
|
{
|
||||||
decimal y = x-1;
|
decimal y = x-1;
|
||||||
while (y >0)
|
while (y >0)
|
||||||
|
Loading…
Reference in New Issue
Block a user