Ejemplo n.º 1
0
        private async Task HandleRaidSignupAsync(ReactionAddedEventArgs e)
        {
            if (!GetClassNames().Contains(e.Emoji.Name))
            {
                return;
            }
            if (e.User.Id == 668648526431125505 || e.User.Id == CurrentUser.Id)
            {
                return;
            }
#if DEBUG
            if (e.User.Id != 89613772372574208)
            {
                return;
            }
#else
            if (e.Channel.Id == 793661221861064715)
            {
                return;
            }
#endif
            var dbContext = this.GetRequiredService <AbfDbContext>();

            var msg = await e.Message.FetchAsync() as RestUserMessage;

            await using (dbContext)
            {
                var(check, raid, user, character) = await CheckForRaidAsync(e.Message.Id.RawValue, e.User.Id.RawValue, e.Emoji.Name, dbContext);

                if (!check)
                {
                    if (character is null)
                    {
                        var reactionUser = await e.User.FetchAsync();

                        await e.Channel.SendMessageAsync($"{reactionUser.Mention}, I didn't find a {e.Emoji.Name} character for you. Please add a character with the `!character add` command. Example: `!character add Gnomeorpuns Mage Ranged`. Do `!help character add` for full command information.");
                    }
                    await msg.RemoveMemberReactionAsync(e.User.Id, e.Emoji);

                    return;
                }

                if (raid.Participants.Any(p => p.CharacterId == character.Id))
                {
                    return;
                }

                var participant = new RaidParticipant {
                    Character = character, Raid = raid, SignedUpAt = DateTimeOffset.UtcNow
                };

                raid.Participants.Add(participant);
                dbContext.Update(raid);

                await dbContext.SaveChangesAsync();

                await WowRaidModule.CreateRaidEmbedAsync(msg, raid);
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public async Task SignupToRaidAsync(RaidParticipant raidParticipant)
 {
     var raid = await _raids.GetAsync(raidParticipant.RaidId);
 }