calculate

This commit is contained in:
appelemac
2016-08-21 19:31:13 +02:00
parent 1d685757bf
commit 3432e3fde3
5 changed files with 311 additions and 6 deletions

View File

@@ -0,0 +1,30 @@
using Discord;
using Discord.Commands;
using NadekoBot.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace NadekoBot.Modules.Searches.Commands
{
public partial class Searches
{
public static async Task Calc(IMessage msg, [Remainder] string expression)
{
var expr = new NCalc.Expression(expression);
//expr.EvaluateParameter += delegate (string name, NCalc.ParameterArgs args)
//{
// if (name.ToLowerInvariant() == "pi") args.Result = Math.PI;
//};
var result = expr.Evaluate();
await msg.Reply(string.Format("Your expression evaluated to: {0}", expr.Error ?? result));
}
}
class ExpressionContext
{
public double Pi { get; set; } = Math.PI;
}
}

View File

@@ -13,6 +13,7 @@ using NadekoBot.Extensions;
using System.Text.RegularExpressions;
using System.Net;
using NadekoBot.Modules.Searches.Commands.Models;
using NCalc;
namespace NadekoBot.Modules.Searches
{
@@ -26,6 +27,14 @@ namespace NadekoBot.Modules.Searches
_yt = youtube;
}
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
[RequireContext(ContextType.Guild)]
public async Task Calc(IMessage msg, [Remainder] string calculation)
{
var channel = msg.Channel as ITextChannel;
}
[LocalizedCommand, LocalizedDescription, LocalizedSummary]
[RequireContext(ContextType.Guild)]
public async Task Weather(IMessage imsg, string city, string country)