/// <summary> /// Sends a trivia question in a channel and awaits the correct answer. If someone does correctly answer, they are rewarded. /// </summary> /// <param name="channel">The channel to send the trivia question in.</param> /// <param name="dbGuild">The data information of the guild in question.</param> public async Task TriviaAsync(IMessageChannel channel, Guild dbGuild) { if (dbGuild.Trivia.ElementCount == 0) { throw new DEAException("There are no trivia questions yet!"); } var random = Config.RAND; int roll = random.Next(0, dbGuild.Trivia.ElementCount); var element = dbGuild.Trivia.GetElement(roll); var answer = element.Value.AsString.ToLower(); Predicate <IUserMessage> correctResponse = y => y.Content.ToLower() == answer; if (!answer.Any(char.IsDigit)) { if (answer.Length < 5) { correctResponse = y => y.Content.ToLower() == answer; } else if (answer.Length >= 5 && answer.Length < 10) { correctResponse = y => LevenshteinDistance.Compute(y.Content, element.Value.AsString) <= 1; } else if (answer.Length < 20) { correctResponse = y => LevenshteinDistance.Compute(y.Content, element.Value.AsString) <= 2; } else { correctResponse = y => LevenshteinDistance.Compute(y.Content, element.Value.AsString) <= 3; } } await channel.SendAsync("__**TRIVIA:**__ " + element.Name); var response = await _interactiveService.WaitForMessage(channel, correctResponse); if (response != null) { var user = response.Author as IGuildUser; var winnings = random.Next(Config.TRIVIA_PAYOUT_MIN * 100, Config.TRIVIA_PAYOUT_MAX * 100) / 100m; await _userRepo.EditCashAsync(user, dbGuild, await _userRepo.GetUserAsync(user), winnings); await channel.SendAsync($"{user.Boldify()}, Congrats! You just won {winnings.USD()} for correctly answering \"{element.Value.AsString}\"."); } else { await channel.SendAsync($"NOBODY got the right answer for the trivia question! Alright, I'll sauce it to you guys, but next time " + $"you are on your own. The right answer is: \"{element.Value.AsString}\"."); } }
public async Task TriviaAsync(IMessageChannel channel, Guild dbGuild) { if (dbGuild.Trivia.ElementCount == 0) { throw new FriendlyException("There are no trivia questions yet!"); } int roll = CryptoRandom.Next(dbGuild.Trivia.ElementCount); var element = dbGuild.Trivia.GetElement(roll); var answer = element.Value.AsString.ToLower(); Predicate <IUserMessage> correctResponse = y => y.Content.ToLower() == answer; if (!answer.Any(char.IsDigit)) { correctResponse = y => y.Content.SimilarTo(element.Value.AsString, 5, 10, 20); } await channel.SendAsync("__**TRIVIA:**__ " + element.Name); var response = await _interactiveService.WaitForMessage(channel, correctResponse); if (response != null) { var user = response.Author as IGuildUser; var winnings = CryptoRandom.NextDecimal(Config.MinTriviaPayout, Config.MaxTriviaPayout); await _userRepo.EditCashAsync(user, dbGuild, await _userRepo.GetUserAsync(user), winnings); await channel.SendAsync($"{user.Boldify()}, Congrats! You just won {winnings.USD()} for correctly answering \"{element.Value.AsString}\"."); } else { await channel.SendAsync($"NOBODY got the right answer for the trivia question! Alright, I'll sauce it to you guys, but next time " + $"you are on your own. The right answer is: \"{element.Value.AsString}\"."); } }
public static Task <IUserMessage> ReplyAsync(this IMessageChannel channel, IUser user, string description, string title = null, Color color = default(Color)) { return(channel.SendAsync($"{user.Boldify()}, {description}", title, color)); }
public static Task <IUserMessage> SendErrorAsync(this IMessageChannel channel, string message, string title = null) { return(channel.SendAsync(message, title, Config.ErrorColor)); }