private async Task _popTrophyAsync(ScannerQueueItem item, Trophy trophy) { EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle(string.Format("🏆 Trophy unlocked!")); embed.WithDescription(string.Format("Congratulations {0}! You've earned the **{1}** trophy.", (await item.Context.Guild.GetUserAsync(item.UserId)).Mention, trophy.GetName())); embed.WithFooter(trophy.GetDescription()); embed.WithColor(new Color(255, 204, 77)); await item.Context.Channel.SendMessageAsync("", false, embed.Build()); }
private async Task _scanTrophiesAsync(ScannerQueueItem item) { // Get the trophies the user has already unlocked so we don't pop trophies that have already been popped. UnlockedTrophyInfo[] already_unlocked = await _trophy_registry.GetUnlockedTrophiesAsync(item.UserId); HashSet <string> already_unlocked_identifiers = new HashSet <string>(); foreach (UnlockedTrophyInfo info in already_unlocked) { already_unlocked_identifiers.Add(info.identifier); } // Check for new trophies that the user has just unlocked. foreach (Trophy trophy in await _trophy_registry.GetTrophiesAsync()) { try { if (!already_unlocked_identifiers.Contains(trophy.GetIdentifier()) && await trophy.IsUnlocked(item)) { // Insert new trophy into the database. await _trophy_registry.UnlockAsync(item.UserId, trophy); // Pop the new trophy. await _popTrophyAsync(item, trophy); } } // If an error occurs when checking a trophy, we'll just move on to the next one. catch (Exception ex) { await Bot.OurFoodChainBot.Instance.LogAsync(Discord.LogSeverity.Error, "Trophies", string.Format("Exception occured while checking \"{0}\" trophy: {1}", trophy.GetName(), ex.ToString() )); } } }