Пример #1
0
 /// <summary>
 /// Gets an image from the Qwant API for the query supplied.
 /// Returns a default RecipyBot image if none found from Qwant.
 /// </summary>
 public static string GetImage(string query)
 {
     try
     {
         QwantDataModel    webResponse   = WebApiConnectorService.GenericGetRequest <QwantDataModel>(BotConstants.BotApiSettings.QwantImageApi + "" + query);
         IEnumerable <int> randomNumbers = MiscService.GiveXFromYNumbers(1, webResponse.data.result.items.Count());
         string            _imageUrl     = string.Empty;
         foreach (var value in randomNumbers)
         {
             var recipe = webResponse.data.result.items.ElementAt(value);
             _imageUrl = recipe.media.ToString();
         }
         return(_imageUrl);
     }
     catch (NullReferenceException nex)
     {
         System.Diagnostics.Trace.TraceError("QwantService GetImage " + nex.Message);
         return("https://github.com/ClydeDz/RecipyBot/blob/master/Docs/recipybot/3.png");
     }
     catch (Exception e)
     {
         System.Diagnostics.Trace.TraceError("QwantService GetImage " + e.Message);
         return("https://github.com/ClydeDz/RecipyBot/blob/master/Docs/recipybot/3.png");
     }
 }
Пример #2
0
 /// <summary>
 /// Gets an image from the Flickr API for the query supplied.
 /// Returns a default RecipyBot image if none found from Flickr.
 /// </summary>
 public static string GetImage(string query)
 {
     try
     {
         string            apiCall       = BotConstants.BotApiSettings.FlickrImageApi + "&method=flickr.photos.search&text=" + HttpContext.Current.Server.UrlEncode(query) + "&format=json&nojsoncallback=1";
         FlickrDataModel   webResponse   = WebApiConnectorService.GenericGetRequest <FlickrDataModel>(apiCall);
         IEnumerable <int> randomNumbers = MiscService.GiveXFromYNumbers(1, webResponse.photos.photo.Count);
         string            _imageUrl     = string.Empty;
         foreach (var value in randomNumbers)
         {
             _imageUrl = "https://farm" + webResponse.photos.photo.ElementAt(value).farm + ".staticflickr.com/" + webResponse.photos.photo.ElementAt(value).server + "/" + webResponse.photos.photo.ElementAt(value).id + "_" + webResponse.photos.photo.ElementAt(value).secret + ".jpg";
         }
         return(_imageUrl);
     }
     catch (NullReferenceException nex)
     {
         System.Diagnostics.Trace.TraceError("Flickr GetImage " + nex.Message);
         return("https://raw.githubusercontent.com/ClydeDz/RecipyBot/master/Docs/recipybot/2.png");
     }
     catch (Exception e)
     {
         System.Diagnostics.Trace.TraceError("Flickr GetImage " + e.Message);
         return("https://raw.githubusercontent.com/ClydeDz/RecipyBot/master/Docs/recipybot/2.png");
     }
 }
Пример #3
0
        public static Activity GetRecipeFor(Activity message, string dish, string defaultResponse)
        {
            BotService.SendATextResponse(message, defaultResponse);
            RecipePuppyDataModel webResponse   = WebApiConnectorService.GenericGetRequest <RecipePuppyDataModel>(BotConstants.BotApiSettings.RecipePuppyWebApiUrlWithQuery + "" + dish);
            IEnumerable <int>    randomNumbers = MiscService.GiveXFromYNumbers(BotConstants.OtherConstants.MaxOptionsGives, webResponse.results.Count());

            return(GenerateRecipeMessage(message, webResponse, randomNumbers, defaultResponse));
        }
Пример #4
0
        public static Activity GetTopNRecipes(Activity message, int n, string defaultResponse)
        {
            if (!string.IsNullOrEmpty(defaultResponse))
            {
                BotService.SendATextResponse(message, defaultResponse);
            }

            RecipePuppyDataModel webResponse   = WebApiConnectorService.GenericGetRequest <RecipePuppyDataModel>(BotConstants.BotApiSettings.RecipePuppyWebApiUrl);
            IEnumerable <int>    randomNumbers = MiscService.GiveXFromYNumbers(n, webResponse.results.Count());

            return(GenerateRecipeMessage(message, webResponse, randomNumbers, defaultResponse));
        }
Пример #5
0
        public static Activity GetRecipeWith(Activity message, string[] ingredients, string defaultResponse)
        {
            if (!string.IsNullOrEmpty(defaultResponse))
            {
                BotService.SendATextResponse(message, defaultResponse);
            }

            string listOfIngredients           = string.Join(",", ingredients.Select(item => item).ToArray());
            RecipePuppyDataModel webResponse   = WebApiConnectorService.GenericGetRequest <RecipePuppyDataModel>(BotConstants.BotApiSettings.RecipePuppyWebApiUrlWithIngredients + "" + listOfIngredients);
            IEnumerable <int>    randomNumbers = MiscService.GiveXFromYNumbers(BotConstants.OtherConstants.MaxOptionsGives, webResponse.results.Count());

            return(GenerateRecipeMessage(message, webResponse, randomNumbers, defaultResponse));
        }
Пример #6
0
        public static Activity GetRecipeGif(Activity message, string defaultResponse)
        {
            try
            {
                if (!string.IsNullOrEmpty(defaultResponse))
                {
                    BotService.SendATextResponse(message, defaultResponse);
                }

                GifRecipesDataModel webResponse   = WebApiConnectorService.GenericGetRequest <GifRecipesDataModel>(BotConstants.BotApiSettings.GifRecipes);
                IEnumerable <int>   randomNumbers = MiscService.GiveXFromYNumbers(1, webResponse.data.children.Where(p => p.data.domain == BotConstants.OtherConstants.GifImgurKeyword).Count());

                Activity replyToConversation = message.CreateReply("Here's your GIF recipe");
                replyToConversation.Attachments      = new List <Attachment>();
                replyToConversation.AttachmentLayout = AttachmentLayoutTypes.List;
                //replyToConversation.Text = "kjfjefkwek";

                foreach (var value in randomNumbers)
                {
                    var thisData = webResponse.data.children.Where(k => k.data.domain == BotConstants.OtherConstants.GifImgurKeyword).ElementAt(value);

                    BotService.SendATextResponse(message, MiscService.MakeGif(thisData.data.url));

                    replyToConversation.Attachments.Add(
                        new AnimationCard
                    {
                        Title     = thisData.data.title,
                        Subtitle  = "by @" + thisData.data.author + ". Perfect for " + thisData.data.link_flair_text.ToString().ToLower().Trim(),
                        Autostart = true,
                        Shareable = true,
                        Image     = new ThumbnailUrl
                        {
                            Url = thisData.data.thumbnail
                        },
                        Media = new List <MediaUrl>
                        {
                            new MediaUrl()
                            {
                                Url = MiscService.MakeGif(thisData.data.url), Profile = "image/gif"
                            }
                        },
                        Buttons = new List <CardAction>
                        {
                            new CardAction()
                            {
                                Title = "Learn More",
                                Type  = ActionTypes.OpenUrl,
                                Value = "https://peach.blender.org/"
                            }
                        }
                    }.ToAttachment()
                        );
                }

                return(replyToConversation);
            }
            catch (NullReferenceException nex)
            {
                System.Diagnostics.Trace.TraceError("GIF Recipes " + nex.Message);
                return(message.CreateReply("Apologies, we couldn't find any GIF recipes at this moment."));
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.TraceError("GIF Recipes " + e.Message);
                return(message.CreateReply("Apologies, we couldn't find any GIF recipes at this moment."));
            }
        }