public async Task ShowUrlsAsync(string key) { var config = Database.Load <AttachmentRandomConfig>(AttachmentRandomConfig.DocumentName(Context.Guild.Id, key)); if (config == null) { await ReplyAsync("Key not found."); return; } await ReplyAsync("", false, new EmbedBuilder() { Description = string.Join("\n", config.AttachmentUrls) }.Build()); }
public async Task AddFileAsync(string key) { if (!Context.Message.Attachments.Any(x => x.Size / 1024 / 1024 <= 8)) { await ReplyAsync("You must attach a file when using this command and ensure that it is less than 8mb in size."); return; } var config = Database.Load <AttachmentRandomConfig>(AttachmentRandomConfig.DocumentName(Context.Guild.Id, key)); if (config == null) { config = new AttachmentRandomConfig(Context.Guild.Id, key); } config.AttachmentUrls.AddRange(Context.Message.Attachments.Where(x => x.Size / 1024 / 1024 <= 8).Select(x => x.Url).ToArray()); Database.Store(config, AttachmentRandomConfig.DocumentName(Context.Guild.Id, key)); await ReplyAsync("Attachment(s) added."); }
public async Task RemoveFilesAsync(string key, [Remainder] string url) { var config = Database.Load <AttachmentRandomConfig>(AttachmentRandomConfig.DocumentName(Context.Guild.Id, key)); if (config == null) { await ReplyAsync("Key not found."); return; } config.AttachmentUrls.RemoveAll(n => n.Equals(url, StringComparison.InvariantCultureIgnoreCase)); if (config.AttachmentUrls.Count == 0) { Database.Remove <AttachmentRandomConfig>(AttachmentRandomConfig.DocumentName(Context.Guild.Id, key)); await ReplyAsync("Cleared Document."); return; } Database.Store(config, AttachmentRandomConfig.DocumentName(Context.Guild.Id, key)); await ReplyAsync("Removed attachment."); }
public async Task GetImageAsync(string key) { var config = Database.Load <AttachmentRandomConfig>(AttachmentRandomConfig.DocumentName(Context.Guild.Id, key)); if (config == null) { await ReplyAsync("Key not found."); return; } var selection = config.AttachmentUrls.OrderBy(x => Random.Next()).FirstOrDefault(); var response = await Client.GetAsync(selection); if (!response.IsSuccessStatusCode) { await ReplyAsync($"Error, attachment <{selection}> not found."); return; } var contentDir = selection.LastIndexOf("\\"); if (contentDir != -1) { selection = selection.Substring(contentDir); } using (var stream = await response.Content.ReadAsStreamAsync()) { await Context.Channel.SendFileAsync(stream, selection); } if (Context.Guild.CurrentUser.GuildPermissions.ManageMessages) { await Context.Message.DeleteAsync(); } }
public async Task RemoveFilesAsync(string key) { if (!Context.Message.Attachments.Any(x => x.Size / 1024 / 1024 <= 8)) { await ReplyAsync("You must attach a file when using this command and ensure that it is less than 8mb in size."); return; } var configExists = Database.Exists <AttachmentRandomConfig>(AttachmentRandomConfig.DocumentName(Context.Guild.Id, key)); if (configExists == false) { await ReplyAsync("Unknown key."); return; } else { Database.Remove <AttachmentRandomConfig>(AttachmentRandomConfig.DocumentName(Context.Guild.Id, key)); } await ReplyAsync("Cleared Document."); }