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.Text.RegularExpressions;
using System.Net; using System.Net;
using NadekoBot.Modules.Searches.Commands.Models; using NadekoBot.Modules.Searches.Commands.Models;
using NCalc;
namespace NadekoBot.Modules.Searches namespace NadekoBot.Modules.Searches
{ {
@ -26,6 +27,14 @@ namespace NadekoBot.Modules.Searches
_yt = youtube; _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] [LocalizedCommand, LocalizedDescription, LocalizedSummary]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Weather(IMessage imsg, string city, string country) public async Task Weather(IMessage imsg, string city, string country)

View File

@ -29,7 +29,7 @@ namespace NadekoBot
public async Task RunAsync(string[] args) public async Task RunAsync(string[] args)
{ {
SetupLogger(); SetupLogger();
_log.Debug("Logger created, starting client");
//create client //create client
Client = new DiscordSocketClient(new DiscordSocketConfig Client = new DiscordSocketClient(new DiscordSocketConfig
{ {

View File

@ -18,12 +18,13 @@
"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": "1.0.0-dev", "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",
"System.Diagnostics.Contracts": "4.0.1", "System.Diagnostics.Contracts": "4.0.1",
"NLog": "4.4.0-betaV15" "NLog": "4.4.0-betaV15",
"Discord.Net": "1.0.0-dev-*",
"CoreCLR-NCalc": "2.1.0"
}, },
"frameworks": { "frameworks": {

View File

@ -3,6 +3,26 @@
"version": 2, "version": 2,
"targets": { "targets": {
".NETCoreApp,Version=v1.0": { ".NETCoreApp,Version=v1.0": {
"CoreCLR-NCalc/2.1.0": {
"type": "package",
"dependencies": {
"NETStandard.Library": "1.6.0",
"System.Diagnostics.Debug": "4.0.11",
"System.Linq": "4.1.0",
"System.Linq.Expressions": "4.1.0",
"System.Reflection.TypeExtensions": "4.1.0",
"System.Runtime.Extensions": "4.1.0",
"System.Runtime.Serialization.Xml": "4.1.1",
"System.Text.RegularExpressions": "4.1.0",
"System.Threading.Thread": "4.0.0"
},
"compile": {
"lib/netstandard1.3/NCalc.dll": {}
},
"runtime": {
"lib/netstandard1.3/NCalc.dll": {}
}
},
"Google.Apis/1.15.0": { "Google.Apis/1.15.0": {
"type": "package", "type": "package",
"dependencies": { "dependencies": {
@ -1626,6 +1646,41 @@
"lib/netstandard1.3/System.ObjectModel.dll": {} "lib/netstandard1.3/System.ObjectModel.dll": {}
} }
}, },
"System.Private.DataContractSerialization/4.1.1": {
"type": "package",
"dependencies": {
"System.Collections": "4.0.11",
"System.Collections.Concurrent": "4.0.12",
"System.Diagnostics.Debug": "4.0.11",
"System.Globalization": "4.0.11",
"System.IO": "4.1.0",
"System.Linq": "4.1.0",
"System.Reflection": "4.1.0",
"System.Reflection.Emit.ILGeneration": "4.0.1",
"System.Reflection.Emit.Lightweight": "4.0.1",
"System.Reflection.Extensions": "4.0.1",
"System.Reflection.Primitives": "4.0.1",
"System.Reflection.TypeExtensions": "4.1.0",
"System.Resources.ResourceManager": "4.0.1",
"System.Runtime": "4.1.0",
"System.Runtime.Extensions": "4.1.0",
"System.Runtime.Serialization.Primitives": "4.1.1",
"System.Text.Encoding": "4.0.11",
"System.Text.Encoding.Extensions": "4.0.11",
"System.Text.RegularExpressions": "4.1.0",
"System.Threading": "4.0.11",
"System.Threading.Tasks": "4.0.11",
"System.Xml.ReaderWriter": "4.0.11",
"System.Xml.XmlDocument": "4.0.1",
"System.Xml.XmlSerializer": "4.0.11"
},
"compile": {
"ref/netstandard/_._": {}
},
"runtime": {
"lib/netstandard1.3/System.Private.DataContractSerialization.dll": {}
}
},
"System.Reflection/4.1.0": { "System.Reflection/4.1.0": {
"type": "package", "type": "package",
"dependencies": { "dependencies": {
@ -1922,6 +1977,23 @@
"lib/netstandard1.3/System.Runtime.Serialization.Primitives.dll": {} "lib/netstandard1.3/System.Runtime.Serialization.Primitives.dll": {}
} }
}, },
"System.Runtime.Serialization.Xml/4.1.1": {
"type": "package",
"dependencies": {
"System.IO": "4.1.0",
"System.Private.DataContractSerialization": "4.1.1",
"System.Runtime": "4.1.0",
"System.Runtime.Serialization.Primitives": "4.1.1",
"System.Text.Encoding": "4.0.11",
"System.Xml.ReaderWriter": "4.0.11"
},
"compile": {
"ref/netstandard1.3/System.Runtime.Serialization.Xml.dll": {}
},
"runtime": {
"lib/netstandard1.3/System.Runtime.Serialization.Xml.dll": {}
}
},
"System.Security.Claims/4.0.1": { "System.Security.Claims/4.0.1": {
"type": "package", "type": "package",
"dependencies": { "dependencies": {
@ -2469,6 +2541,34 @@
"lib/netstandard1.3/System.Xml.XmlDocument.dll": {} "lib/netstandard1.3/System.Xml.XmlDocument.dll": {}
} }
}, },
"System.Xml.XmlSerializer/4.0.11": {
"type": "package",
"dependencies": {
"System.Collections": "4.0.11",
"System.Globalization": "4.0.11",
"System.IO": "4.1.0",
"System.Linq": "4.1.0",
"System.Reflection": "4.1.0",
"System.Reflection.Emit": "4.0.1",
"System.Reflection.Emit.ILGeneration": "4.0.1",
"System.Reflection.Extensions": "4.0.1",
"System.Reflection.Primitives": "4.0.1",
"System.Reflection.TypeExtensions": "4.1.0",
"System.Resources.ResourceManager": "4.0.1",
"System.Runtime": "4.1.0",
"System.Runtime.Extensions": "4.1.0",
"System.Text.RegularExpressions": "4.1.0",
"System.Threading": "4.0.11",
"System.Xml.ReaderWriter": "4.0.11",
"System.Xml.XmlDocument": "4.0.1"
},
"compile": {
"ref/netstandard1.3/_._": {}
},
"runtime": {
"lib/netstandard1.3/System.Xml.XmlSerializer.dll": {}
}
},
"System.Xml.XPath/4.0.1": { "System.Xml.XPath/4.0.1": {
"type": "package", "type": "package",
"dependencies": { "dependencies": {
@ -2552,6 +2652,17 @@
} }
}, },
"libraries": { "libraries": {
"CoreCLR-NCalc/2.1.0": {
"sha512": "GUPPo99NUeAgLR5oIOLrApJx3Mx5BZEaKkK9OlDd/CmAYaACLHo68FnO+kCamsLH2+rvr6Rw3hAwzap4GVFV8Q==",
"type": "package",
"path": "CoreCLR-NCalc/2.1.0",
"files": [
"CoreCLR-NCalc.2.1.0.nupkg.sha512",
"CoreCLR-NCalc.nuspec",
"lib/net451/NCalc.dll",
"lib/netstandard1.3/NCalc.dll"
]
},
"Google.Apis/1.15.0": { "Google.Apis/1.15.0": {
"sha512": "B//vbZgUsR0jdJztCJ0ORmVcAzhoiisIsxwc1libVjoZzu+kxUKNJKUl5Wlkj7V28kauS56y3hJUj3FMsgaJZQ==", "sha512": "B//vbZgUsR0jdJztCJ0ORmVcAzhoiisIsxwc1libVjoZzu+kxUKNJKUl5Wlkj7V28kauS56y3hJUj3FMsgaJZQ==",
"type": "package", "type": "package",
@ -5677,6 +5788,20 @@
"ref/xamarinwatchos10/_._" "ref/xamarinwatchos10/_._"
] ]
}, },
"System.Private.DataContractSerialization/4.1.1": {
"sha512": "lcqFBUaCZxPiUkA4dlSOoPZGtZsAuuElH2XHgLwGLxd7ZozWetV5yiz0qGAV2AUYOqw97MtZBjbLMN16Xz4vXA==",
"type": "package",
"path": "System.Private.DataContractSerialization/4.1.1",
"files": [
"System.Private.DataContractSerialization.4.1.1.nupkg.sha512",
"System.Private.DataContractSerialization.nuspec",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/netstandard1.3/System.Private.DataContractSerialization.dll",
"ref/netstandard/_._",
"runtimes/aot/lib/netcore50/System.Private.DataContractSerialization.dll"
]
},
"System.Reflection/4.1.0": { "System.Reflection/4.1.0": {
"sha512": "JCKANJ0TI7kzoQzuwB/OoJANy1Lg338B6+JVacPl4TpUwi3cReg3nMLplMq2uqYfHFQpKIlHAUVAJlImZz/4ng==", "sha512": "JCKANJ0TI7kzoQzuwB/OoJANy1Lg338B6+JVacPl4TpUwi3cReg3nMLplMq2uqYfHFQpKIlHAUVAJlImZz/4ng==",
"type": "package", "type": "package",
@ -6617,6 +6742,76 @@
"runtimes/aot/lib/netcore50/System.Runtime.Serialization.Primitives.dll" "runtimes/aot/lib/netcore50/System.Runtime.Serialization.Primitives.dll"
] ]
}, },
"System.Runtime.Serialization.Xml/4.1.1": {
"sha512": "yqfKHkWUAdI0hdDIdD9KDzluKtZ8IIqLF3O7xIZlt6UTs1bOvFRpCvRTvGQva3Ak/ZM9/nq9IHBJ1tC4Ybcrjg==",
"type": "package",
"path": "System.Runtime.Serialization.Xml/4.1.1",
"files": [
"System.Runtime.Serialization.Xml.4.1.1.nupkg.sha512",
"System.Runtime.Serialization.Xml.nuspec",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net45/_._",
"lib/net46/System.Runtime.Serialization.Xml.dll",
"lib/netcore50/System.Runtime.Serialization.Xml.dll",
"lib/netstandard1.3/System.Runtime.Serialization.Xml.dll",
"lib/portable-net45+win8+wp8+wpa81/_._",
"lib/win8/_._",
"lib/wp80/_._",
"lib/wpa81/_._",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/net45/_._",
"ref/net46/System.Runtime.Serialization.Xml.dll",
"ref/netcore50/System.Runtime.Serialization.Xml.dll",
"ref/netcore50/System.Runtime.Serialization.Xml.xml",
"ref/netcore50/de/System.Runtime.Serialization.Xml.xml",
"ref/netcore50/es/System.Runtime.Serialization.Xml.xml",
"ref/netcore50/fr/System.Runtime.Serialization.Xml.xml",
"ref/netcore50/it/System.Runtime.Serialization.Xml.xml",
"ref/netcore50/ja/System.Runtime.Serialization.Xml.xml",
"ref/netcore50/ko/System.Runtime.Serialization.Xml.xml",
"ref/netcore50/ru/System.Runtime.Serialization.Xml.xml",
"ref/netcore50/zh-hans/System.Runtime.Serialization.Xml.xml",
"ref/netcore50/zh-hant/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.0/System.Runtime.Serialization.Xml.dll",
"ref/netstandard1.0/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.0/de/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.0/es/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.0/fr/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.0/it/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.0/ja/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.0/ko/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.0/ru/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.0/zh-hans/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.0/zh-hant/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.3/System.Runtime.Serialization.Xml.dll",
"ref/netstandard1.3/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.3/de/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.3/es/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.3/fr/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.3/it/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.3/ja/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.3/ko/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.3/ru/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.3/zh-hans/System.Runtime.Serialization.Xml.xml",
"ref/netstandard1.3/zh-hant/System.Runtime.Serialization.Xml.xml",
"ref/portable-net45+win8+wp8+wpa81/_._",
"ref/win8/_._",
"ref/wp80/_._",
"ref/wpa81/_._",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._"
]
},
"System.Security.Claims/4.0.1": { "System.Security.Claims/4.0.1": {
"sha512": "4Jlp0OgJLS/Voj1kyFP6MJlIYp3crgfH8kNQk2p7+4JYfc1aAmh9PZyAMMbDhuoolGNtux9HqSOazsioRiDvCw==", "sha512": "4Jlp0OgJLS/Voj1kyFP6MJlIYp3crgfH8kNQk2p7+4JYfc1aAmh9PZyAMMbDhuoolGNtux9HqSOazsioRiDvCw==",
"type": "package", "type": "package",
@ -7766,6 +7961,75 @@
"ref/xamarinwatchos10/_._" "ref/xamarinwatchos10/_._"
] ]
}, },
"System.Xml.XmlSerializer/4.0.11": {
"sha512": "FrazwwqfIXTfq23mfv4zH+BjqkSFNaNFBtjzu3I9NRmG8EELYyrv/fJnttCIwRMFRR/YKXF1hmsMmMEnl55HGw==",
"type": "package",
"path": "System.Xml.XmlSerializer/4.0.11",
"files": [
"System.Xml.XmlSerializer.4.0.11.nupkg.sha512",
"System.Xml.XmlSerializer.nuspec",
"ThirdPartyNotices.txt",
"dotnet_library_license.txt",
"lib/MonoAndroid10/_._",
"lib/MonoTouch10/_._",
"lib/net45/_._",
"lib/netcore50/System.Xml.XmlSerializer.dll",
"lib/netstandard1.3/System.Xml.XmlSerializer.dll",
"lib/portable-net45+win8+wp8+wpa81/_._",
"lib/win8/_._",
"lib/wp80/_._",
"lib/wpa81/_._",
"lib/xamarinios10/_._",
"lib/xamarinmac20/_._",
"lib/xamarintvos10/_._",
"lib/xamarinwatchos10/_._",
"ref/MonoAndroid10/_._",
"ref/MonoTouch10/_._",
"ref/net45/_._",
"ref/netcore50/System.Xml.XmlSerializer.dll",
"ref/netcore50/System.Xml.XmlSerializer.xml",
"ref/netcore50/de/System.Xml.XmlSerializer.xml",
"ref/netcore50/es/System.Xml.XmlSerializer.xml",
"ref/netcore50/fr/System.Xml.XmlSerializer.xml",
"ref/netcore50/it/System.Xml.XmlSerializer.xml",
"ref/netcore50/ja/System.Xml.XmlSerializer.xml",
"ref/netcore50/ko/System.Xml.XmlSerializer.xml",
"ref/netcore50/ru/System.Xml.XmlSerializer.xml",
"ref/netcore50/zh-hans/System.Xml.XmlSerializer.xml",
"ref/netcore50/zh-hant/System.Xml.XmlSerializer.xml",
"ref/netstandard1.0/System.Xml.XmlSerializer.dll",
"ref/netstandard1.0/System.Xml.XmlSerializer.xml",
"ref/netstandard1.0/de/System.Xml.XmlSerializer.xml",
"ref/netstandard1.0/es/System.Xml.XmlSerializer.xml",
"ref/netstandard1.0/fr/System.Xml.XmlSerializer.xml",
"ref/netstandard1.0/it/System.Xml.XmlSerializer.xml",
"ref/netstandard1.0/ja/System.Xml.XmlSerializer.xml",
"ref/netstandard1.0/ko/System.Xml.XmlSerializer.xml",
"ref/netstandard1.0/ru/System.Xml.XmlSerializer.xml",
"ref/netstandard1.0/zh-hans/System.Xml.XmlSerializer.xml",
"ref/netstandard1.0/zh-hant/System.Xml.XmlSerializer.xml",
"ref/netstandard1.3/System.Xml.XmlSerializer.dll",
"ref/netstandard1.3/System.Xml.XmlSerializer.xml",
"ref/netstandard1.3/de/System.Xml.XmlSerializer.xml",
"ref/netstandard1.3/es/System.Xml.XmlSerializer.xml",
"ref/netstandard1.3/fr/System.Xml.XmlSerializer.xml",
"ref/netstandard1.3/it/System.Xml.XmlSerializer.xml",
"ref/netstandard1.3/ja/System.Xml.XmlSerializer.xml",
"ref/netstandard1.3/ko/System.Xml.XmlSerializer.xml",
"ref/netstandard1.3/ru/System.Xml.XmlSerializer.xml",
"ref/netstandard1.3/zh-hans/System.Xml.XmlSerializer.xml",
"ref/netstandard1.3/zh-hant/System.Xml.XmlSerializer.xml",
"ref/portable-net45+win8+wp8+wpa81/_._",
"ref/win8/_._",
"ref/wp80/_._",
"ref/wpa81/_._",
"ref/xamarinios10/_._",
"ref/xamarinmac20/_._",
"ref/xamarintvos10/_._",
"ref/xamarinwatchos10/_._",
"runtimes/aot/lib/netcore50/System.Xml.XmlSerializer.dll"
]
},
"System.Xml.XPath/4.0.1": { "System.Xml.XPath/4.0.1": {
"sha512": "UWd1H+1IJ9Wlq5nognZ/XJdyj8qPE4XufBUkAW59ijsCPjZkZe0MUzKKJFBr+ZWBe5Wq1u1d5f2CYgE93uH7DA==", "sha512": "UWd1H+1IJ9Wlq5nognZ/XJdyj8qPE4XufBUkAW59ijsCPjZkZe0MUzKKJFBr+ZWBe5Wq1u1d5f2CYgE93uH7DA==",
"type": "package", "type": "package",
@ -7853,8 +8117,9 @@
}, },
"projectFileDependencyGroups": { "projectFileDependencyGroups": {
"": [ "": [
"Discord.Net >= 1.0.0-dev", "CoreCLR-NCalc >= 2.1.0",
"Discord.Net.Commands >= 1.0.0-dev", "Discord.Net >= 1.0.0-dev-*",
"Discord.Net.Commands >= 1.0.0-dev-*",
"Google.Apis.YouTube.v3 >= 1.15.0.582", "Google.Apis.YouTube.v3 >= 1.15.0.582",
"Microsoft.Extensions.DependencyInjection >= 1.0.0", "Microsoft.Extensions.DependencyInjection >= 1.0.0",
"Microsoft.Extensions.DependencyInjection.Abstractions >= 1.0.0", "Microsoft.Extensions.DependencyInjection.Abstractions >= 1.0.0",