コード例 #1
0
        private async Task <string> GetJoke(string message)
        {
            var joke = await
                       _jokeService.GetJokeAsync(message)
                       .ConfigureAwait(false);

            return(joke.Value);
        }
コード例 #2
0
        public async void AddJokeAsync()
        {
            try
            {
                if (!string.IsNullOrEmpty(url))
                {
                    Scroll = ScrollEnum.Scroll;
                    var actualCategory = (Category == 0) ? (CategoryEnum)random.Next(1, 16) : Category;

                    var joke = await _jokeService.GetJokeAsync(url, actualCategory.ToString().ToLower()); //if category is "All", select random one

                    if (joke != null)
                    {
                        int id = 1;

                        if (JokeList.Count > 0)
                        {
                            id = JokeList.Last().Id + 1;
                        }

                        var jokeItem = new JokeItem
                        {
                            Id       = id,
                            Icon     = iconUrl,
                            Joke     = joke.value,
                            Url      = new Uri(joke.url),
                            RestId   = joke.icon_url,
                            Category = actualCategory
                        };

                        JokeList.Add(jokeItem);
                        UpdateBindedCollection();

                        if (Device.RuntimePlatform == Device.Android || Device.RuntimePlatform == Device.UWP)
                        {
                            await _databaseService.AddJoke(jokeItem);
                        }
                    }
                    else
                    {
                        _toastMessage.ShowToast(commonErrorMessage);
                    }
                }
                else
                {
                    _toastMessage.ShowToast(apiErrorMessage);
                }
            }
            catch { _toastMessage.ShowToast(commonErrorMessage); }
        }
コード例 #3
0
        public async Task <ActionResult> Random([FromForm] SlackCommandRequest request)
        {
            // if (await request.IsValidAsync(Request, _slackOptions.SigningSecret))
            // {
            //     return new UnauthorizedResult();
            // }

            var response = await _jokeService.GetJokeAsync();

            return(new JsonResult(new
            {
                response_type = request.Text == "share" ? "in_channel" : "ephemeral",
                text = response.Value.Joke,
                attachments = new[]
                {
                    new { text = _jokeService.GetRandomJokeEmoji() }
                }
            }));
        }
コード例 #4
0
 public async Task <ActionResult <JokeResponse> > GetJokeAsync()
 {
     return(await _jokeService.GetJokeAsync());
 }