Пример #1
0
        public async Task PostRaid(IMessageChannel channel, EpgpRaid raidObject)
        {
            if (!(channel is IGuildChannel guildChannel))
            {
                throw new ArgumentException("Raids can only be posted to server text channels");
            }

            var leader = await guildChannel.GetUserAsync(raidObject.RaidLeader);

            IMessageChannel leaderChannel;

            if (leader == null)
            {
                leaderChannel = channel;
            }
            else
            {
                leaderChannel = await leader.GetOrCreateDMChannelAsync();
            }
            var domainRaid = new Raid()
            {
                Id = Guid.NewGuid(), StartTime = raidObject.StartTime, EndTime = raidObject.StartTime + raidObject.Duration, Name = raidObject.Name
            };

            _dbContext.Raids.Add(domainRaid);
            _dbContext.SaveChanges();
            raidObject.RaidId = domainRaid.Id;
            var guildId = guildChannel.GuildId;
            var message = await channel.SendMessageAsync("", false, CreateEmbed(raidObject, guildChannel.GuildId), null);

            var raidData = new RaidData(message, raidObject, guildChannel.GuildId);

            raidData.LeaderChannel   = leaderChannel;
            _client.ReactionAdded   += ReactionAdded;
            _client.ReactionRemoved += ReactionRemoved;
            _aliasEventAlerter.ActiveAliasChanged += ActiveAliasChanged;
            await message.AddReactionAsync(Emote.Parse(_emoteService.GetFullyQualifiedName(guildId, EmbedConstants.CasterEmoteName)));

            await message.AddReactionAsync(Emote.Parse(_emoteService.GetFullyQualifiedName(guildId, EmbedConstants.MeleeEmoteName)));

            await message.AddReactionAsync(Emote.Parse(_emoteService.GetFullyQualifiedName(guildId, EmbedConstants.RangedEmoteName)));

            await message.AddReactionAsync(Emote.Parse(_emoteService.GetFullyQualifiedName(guildId, EmbedConstants.TankEmoteName)));

            await message.AddReactionAsync(Emote.Parse(_emoteService.GetFullyQualifiedName(guildId, EmbedConstants.HealerEmoteName)));

            await message.AddReactionAsync(new Emoji("❌"));

            using (var raidMonitor = await AddRaid(raidData))
            {
                await raidMonitor.Run();
            }
            await RemoveRaid(raidData);
        }
Пример #2
0
        private async Task <EpgpRaidMonitor> AddRaid(RaidData raidData)
        {
            var raidMonitor = _raidMonitorFactory.GetNew(raidData);

            raidData.RaidMonitor = raidMonitor;
            _raidRepository.AddOrUpdateRaid(raidData);
            while (_raidRepository.Count > MaxConcurrentRaids)
            {
                await RemoveRaid(_raidRepository.GetRaids().First());
            }

            return(raidMonitor);
        }
Пример #3
0
        private async Task RemoveRaid(RaidData raidData)
        {
            _raidRepository.RemoveRaid(raidData.Id);
            if (raidData.RaidObject.Participants.Values.All(p => p.Aliases.All(a => a.IsPrimary)))
            {
                return;
            }
            foreach (var participant in raidData.RaidObject.Participants.Values)
            {
                if (participant.Aliases.All(a => a.IsPrimary))
                {
                    continue;
                }
                _aliasService.SetActiveAlias(participant.Id, _aliasService.GetPrimaryAlias(participant.Id).Name);
            }

            await raidData.Message.Channel.SendMessageAsync("All users have been reset to their primary alias");
        }