Exemplo n.º 1
0
 public async void OnMouseDown()
 {
     if (Title != null && Description != null)
     {
         MemoryDataService.Language = "en";
         Title.text = await WikipediaService.GetOpenSearch(Title.text, MemoryDataService.Language);
         Description.text = await WikipediaService.FullSearch(Title.text, MemoryDataService.Language);
     }
 }
Exemplo n.º 2
0
        public async Task Wikipedia(CommandContext ctx,
                                    [Description("Query to search on Wikipedia")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var results = WikipediaService.GetWikipediaDataAsync(query).Result;

            if (results.Missing)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_WIKIPEDIA, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                await ctx.Channel.SendMessageAsync(results.FullUrl).ConfigureAwait(false);
            }
        }
Exemplo n.º 3
0
        public async Task Wikipedia(CommandContext ctx,
                                    [Description("Articles to find on Wikipedia.")][RemainingText]
                                    string query)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                return;
            }
            await ctx.TriggerTypingAsync();

            var results = WikipediaService.GetWikipediaDataAsync(query);

            if (results.Error != null || results.Search?.Count == 0)
            {
                await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_WIKIPEDIA, ResponseType.Missing)
                .ConfigureAwait(false);

                return;
            }

            if (results.Search?.Count <= 1)
            {
                await BotServices.SendResponseAsync(ctx, Resources.NOT_FOUND_COMMON, ResponseType.Missing)
                .ConfigureAwait(false);

                return;
            }

            while (results.Search?.Count > 0)
            {
                var output = new DiscordEmbedBuilder()
                             .WithColor(new DiscordColor("#6B6B6B"))
                             .WithFooter(results.Search.Count - 5 >= 5
                        ? "Type 'next' within 10 seconds for the next five articles."
                        : "There articles are retrieved using WikipediaNET.");

                foreach (var result in results.Search.Take(5))
                {
                    var desc = Regex.Replace(
                        result.Snippet.Length <= 300
                            ? string.IsNullOrEmpty(result.Snippet) ? "Article has not content." : result.Snippet
                            : result.Snippet[..150] + "...", "<[^>]*>", "");
        public async void OnMouseDown()
        {
            MarkerStorage.ActiveMarkers.TryGetValue(gameObject, out PlaceAtLocation marker);

            if (PlaceOfInterestDescription != null && marker != null)
            {
                if (lastClickedMarker == gameObject && PlaceOfInterestDescription.activeSelf)
                {
                    PlaceOfInterestDescription.SetActive(false);
                }
                else
                {
                    PlaceOfInterestDescription.SetActive(true);

                    lastClickedMarker = gameObject;

                    Title.text = await WikipediaService.GetOpenSearch(gameObject.name, MemoryDataService.Language);

                    Description.text = await WikipediaService.FullSearch(gameObject.name, MemoryDataService.Language);
                }
            }
        }
Exemplo n.º 5
0
        public async Task RunAsync(
            [Summary("The phrase to search on Wikipedia.")]
            [Remainder] string phrase)
        {
            var response = await WikipediaService.GetWikipediaResultsAsync(phrase);

            // Empty response.
            if (response == null || response.Query == null || !response.Query.Pages.Any())
            {
                await ReplyAsync($"Failed to find anything for `!wiki {phrase}`.");

                return;
            }

            // Construct results into one string (use StringBuilder for concat speed).
            var messageBuilder = new StringBuilder();

            response.Query.Pages.Values.ToList().ForEach(p => messageBuilder.AppendLine(p.Extract));
            var message = messageBuilder.ToString();

            // Sometimes we get here and there's no message, just double check.
            if (message.Length == 0 || message == Environment.NewLine)
            {
                await ReplyAsync($"Failed to find anything for `!wiki {phrase}`.");

                return;
            }

            // Discord has a limit on channel message size... so this accounts for that.
            if (message.Length > DiscordConfig.MaxMessageSize)
            {
                // How many batches do we need to send?
                // IE: 5000 / 2000 = 2.5
                // Round up = 3
                var batchCount = Math.Ceiling(decimal.Divide(message.Length, DiscordConfig.MaxMessageSize));

                // Keep track of how many characters we've sent to the channel.
                // Use the cursor to see the diff between what we've sent, and what is remaining to send
                //  So we can satisfy the batch sending approach.
                var cursor = 0;

                for (var i = 0; i < batchCount; i++)
                {
                    var builder = new EmbedBuilder()
                                  .WithColor(new Color(95, 186, 125))
                                  .WithTitle($"Results for {phrase} (pt {i + 1})")
                                  .WithDescription(message.Substring(cursor, (i == batchCount - 1) ? message.Length - cursor : DiscordConfig.MaxMessageSize));

                    await ReplyAsync("", embed : builder.Build());

                    cursor += DiscordConfig.MaxMessageSize;
                }
            }
            else
            {
                var builder = new EmbedBuilder()
                              .WithColor(new Color(95, 186, 125))
                              .WithTitle($"Results for {phrase}")
                              .WithDescription(message);

                await ReplyAsync("", embed : builder.Build());
            }
        }
Exemplo n.º 6
0
 public WikipediaModule(WikipediaService wikipediaService)
 {
     WikipediaService = wikipediaService;
 }
Exemplo n.º 7
0
 public void GetWikipediaPage()
 {
     Assert.IsFalse(WikipediaService.GetWikipediaDataAsync("Russia").Result.Missing);
 }
Exemplo n.º 8
0
 public Define(WikipediaService wiki)
 {
     _wikipedia = wiki;
 }
Exemplo n.º 9
0
 public void GetWikipediaPage()
 {
     Assert.IsNull(WikipediaService.GetWikipediaDataAsync("Russia").Error);
 }
Exemplo n.º 10
0
        private async Task HandleLuisResult(IDialogContext context)
        {
            if (_textAnalyticsDocumentSentimentModel != null)
            {
                var helper   = new Helpers.SomeHelpers();
                var heroCard = new HeroCard
                {
                    Title    = "Voici ce que j'ai trouvé",
                    Subtitle = "",
                    Text     = "",
                    Images   = new List <CardImage>
                    {
                        new CardImage(helper.GetImgByScore(_textAnalyticsDocumentSentimentModel.Score)),
                    },
                    Buttons = new List <CardAction>()
                };

                var message = context.MakeMessage();
                if (_textAnalyticsDocumentSentimentModel?.Score != null)
                {
                    var txtAnalyticsResult =
                        $@"Score de sentiment :  {
                            _textAnalyticsDocumentSentimentModel?.Score.Value
                        :0.0}  KeyWords : {_textAnalyticsDocumentSentimentModel.KeyWords} Langage : {
                            _textAnalyticsDocumentSentimentModel.DetectedLanguage
                        }";
                    message.Text = "Voici ce que j'ai trouvé :";

                    if (_luisAnswer.TopScoringIntent.Intent == "GetWeather")
                    {
                        var openWeatherMapService = new Services.WeatherServices.OpenWeatherMapService();
                        var city = _luisAnswer.Entities?.FirstOrDefault(x => x.Type == "City")?.entity;

                        if (city != null)
                        {
                            var weatherQuery = new OpenWeatherMapQueryModel();
                            weatherQuery.Location = city;

                            var response = await openWeatherMapService.GetWeatherAsync(weatherQuery);

                            var minTemp = 0;
                            var maxTemp = 0;
                            if (response.Main.MinTemperature != null && response.Main.MaxTemperature != null)
                            {
                                minTemp = (int)response.Main.MinTemperature;
                                maxTemp = (int)response.Main.MaxTemperature;
                            }

                            if (minTemp == maxTemp)
                            {
                                if (response.Main.MaxTemperature != null)
                                {
                                    if (_textAnalyticsDocumentSentimentModel.Score != null)
                                    {
                                        heroCard.Text = "A " + response.Name + " , le temps est " +
                                                        response.Weather.FirstOrDefault()?.Description +
                                                        " avec une température de "
                                                        + response.Main.MaxTemperature.Value.ToString("00.0") +
                                                        " °";
                                    }
                                }
                                heroCard.Title = "Voici la météo ";
                                message.Attachments.Add(heroCard.ToAttachment());
                                await context.PostAsync(txtAnalyticsResult);

                                await context.PostAsync(message);
                            }
                            else
                            {
                                if (response.Main.MinTemperature != null)
                                {
                                    if (response.Main.MaxTemperature != null)
                                    {
                                        heroCard.Text = "A " + response.Name + " , le temps est " +
                                                        response.Weather.FirstOrDefault()?.Description +
                                                        " avec des températures comprises entre "
                                                        + response.Main.MinTemperature.Value.ToString("00.0") +
                                                        " et " +
                                                        response.Main.MaxTemperature.Value.ToString("00.0") +
                                                        " °";
                                    }
                                }
                                heroCard.Title = "Voici la météo ";
                                message.Attachments.Add(heroCard.ToAttachment());
                                await context.PostAsync(txtAnalyticsResult);

                                await context.PostAsync(message);
                            }
                        }
                    }

                    //if (_luisAnswer.TopScoringIntent.Intent == "Greetings")
                    //{
                    //    if (_textAnalyticsDocumentSentimentModel.Score != null)
                    //        heroCard.Text = "Bonjour ! Enchanté :) ";
                    //    message.Text += message.Text + _textAnalyticsDocumentSentimentModel.Score.Value.ToString("0.0");
                    //    message.Attachments.Add(heroCard.ToAttachment());
                    //        await context.PostAsync(message);
                    //}

                    if (_luisAnswer.TopScoringIntent.Intent == "GetWikipediaInformations")
                    {
                        var wikipediaService = new WikipediaService();
                        var location         = _luisAnswer.Entities?.FirstOrDefault(x => x.Type == "Location")?.entity;
                        var subject          = _utterance.Split(new[] { "histoire" }, StringSplitOptions.None)[1];
                        var result           = wikipediaService.GetWikipediaInformations(subject).Result.Search;

                        foreach (var item in result)
                        {
                            heroCard.Buttons.Add(new CardAction
                            {
                                Value = item.Url,
                                Type  = "openUrl",
                                Title = item.Url.AbsoluteUri
                            }
                                                 );
                        }

                        message.Text = "";
                        message.Attachments.Add(heroCard.ToAttachment());
                        await context.PostAsync(txtAnalyticsResult);

                        await context.PostAsync(message);
                    }
                    if (_luisAnswer.TopScoringIntent.Intent == "GetAppreciation")
                    {
                        heroCard.Title = "Tout le plaisir est pour moi :)";
                        message.Attachments.Add(heroCard.ToAttachment());
                        await context.PostAsync(txtAnalyticsResult);

                        await context.PostAsync(message);
                    }
                    if (_luisAnswer.TopScoringIntent.Intent == "GetOpinion")
                    {
                        heroCard.Title = "Je vais te donner mon avis sur la question :)";
                        message.Attachments.Add(heroCard.ToAttachment());
                        await context.PostAsync(txtAnalyticsResult);

                        await context.PostAsync(message);
                    }
                }
            }
            context.Done <object>(null);
        }