Shows a random image within your chosen category.
README
Very simple usage. Simply save the skill as is and run “@abbot show cats” or “@abbot show donkeys” or whatever you want to see an image of. If the image exists, you’ll get one back. If not, you’ll feel some rejection.
Code
try{
var response = await Bot.Http.GetJsonAsync($”http://www.reddit.com/r/{command}.json?sort=top&t=week”);
IEnumerable<dynamic> children = response.data.children;
var images = children.Where(child => !(bool)(child.data.is_self)).ToList();
var rnd = new Random();
await Bot.ReplyAsync(images.Skip(rnd.Next(images.Count – 1)).Take(1).Select(image => (string)image.data.url + “”).FirstOrDefault() ?? $”No {command} for you.”);
}
catch{
await Bot.ReplyAsync($”No {command} for you.”);
}