public async Task Command([Remainder] string text) { Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id); IEnumerable <Quote> quotes = server.Quotes; int quoteCount = quotes?.Count() ?? 0; if (quoteCount > 0) { if (server.Quotes.Any(x => x.Text.Equals(text))) { var cEmbed = new KaguyaEmbedBuilder(EmbedColor.YELLOW) { Description = "A quote with the same text already exists. Do you want to create this one anyway?" }; var data = new ReactionCallbackData("", cEmbed.Build(), true, true, TimeSpan.FromSeconds(120)); data.AddCallBack(GlobalProperties.CheckMarkEmoji(), async(c, r) => { await InsertQuote(Context, server, text); }); data.AddCallBack(GlobalProperties.NoEntryEmoji(), async(c, r) => { await SendBasicErrorEmbedAsync("Okay, no action will be taken."); }); await InlineReactionReplyAsync(data); return; } } await InsertQuote(Context, server, text); }
// if the user supplies a tagname that doesn't exist, search the database to see if there are // any tags containing the user-supplied text // if there are any results from the database, post a list of the results & add emoji reactions // corresponding to each item in the list // when the user selects a emoji, it will pass the corresponding tagName and any extra passed // parameters to the RetryCommandUsingFoundTag function // afterwards, save a pairing of the calling user object and the searchResults message into a // dictionary, for use by the RetryCommandUsingFoundTag function private async Task FindTagAndRetry(string functionToRetry, params string[] args) { var tagName = args[0]; var searchResponse = await DatabaseTags.SearchTagsInDatabase(Context, tagName); // if single result, just use that if (searchResponse.Count == 1) { await RetryCommandUsingFoundTag(searchResponse[0], functionToRetry, args); return; } // if the single-result check didn't catch but there are results if (searchResponse.Any()) { string[] numbers = new[] { "0⃣", "1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣" }; var numberEmojis = new List <Emoji>(); EmbedBuilder embedBuilder = new EmbedBuilder(); StringBuilder stringBuilder = new StringBuilder(); // add the number of emojis we need to the emojis list, and build our string-list of search results for (int i = 0; i < searchResponse.Count && i < numbers.Length; i++) { numberEmojis.Add(new Emoji(numbers[i])); stringBuilder.AppendLine($"{numbers[i]} - {searchResponse[i]}"); } embedBuilder.WithDescription(stringBuilder.ToString()); embedBuilder.WithColor(Color.Blue); // build a message and add reactions to it // reactions will be watched, and the one selected will fire the HandleFindTagReactionResult method, passing // that reaction's corresponding tagname and the function passed into this parameter var messageContents = new ReactionCallbackData("Did you mean... ", embedBuilder.Build()); for (int i = 0; i < searchResponse.Count; i++) { var counter = i; messageContents.AddCallBack(numberEmojis[counter], (c, r) => RetryCommandUsingFoundTag(searchResponse[counter], functionToRetry, args)); } var message = await InlineReactionReplyAsync(messageContents); // add calling user and searchResults embed to a dict as a pair // this way we can hold multiple users' reaction messages and operate on them separately _dictFindTagUserEmbedPairs.Add(Context.User, message); } else { await ReplyAsync("I can't find any tags like what you're looking for."); } }
public async Task Command() { User user = await DatabaseQueries.GetOrCreateUserAsync(Context.User.Id); Reminder[] reminders = user.Reminders.Where(x => x.Expiration > DateTime.Now.ToOADate()).ToArray(); var embed = new KaguyaEmbedBuilder(); int i = 0; if (!(reminders.Length == 0)) { foreach (Reminder reminder in reminders) { i++; string expirationStr = DateTime.FromOADate(reminder.Expiration).Humanize(false); var fSb = new StringBuilder(); fSb.AppendLine($"Reminder: `{reminder.Text}`"); fSb.AppendLine($"Expires: `{expirationStr}`"); var field = new EmbedFieldBuilder { IsInline = false, Name = $"#{i}", Value = fSb.ToString() }; embed.AddField(field); } embed.Footer = new EmbedFooterBuilder { Text = "To delete a reminder, click the corresponding reaction." }; } else { var field = new EmbedFieldBuilder { Name = "No reminders active", Value = "You currently don't have any active reminders." }; embed.AddField(field); } int j = 0; var data = new ReactionCallbackData("", embed.Build()); foreach (Reminder reminder in reminders) { data.AddCallBack(GlobalProperties.EmojisOneThroughNine()[j], async(c, r) => { await DatabaseQueries.DeleteAsync(reminder); await ReplyAsync($"{Context.User.Mention} Successfully deleted reminder #{j}."); }); j++; } await InlineReactionReplyAsync(data); }