private async Task ReactionManipulated(SocketReaction reaction, ReactionAction action) { if (reaction.User.Value.IsBot) { return; } if (!_raidRepository.Contains(reaction.MessageId)) { return; } if (!_userService.UserExists(reaction.UserId) && !(await _userService.TryAddUser(reaction.UserId, (reaction.Channel as IGuildChannel)?.Guild))) { return; } var raid = _raidRepository.GetRaid(reaction.MessageId); if (!(reaction.User.Value is IGuildUser)) { return; } var aliases = _aliasService.GetActiveAliases(reaction.UserId).ToList(); if (!aliases.Any()) { return; } var aliasViewModels = _mapper.Map <List <EpgpAlias>, List <EpgpAliasViewModel> >(aliases); var role = reaction.Emote.Name.ParseRoleFromEmote(); var participant = new RaidParticipant(reaction.UserId) { Aliases = aliasViewModels, Role = role }; if (action == ReactionAction.Add) { raid.RaidObject.Participants.AddOrUpdate(participant.Id, id => participant, (id, raidParticipant) => participant); } else if (action == ReactionAction.Remove) { if (raid.RaidObject.Participants.TryGetValue(reaction.UserId, out var existingParticipant) && existingParticipant.Role == participant.Role) { raid.RaidObject.Participants.TryRemove(reaction.UserId, out _); } } var embed = CreateEmbed(raid.RaidObject, raid.ServerId); await raid.Message.ModifyAsync(opt => opt.Embed = embed); }
public void Gp(EpgpAlias alias, Item item, string memo, int overrideGpValue = -1) { var gpValue = overrideGpValue == -1 ? _epgpCalculator.CalculateItem(item, alias.Class == Class.Hunter, false) : overrideGpValue; var rounded = (int)Math.Round(gpValue, MidpointRounding.AwayFromZero); var raid = _raidRepository.GetRaid(); if (raid == null) { Gp(alias, rounded, memo, TransactionType.GpFromGear); return; } var transaction = _epgpTransactionFactory.GetTransaction(alias, (int)Math.Round(gpValue, MidpointRounding.AwayFromZero), memo, TransactionType.GpFromGear); _dbContext.EpgpTransactions.Add(transaction); alias.Transactions.Add(transaction); alias.GearPoints += transaction.Value; var raidData = _dbContext.Raids.Include(r => r.Loot).First(r => r.Id == raid.RaidObject.RaidId); var raidItem = new RaidItem { Id = Guid.NewGuid(), AwardedAliasId = alias.Id, ItemId = item.Id, RaidId = raidData.Id, TransactionId = transaction.Id }; _dbContext.RaidItems.Add(raidItem); _dbContext.SaveChanges(); }