private async Task SendRandomFileAsync(string path, string text) { try { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException(nameof(path)); } string file = _randomFile.Pick(path); await base.Context.Channel.SendFileAsync(file, text).ConfigureAwait(false); } catch (Exception ex) when(ex.LogAsError(this._log, "Exception when picking a random meme from path '{Path}'", path)) { await base.ReplyAsync("\u274C Failed sending meme, please contact the developers").ConfigureAwait(false); return; } }
public static string Pick(this IRandomFilePicker picker, string path, string searchPattern, bool recursive = true) => picker.Pick(path, searchPattern, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
public static string Pick(this IRandomFilePicker picker, string path, bool recursive = true) => picker.Pick(path, "*", true);