示例#1
0
        public async Task OnMessage(SocketMessage message)
        {
            if (message.Author.IsBot)
            {
                return;
            }

            var guildChannel = message.Channel as SocketGuildChannel;

            if (guildChannel is null)
            {
                return;
            }

            var guild = _guildRepo.Get(guildChannel.Guild.Id);

            if (guild == null)
            {
                return;
            }


            if (message.Content.StartsWith(guild.Settings.Prefix))
            {
                await HandleCommand(guild, message);

                return;
            }

            if (guild.AutoResponses.ContainsKey(message.Content))
            {
                await message.Channel.SendMessageAsync(guild.AutoResponses[message.Content]);
            }
        }
示例#2
0
        public async Task <Guild> Create(Guid id, String name, GuildStatus status, RecruitmentStatus recruitmentStatus, CancellationToken cancellationToken)
        {
            var guild = await _repository.Get(id, cancellationToken);

            if (guild != null)
            {
                if (guild.Name == name)
                {
                    return(guild);
                }
                throw new GuildAlreadyExistsException($"Гильдия {id} уже существует");
            }

            return(new Guild(id: id, name: name, status: status, recruitmentStatus: recruitmentStatus));
        }
示例#3
0
        public async Task <IActionResult> SetOrUpdateGuildTax(
            [FromBody] UpdateUserRoleBinding binding,
            [FromRoute] GamerRank rank,
            [FromServices] IGuildRepository guildRepository,
            CancellationToken cancellationToken)
        {
            var guild = await guildRepository.Get(HttpContext.GetGuildId(), cancellationToken);

            if (guild == null)
            {
                throw new ApiException(HttpStatusCode.NotFound, ErrorCodes.GuildNotFound, "Guild not found");
            }

            guild.AddOrUpdateRole(rank, binding.Tariff.LoanTax, binding.Tariff.ExpiredLoanTax, binding.Tariff.Tax);

            guildRepository.Save(guild);

            return(Ok(new { }));
        }
示例#4
0
        public GuildQuery Guild(string authKey, string name)
        {
            if (!_apiRepository.ValidateAuthKey(authKey))
            {
                return(new GuildQuery()
                {
                    StatusCode = HttpStatusCode.Unauthorized,
                    Guilds = new List <Guild>()
                    {
                        new Guild()
                        {
                            Name = "Unauthorized"
                        }
                    }
                });
            }

            var returnValue = new GuildQuery();
            var guild       = _guildRepository.Get(name);

            if (guild == null)
            {
                returnValue.Guilds.Add(new Guild()
                {
                    Id     = 0,
                    Name   = "GuildNotFound",
                    Shard  = "N/A",
                    Region = "N/A"
                });
            }
            else
            {
                returnValue.Guilds.Add(new Guild()
                {
                    Id     = guild.Id,
                    Name   = guild.Name,
                    Shard  = guild.Shard.Name,
                    Region = guild.Shard.Region
                });
            }
            return(returnValue);
        }
        public ActionResult Guild(int id = -1, int d = -1, int g = -1)
        {
            #region Validation
            if (id == -1)
            {
                return(View("InvalidResource", model: "bossfight"));
            }

            var difficulty = _difficultyRepository.GetDefaultDifficulty();
            if (difficulty == null)
            {
                return(View("InvalidResource", model: "encounter difficulty"));
            }

            if (d != -1)
            {
                var overrideDifficulty = _difficultyRepository.Get(d);
                if (overrideDifficulty != null)
                {
                    difficulty = overrideDifficulty;
                }
            }

            var bossFight = _bossFightRepository.Get(id);
            if (bossFight == null)
            {
                return(View("InvalidResource", model: "bossfight"));
            }

            var guild = _guildRepository.Get(g);
            if (guild == null)
            {
                return(View("InvalidResource", model: "guild"));
            }

            // Privacy
            if (!Request.IsAuthenticated && guild.HideFromRankings)
            {
                return(View("GuildPrivate"));
            }
            if (guild.HideFromRankings)
            {
                bool sameGuild = false;
                // Check we have a valid user
                var user = _authRepository.GetUserAccount(User.Identity.GetUserId());
                if (user == null)
                {
                    HttpContext.GetOwinContext().Authentication.SignOut();
                    return(RedirectToAction("Index", "Home"));
                }

                // Get the characters for this user
                var userCharacters = _authUserCharacterRepository.GetCharacters(user.Email);
                if (userCharacters.Any(c => c.GuildId == guild.Id) || User.IsInRole(UserGroups.Admin))
                {
                    sameGuild = true;
                }

                if (!sameGuild)
                {
                    return(View("GuildPrivate"));
                }
            }

            #endregion

            var model = new GuildRecords()
            {
                GuildName = guild.Name,
                // Fight related
                BossFight  = bossFight,
                Difficulty = difficulty,
                // General, not guild related
                SingleFastestKill = _encounterRepository.GetFastestKills(id, difficulty.Id).FirstOrDefault(), // Fix this later - use the method that only returns one

                // Player-based
                SingleTopAps = _recordsRepository.GetSingleTopAps(id, difficulty.Id),
                SingleTopDps = _recordsRepository.GetSingleTopDps(id, difficulty.Id),
                SingleTopHps = _recordsRepository.GetSingleTopHps(id, difficulty.Id),
                // Guild-based
                SingleTopApsGuild = _recordsRepository.GetSingleTopApsGuild(id, difficulty.Id),
                SingleTopDpsGuild = _recordsRepository.GetSingleTopDpsGuild(id, difficulty.Id),
                SingleTopHpsGuild = _recordsRepository.GetSingleTopHpsGuild(id, difficulty.Id),
                // This guild-related
                GuildHybridXpsOverTimeChart = _recordCharts.GuildHybridXpsOverTime(id, difficulty.Id, g, guild.Name, bossFight.Name),
                GuildDurationOverTimeChart  = _recordCharts.GetEncounterDurationOverTime(id, difficulty.Id, g, guild.Name, bossFight.Name),
                GuildTopDps            = _recordsRepository.GetTopGuildDps(id, g, difficulty.Id),
                GuildTopHps            = _recordsRepository.GetTopGuildHps(id, g, difficulty.Id),
                GuildTopAps            = _recordsRepository.GetTopGuildAps(id, g, difficulty.Id),
                PlayerDpsOverTimeChart = _recordCharts.GuildPlayerXpsOverTime(id, difficulty.Id, guild.Id, guild.Name, bossFight.Name, "DPS", 20),
                PlayerHpsOverTimeChart = _recordCharts.GuildPlayerXpsOverTime(id, difficulty.Id, guild.Id, guild.Name, bossFight.Name, "HPS", 20),
                PlayerApsOverTimeChart = _recordCharts.GuildPlayerXpsOverTime(id, difficulty.Id, guild.Id, guild.Name, bossFight.Name, "APS", 20),
            };

            if (System.IO.File.Exists(Server.MapPath(string.Format("~/Content/images/portrait/{0}.png", bossFight.PortraitFilename))))
            {
                model.LoadImage = true;
            }

            return(View(model));
        }
示例#6
0
        // GET: Guild/1
        public ActionResult Index(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var guild = _guildRepository.Get((int)id);

            if (guild == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var guildCounts = _guildRepository.GetGuildIndexCounts(guild.Id);

            var model = new GuildIndexVM
            {
                Guild      = guild,
                Members    = guildCounts.MemberCount,
                Sessions   = guildCounts.SessionCount,
                Encounters = guildCounts.EncounterCount,
                GuildRank  = new GuildRank(),
                //BossFightProgressionOld = GetBossFightProgression(guild.Id), // Soon to be removed
                BossFightProgression = _guildRepository.GetGuildProgression(guild.Id),
                // We are checking roster visibility on the view, so get the member list here
                MemberList = _authUserCharacterRepository.GetGuildMembers(guild.Id)
            };


            // Check whether we're able to display the link to the guild sessions, or whether they are private
            if (guild.HideSessions)
            {
                if (!Request.IsAuthenticated)
                {
                    model.CanLinkToSessions = false;
                }
                else
                {
                    var user = _authRepository.GetUserAccount(User.Identity.GetUserId());
                    if (user == null)
                    {
                        HttpContext.GetOwinContext().Authentication.SignOut();
                        return(RedirectToAction("Index", "Home"));
                    }

                    model.CanLinkToSessions = model.MemberList.Any(gm => gm.AuthUserId == user.Id);
                }
            }
            else
            {
                model.CanLinkToSessions = true;
            }



            // If the request has been authenticated, check whether the user is valid
            if (Request.IsAuthenticated)
            {
                string email = User.Identity.GetUserId();

                var user = _authRepository.GetUserAccount(email);
                if (user == null)
                {
                    HttpContext.GetOwinContext().Authentication.SignOut();
                    return(RedirectToAction("Index", "Home"));
                }

                // So we have a valid user - are they an approved part of this guild? Also, approve global admins
                if (User.IsInRole(UserGroups.Admin))
                {
                    if (!guild.Status.Approved)
                    {
                        model.CanBeApproved = true;
                    }
                    model.CanBeRemoved = true;
                }

                var member = _authUserCharacterRepository.GetCharacterWithHighestGuildRank(user.Id, guild.Id);
                if (member != null)
                {
                    model.IsMember  = true;
                    model.GuildRank = member.GuildRank;

                    // We're checking roster visibility on the view, so this has been moved further up the method
                    //model.MemberList = _authUserCharacterRepository.GetGuildMembers(guild.Id);
                    model.AvailableRanks = _guildRankRepository.GetRanks();
                    model.CurrentUserId  = user.Id;

                    if (member.GuildRank.CanApproveUsers)
                    {
                        model.Applications = _authUserCharacterGuildApplicationRepository.PendingApplications(guild.Id);
                    }
                }
                else if (User.IsInRole(UserGroups.Admin))                                             // Allow admins to administrate any guild
                {
                    model.IsMember = true;                                                            // Required to see members and applications
                    //model.MemberList = _authUserCharacterRepository.GetGuildMembers(guild.Id);
                    model.AvailableRanks = _guildRankRepository.GetRanks();                           // Get the list of ranks
                    model.Applications   = _authUserCharacterGuildApplicationRepository.PendingApplications(guild.Id);
                    model.GuildRank      = model.AvailableRanks.OrderBy(r => r.RankPriority).First(); // Assign the admin the top rank
                }
            }

            // Go through the list of members and make sure that if the current user is a member, that they can't
            // accidentally remove their own permissions
            foreach (var member in model.MemberList)
            {
                member.CanBeModified = member.AuthUserId != model.CurrentUserId;
            }

            return(View(model));
        }
        public ActionResult Detail(int?id, bool debug = false)
        {
            #region Validation
            if (id == null)
            {
                return(RedirectToAction("InvalidSession"));
            }
            var sessionId = (int)id;
            var session   = _sessionRepository.Get(sessionId);
            if (session == null)
            {
                return(RedirectToAction("InvalidSession"));
            }
            #endregion
            var encounters = _sessionRepository.GetEncounters(sessionId, false);
            var log        = _sessionLogRepository.GetFirstSessionLogForSession(sessionId);
            var uploaders  = _sessionLogRepository.GetUploadersForSession(sessionId);

            var model = new SessionDetailVM()
            {
                FirstLog                = log,
                Session                 = session,
                Encounters              = encounters,
                CanBeRemoved            = false,
                DebugMode               = debug,
                Uploaders               = uploaders,
                OriginalUploaderGuildId = 0
            };

            Guild uploaderGuild = _guildRepository.Get(session.AuthUserCharacter.GuildId);
            model.OriginalUploaderGuildId = uploaderGuild.Id;
            if (!Request.IsAuthenticated && uploaderGuild.HideSessions)
            {
                return(View("Private", model: "session"));
            }

            bool sameGuild        = false;
            bool canModifyPrivacy = false;

            if (Request.IsAuthenticated)
            {
                // Check we have a valid user
                var user = _authRepository.GetUserAccount(User.Identity.GetUserId());
                if (user == null)
                {
                    HttpContext.GetOwinContext().Authentication.SignOut();
                    return(RedirectToAction("Index", "Home"));
                }
                model.TimeZoneId = user.TimeZone;

                // Get the characters for this user
                var userCharacters = _authUserCharacterRepository.GetCharacters(user.Email);
                if (userCharacters.Any(c => c.GuildId == uploaderGuild.Id))
                {
                    sameGuild = true;
                    // Update the ranks from the DB
                    foreach (var character in userCharacters)
                    {
                        if (character.GuildId != null)
                        {
                            character.GuildRank = _authUserCharacterRepository.GetGuildRankForCharacter(character.Id);
                        }
                    }
                    // This user has one or more characters in this guild, so check if they are the original uploader or have a rank that allows modifications
                    if (userCharacters.Where(c => c.GuildId == uploaderGuild.Id).Any(userChar => userChar.GuildRank.CanModifyAnySession || userChar.Id == session.AuthUserCharacterId))
                    {
                        model.CanBeRenamed = true;
                        model.CanBeRemoved = true;
                        canModifyPrivacy   = true;
                    }
                }
                else
                {
                    // This user doesn't have a character in the guild
                    if (uploaderGuild.HideSessions)
                    {
                        // This user doesn't have a character in this guild, sessions are hidden
                        if (!User.IsInRole(UserGroups.Admin))
                        {
                            return(View("Private", model: "session"));
                        }
                    }
                }

                if (User.IsInRole(UserGroups.Admin))
                {
                    model.CanBeReimported = true;
                    model.CanBeRenamed    = true;
                    model.CanBeRemoved    = true;
                    sameGuild             = true;
                }
            }

            // Loop through the encounters and set UI-specific values (that aren't in the DB)
            foreach (var encounter in encounters)
            {
                //encounter.AverageDps = _mainRepository.GetAverageDpsFromEncounterOverview(encounter.Id);
                if (encounter.Overview == null)
                {
                    encounter.AverageDps = _encounterRepository.GetEncounterDps(encounter.Id,
                                                                                (int)encounter.Duration.TotalSeconds);
                    encounter.AverageHps = _encounterRepository.GetEncounterHps(encounter.Id,
                                                                                (int)encounter.Duration.TotalSeconds);
                    encounter.AverageAps = _encounterRepository.GetEncounterAps(encounter.Id,
                                                                                (int)encounter.Duration.TotalSeconds);
                    encounter.PlayerDeaths = _encounterRepository.GetTotalPlayerDeaths(encounter.Id);

                    // Update these overviews
                    _encounterOverviewRepository.Add(new EncounterOverview
                    {
                        AverageDps   = encounter.AverageDps,
                        AverageHps   = encounter.AverageHps,
                        AverageAps   = encounter.AverageAps,
                        PlayerDeaths = encounter.PlayerDeaths,
                        EncounterId  = encounter.Id
                    });
                }
                else
                {
                    encounter.AverageDps   = encounter.Overview.AverageDps;
                    encounter.AverageHps   = encounter.Overview.AverageHps;
                    encounter.AverageAps   = encounter.Overview.AverageAps;
                    encounter.PlayerDeaths = encounter.Overview.PlayerDeaths;
                }
                encounter.IsViewable       = sameGuild || encounter.IsPublic;
                encounter.CanModifyPrivacy = canModifyPrivacy;
            }

            return(View(model));
        }