public async Task SetPersonalImage([Remainder] string image = null) { image ??= Context.Message.Attachments.FirstOrDefault()?.Url; //to delete image if (image == null) { await ProfileDb.SetImage(Context.User.Id, null); await Context.Channel.SendMessageAsync("Image removed."); return; } //url check if (!WebUtil.IsValidUrl(image)) { await Context.Channel.SendMessageAsync("This URL is just like you... Invalid."); return; } //image validity check if (!WebUtil.IsImageUrl(image)) { await Context.Channel.SendMessageAsync("This URL is not an image, what do you want me to do with it?"); return; } //building embed await ProfileDb.SetImage(Context.User.Id, image); EmbedBuilder embed = UserUtil.QuoteEmbed(Context.User); await Context.Channel.SendMessageAsync("Image set!", false, embed.Build()); }
public async Task DownloadFiles(string path, int amount, int skip = 0, ulong channelId = 0) { await Context.Message.DeleteAsync(); var ch = channelId == 0 ? Context.Channel : (ISocketMessageChannel)Context.Client.GetChannel(channelId); var messages = await ch.GetMessagesAsync(amount, CacheMode.AllowDownload).FlattenAsync(); int total = 0; int downloaded = 0; foreach (var msg in messages.Skip(skip)) { if (msg.Type != MessageType.Default) { continue; } foreach (var attachment in msg.Attachments.Where(x => x.Height != null && x.Width != null)) { if (WebUtil.IsValidUrl(attachment.ProxyUrl)) { Task.Run(() => DownloadFile(attachment.ProxyUrl, path + @"\" + msg.Timestamp.UtcDateTime.ToString("yyyy-MM-dd_HHmm") + "_" + attachment.Filename)) .ContinueWith(x => { if (x.Result == true) { downloaded++; if (downloaded % 5 == 0) { Console.WriteLine("Downloaded: " + downloaded); } } }); total++; if (total % 50 == 0) { Console.WriteLine("Total: " + total); } } } foreach (var word in msg.Content.Split(' ')) { if (WebUtil.IsValidUrl(word) && WebUtil.IsImageUrl(word)) { Task.Run(() => DownloadFile(word, path + @"\" + msg.Timestamp.UtcDateTime.ToString("yyyy-MM-dd_HHmm") + "_" + word.Split(@"/").Last())) .ContinueWith(x => { if (x.Result == true) { downloaded++; if (downloaded % 5 == 0) { Console.WriteLine("Downloaded: " + downloaded); } } }); total++; if (total % 50 == 0) { Console.WriteLine("Total: " + total); } } } } Console.WriteLine("Total: " + total); }