calculate
This commit is contained in:
30
src/NadekoBot/Modules/Searches/Commands/CalcCommand.cs
Normal file
30
src/NadekoBot/Modules/Searches/Commands/CalcCommand.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user