public void AddQuoteWithAdd() { int quoteSize = Quotes.QuotesList.Count; Quotes.AddQuote("add <Me> Quote with 'add'"); Assert.Equal("<Me> Quote with 'add'", Quotes.PrintQuote("#" + (quoteSize + 1))); }
public void AddQuoteWithoutAdd() { int quoteSize = Quotes.QuotesList.Count; Quotes.AddQuote("<Me> Second quote"); Assert.Equal("<Me> Second quote", Quotes.PrintQuote("#" + (quoteSize + 1))); }
public async Task QuoteAdd(CommandContext ctx, [RemainingText] string arg) { logger.Info("Quote Add Command", Useful.GetDiscordName(ctx)); if (!string.IsNullOrWhiteSpace(arg)) { Quotes.AddQuote(arg); await ctx.RespondAsync("Quote added").ConfigureAwait(false); } }
[Description("Show or add quotes. Add argument \"add\" after the command to add quote. If a different argument is used it will perform a search. If no arguments are shown, a random quote is shown")] // this will be displayed to tell users what this command does when they invoke help public async Task Quote(CommandContext ctx, [RemainingText] string arg) { logger.Info("Quote Command", Useful.GetDiscordName(ctx)); if (arg != null && string.Compare(arg.Split(new char[] { ' ' }, 2)[0], "add", StringComparison.OrdinalIgnoreCase) == 0) // add { Quotes.AddQuote(arg); await ctx.RespondAsync("Quote added").ConfigureAwait(false); } else // lookup or random { await ctx.RespondAsync(Quotes.PrintQuote(arg)).ConfigureAwait(false); } }
[Aliases("q")] // alternative names for the command public async Task Quote(CommandContext ctx) { Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss] ", CultureInfo.CreateSpecificCulture("en-GB")) + "Quote Command"); string arg; try { arg = ctx.Message.Content.Split(new char[] { ' ' }, 2)[1]; } catch (IndexOutOfRangeException) { arg = string.Empty; } if (string.Compare(arg.Split(new char[] { ' ' }, 2)[0], "add", StringComparison.OrdinalIgnoreCase) == 0) //add { Quotes.AddQuote(arg); } else //lookup or random { string result = Quotes.PrintQuote(arg); await ctx.RespondAsync(result).ConfigureAwait(false); } }
public async Task GetQuote(params string[] args) { if (args.Length == 0) { await ReplyAsync(Quotes.GetRandomQuote(random).GetFormattedQuote()); } else if (args[0] == "add") { if (args.Length > 2) { string name = args.BuildName(1, args.Length - 2).ToLower(); string text = args[args.Length - 1]; Quote quote = new Quote(name, text); if (!Quotes.QuoteExists(quote)) { Quotes.AddQuote(quote); await ReplyAsync("Added quote."); } else { await ReplyAsync("Quote already exists."); } } else { await ReplyAsync("You need to say which character said the quote ya silly doofus " + Context.User.Mention); } } else if (args[0] == "count") { await ReplyAsync(string.Format("There are {0} quotes stored.", Quotes.GetQuoteCount())); } else if (args[0] == "characters") { List <string> characters = Quotes.GetCharacters(); if (characters.Count > 0) { StringBuilder builder = new StringBuilder(); builder.Append(string.Format("Characters with quotes:{0}", Environment.NewLine)); foreach (string character in characters) { builder.Append(string.Format("{0}{1}", character.ToTitleCase(), Environment.NewLine)); } await ReplyAsync(builder.ToString()); } else { await ReplyAsync("There are currently no characters with quotes."); } } else if (args[0] == "list") { string name = args.BuildName(1, args.Length - 1).ToLower(); List <Quote> quotes = Quotes.GetCharacterQuotes(name); if (quotes.Count > 0) { StringBuilder builder = new StringBuilder(); builder.Append(string.Format("Quotes attributed to {0}:{1}", name.ToTitleCase(), Environment.NewLine)); int i = 1; foreach (Quote quote in quotes) { string line = string.Format("{0} - {1}{2}", i, quote.Text, Environment.NewLine); if (builder.Length + line.Length <= 2000) { builder.Append(line); } else { await ReplyAsync(builder.ToString()); builder = new StringBuilder(); } i++; } await ReplyAsync(builder.ToString()); } else { await ReplyAsync(string.Format("{0} has no quotes.", name.ToTitleCase())); } } else if (args[0] == "remove") { string name = args.BuildName(1, args.Length - 2).ToLower(); int index = int.Parse(args[args.Length - 1]) - 1; try { Quote quote = Quotes.GetQuote(name, index); Quotes.RemoveQuote(name, index); Quotes.SaveQuotes(); await ReplyAsync(string.Format("Quote removed from {0}: \"{1}\"", name, quote.Text)); } catch (ArgumentOutOfRangeException) { await ReplyAsync("Invalid quote number."); } } else { if (int.TryParse(args.Last(), out int index)) { string name = args.BuildName(0, args.Length - 2).ToLower(); index -= 1; try { await ReplyAsync(Quotes.GetQuote(name, index).GetFormattedQuote()); } catch (ArgumentOutOfRangeException) { await ReplyAsync(string.Format("{0} has no quote at index {1}.", name.ToTitleCase(), index)); } } else { string name = args.BuildName().ToLower(); List <Quote> quotes = Quotes.GetCharacterQuotes(name); if (quotes.Count > 0) { Quote quote = quotes[random.Next(quotes.Count)]; if (quote != null) { await ReplyAsync(quote.GetFormattedQuote()); } } else { await ReplyAsync(string.Format("{0} has no quotes.", name.ToTitleCase())); } } } }