public async Task <GifResponseItem> GetGif(GifRequest request) { try { var apiKey = Environment.GetEnvironmentVariable("TENOR_API_KEY"); var result = await _gifClient.GetGif(apiKey, request); var random = new Random(); if (result?.Results == null || result.Results.Count() == 0) { return(null); } return(result.Results.ElementAt(random.Next(0, result.Results.Count()))); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } }
public async Task Gif([Remainder] string q) { try { var request = new GifRequest() { Q = q, ContentFilter = ContentFilter.Off }; var result = await _gifService.GetGif(request); if (string.IsNullOrEmpty(result?.Url)) { await ReplyAsync("I can't find a gif right now"); } await ReplyAsync(result.Url); } catch (Exception e) { Console.WriteLine(e.Message); } }