예제 #1
0
        public async Task Wolfram([Remainder] string text)
        {
            string             wolframToken = _config["tokens:wolframalpha"];
            WolframAlphaClient client       = new WolframAlphaClient(wolframToken);


            FullResultRequest request = new FullResultRequest(text);

            request.ScanTimeout = 8;

            FullResultResponse results = await client.FullResultAsync(request).ConfigureAwait(false);

            if (results.IsError)
            {
                await ReplyAsync($"Error: {results.ErrorDetails.Message}");
            }


            //Results are split into "pods" that contain information. Those pods can have SubPods.
            foreach (Pod pod in results.Pods)
            {
                foreach (SubPod subPod in pod.SubPods)
                {
                    var builder = new EmbedBuilder()
                    {
                        Color = new Color(114, 137, 218),
                    };

                    string value = (subPod.Image.Height <= 21) ? subPod.Image.Alt : "Shown below";
                    string name  = string.IsNullOrEmpty(subPod.Title) ? pod.Title : subPod.Title;

                    if (!string.IsNullOrEmpty(subPod.Image.Src.ToString()) && subPod.Image.Height > 21)
                    {
                        builder.ImageUrl = subPod.Image.Src.ToString();
                    }


                    builder.AddField(x => {
                        x.Name     = name;
                        x.IsInline = false;
                        x.Value    = value;
                    });

                    await ReplyAsync("", false, builder.Build());
                }
            }
        }
예제 #2
0
        public IEnumerable <AssociationResult> ReceiveAssociations(double value, ValueUnit unit)
        {
            WolframAlphaClient client           = null;
            IEnumerable <AssociationResult> ret = null;

            if (!IsValidRequest())
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            client = new WolframAlphaClient()
            {
                Silent = true
            };

            client.Load(value, unit);

            ret = client.GetComparisonData();

            return(ret);
        }
예제 #3
0
        private static async Task Main(string[] args)
        {
            //Create the client.
            WolframAlphaClient client = new WolframAlphaClient(_appId);

            FullResultRequest request = new FullResultRequest("100 digits of pi");

            request.Formats = Format.Plaintext;

            //We start a new query.
            FullResultResponse results = await client.FullResultAsync(request).ConfigureAwait(false);

            //Here we output the Wolfram|Alpha results.
            if (results.IsError)
            {
                Console.WriteLine("Woops, where was an error: " + results.ErrorDetails.Message);
            }

            Console.WriteLine();

            //Results are split into "pods" that contain information. Those pods can have SubPods.
            foreach (Pod pod in results.Pods)
            {
                Console.WriteLine(pod.Title + ":");

                foreach (SubPod subPod in pod.SubPods)
                {
                    if (string.IsNullOrEmpty(subPod.Plaintext))
                    {
                        Console.WriteLine("<Cannot output in console>");
                    }
                    else
                    {
                        Console.WriteLine(subPod.Plaintext);
                    }
                }

                Console.WriteLine();
            }
        }
예제 #4
0
        public async Task WolframCommand([Remainder] string Question)
        {
            if (string.IsNullOrEmpty(UtilityConfiguration.WolframAppAPI) || UtilityConfiguration.WolframAppAPI == "NOTSET")
            {
                await BuildEmbed(EmojiEnum.Annoyed)
                .WithTitle("Whoops! This is on us. <3")
                .WithDescription("It looks like one of our developers forgot to set an API key to use this service. " +
                                 "We appologise for the inconvenience~!")
                .WithCurrentTimestamp()
                .WithFooter("USFurries Developer Team")
                .SendEmbed(Context.Channel);

                return;
            }

            if (WolframAlphaClient == null)
            {
                WolframAlphaClient = new WolframAlphaClient(UtilityConfiguration.WolframAppAPI);
            }

            string Response = await WolframAlphaClient.SpokenResultAsync(Question);

            Response = Response.Replace("Wolfram Alpha", Context.Client.CurrentUser.Username);
            Response = Response.Replace("Wolfram|Alpha", Context.Client.CurrentUser.Username);
            Response = Response.Replace("Stephen Wolfram", "the goat overlords");
            Response = Response.Replace("and his team", "and their team");

            if (Response == "Error 1: Invalid appid")
            {
                WolframAlphaClient = null;
            }
            else if (Response == "DexterBot did not understand your input" || Response == "No spoken result available")
            {
                await Context.Message.AddReactionAsync(new Emoji("❓"));
            }
            else
            {
                await Context.Channel.SendMessageAsync(Response);
            }
        }
예제 #5
0
        public async Task WolframCommand([Remainder] string Question)
        {
            if (string.IsNullOrEmpty(UtilityConfiguration.WolframAppAPI))
            {
                await BuildEmbed(EmojiEnum.Annoyed)
                .WithTitle("Whoops! This is on us. <3")
                .WithDescription("It looks like one of our developers forgot to set an API key to use this service. " +
                                 "We appologise for the inconvenience~!")
                .WithCurrentTimestamp()
                .WithFooter("USFurries Developer Team")
                .SendEmbed(Context.Channel);

                return;
            }

            if (WolframAlphaClient == null)
            {
                WolframAlphaClient = new WolframAlphaClient(UtilityConfiguration.WolframAppAPI);
            }

            string Response = await WolframAlphaClient.ShortAnswerAsync(Question);

            if (Response == "Error 1: Invalid appid")
            {
                WolframAlphaClient = null;
            }

            if (Response.Length > 500)
            {
                Response = $"{Response.Substring(0, 500)}...";
            }

            Response = Response.Replace("Wolfram Alpha", Context.User.Username);
            Response = Response.Replace("Wolfram|Alpha", Context.User.Username);

            await Context.Channel.SendMessageAsync(Response);
        }