示例#1
0
        public ImageCardData GetImageCardEvent(CommandSource source)
        {
            ImageCardData result = new ImageCardData()
            {
                Title       = $"Hey, {source.User}!",
                Description = "If any one of Chuck Norris' sextapes was ever released publicly, it would win the Best Picture Oscar",
                ImageUrl    = "https://assets.chucknorris.host/img/avatar/chuck-norris.png",
                Url         = "https://api.chucknorris.io/jokes/AONc06lISwSZVjqMW2gO3Q"
            };

            try
            {
                string json = this.GetPage().Result;

                if (!string.IsNullOrEmpty(json))
                {
                    JObject fact = JObject.Parse(json);
                    result.Title       = string.IsNullOrEmpty(source?.User) ? "Hey, you!" : $"Hey, {source.User}!";
                    result.Description = fact["value"]?.ToString() ?? string.Empty;
                    result.ImageUrl    = fact["icon_url"]?.ToString() ?? string.Empty;
                    result.Url         = fact["url"]?.ToString() ?? string.Empty;
                }
            }
            catch (Exception ex)
            {
                // external CommandHandler is catching exceptions
                throw;
            }

            return(result);
        }
示例#2
0
        public ImageCardData GetImageCardEvent(CommandSource source)
        {
            ImageCardData result = new ImageCardData()
            {
                Title       = "Rick Astley",
                Description = "Richard Paul Astley (Newton-le-Willows, 6 febbraio 1966) è un cantautore, musicista e conduttore radiofonico britannico.",
                ImageUrl    = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Rick_Astley_-_Pepsifest_2009.jpg/200px-Rick_Astley_-_Pepsifest_2009.jpg"
            };

            try
            {
                string json = this.GetPage().Result;

                if (!string.IsNullOrEmpty(json))
                {
                    JObject wikiPage = JObject.Parse(json);
                    result.Title       = wikiPage["displaytitle"]?.ToString() ?? string.Empty;
                    result.Description = wikiPage["extract"]?.ToString() ?? string.Empty;
                    result.ImageUrl    = wikiPage["thumbnail"]?["source"]?.ToString() ?? string.Empty;
                    result.Url         = wikiPage["content_urls"]?["desktop"]?["page"]?.ToString() ?? string.Empty;
                }
            }
            catch (Exception ex)
            {
                // external CommandHandler is catching exceptions
                throw;
            }

            return(result);
        }