Ejemplo n.º 1
0
        public int SP_TABLE_FortnitePVPProfile_Update(FortnitePVPProfile user)
        {
            var EpicId      = new SqlParameter("@EpicId", user.EpicId);
            var PlayerName  = new SqlParameter("@PlayerName", user.PlayerName);
            var PvpWinSolo  = new SqlParameter("@PvpWinSolo", user.PvpWinSolo);
            var PvpWinDuo   = new SqlParameter("@PvpWinDuo", user.PvpWinDuo);
            var PvpWinSquad = new SqlParameter("@PvpWinSquad", user.PvpWinSquad);

            return(CallStoredProcedure("dbo.SP_TABLE_FortnitePVPProfile_Update @EpicId, @PlayerName, @PvpWinSolo, @PvpWinDuo, @PvpWinSquad",
                                       EpicId, PlayerName, PvpWinSolo, PvpWinDuo, PvpWinSquad));
        }
        public async Task <bool> UpdateDiscordPVPProfileAsync(FortnitePVPProfile mockUser, bool nameTag, IGuildUser guser, IUserMessage msg = null, bool IsNameLocked = false)
        {
            if (guser.IsServerOwner())
            {
                return(true);
            }

            var curUser = await guser.Guild.GetCurrentUserAsync(CacheMode.AllowDownload, Core.Utils.RequestOption);

            var mn_NickName = curUser.GuildPermissions.ManageNicknames;

            if (msg != null && IsNameLocked)
            {
                await msg.SetLockAsync();
            }

            if (mn_NickName)
            {
                try
                {
                    var newWinName = ModifyPVPTag(mockUser.PlayerName, mockUser.PvpCurrentModeWins(GameUserMode.PVP_WIN_ALL), nameTag);
                    var changeName = newWinName != guser?.Nickname;

                    if (!changeName)
                    {
                        return(true);
                    }
                    else if (IsNameLocked)
                    {
                        return(true);
                    }

                    guser.ModifyAsync((o) =>
                    {
                        if (curUser.GuildPermissions.ManageNicknames && IsNameLocked == false)
                        {
                            o.Nickname = newWinName;
                        }
                    }, Core.Utils.RequestOption).Wait();
                }
                catch (Exception e)
                {
                    if (msg != null)
                    {
                        await msg.SetErrorAsync();

                        return(false);
                    }
                }
            }
            return(true);
        }
        public async Task <bool> UpdateDatabasePVPProfileAsync(KeyValuePair <string, global::fortniteLib.Responses.Pvp.BattleRoyaleStats> profile, IGuildUser guser, IUserMessage msg = null, bool nameTag = false, bool IsNameLocked = false)
        {
            if (_uow.Db <BlackListUser>().Where(p => p.Id == guser.Id.ToString()).Any())
            {
                return(false);
            }

            var mockPVPProfile = new FortnitePVPProfile
            {
                PlayerName  = profile.Key,
                EpicId      = profile.Value.accountId,
                PvpWinSolo  = profile.Value.stats.BR_Placetop1(MatchType.solo, Platform.all, true),
                PvpWinDuo   = profile.Value.stats.BR_Placetop1(MatchType.duo, Platform.all, true),
                PvpWinSquad = profile.Value.stats.BR_Placetop1(MatchType.squad, Platform.all, true)
            };

            UpdateDatabaseUserProfile(mockPVPProfile.EpicId, guser, msg, nameTag, GameUserMode.PVP_WIN_ALL);
            StoredProcedure.SP_TABLE_FortnitePVPProfile_Update(mockPVPProfile);
            await UpdateDiscordPVPProfileAsync(mockPVPProfile, nameTag, guser, msg, IsNameLocked);

            return(true);
        }
        public Task _UpdateName(string mention)
        {
            return(Task.Run(async() =>
            {
                Regex r = new Regex("<@!?(\\d+)>", RegexOptions.Singleline);
                var m = r.Match(mention);
                if (m.Success)
                {
                    RestGuildUser cuser = Context.DiscordRestApi.GetGuildUserAsync(Context.Guild.Id, m.Groups[1].Value.ToUlong()).Result;
                    if (cuser == null)
                    {
                        return;
                    }
                    if (cuser.IsServerOwner())
                    {
                        await ReplyEmbedErrorAsync(Translate.GetBotTranslation(BotTranslationString.CanNotUpdateDiscordOwner, GetLanguage(), cuser.Mention));
                        return;
                    }

                    var uid = cuser.Id.ToString();
                    {
                        var usr = Context.Repo.Db <FortniteUser>()
                                  .GetById(uid);
                        NameState ns = usr.NameStates.FirstOrDefault(p => p.FortniteUserId == uid && p.DiscordServerId == Context.Guild.Id.ToString());
                        if (usr == null)
                        {
                            await ReplyEmbedErrorAsync(Translate.GetBotTranslation(BotTranslationString.FirstlyUseAnotherCmd1, GetLanguage(), cuser.Mention));
                            return;
                        }
                        else if (ns == null)
                        {
                            ns = await Context.Repo.User.AddOrGetNameStateAsync(usr, Context.Guild.Id.ToString());
                        }

                        if (!usr.IsValidName)
                        {
                            await ReplyEmbedErrorAsync(Translate.GetBotTranslation(BotTranslationString.FirstlyUseAnotherCmd2, GetLanguage(), cuser.Mention));

                            return;
                        }
                        var pstate = await CheckUserPriority(new TimeSpan(0, 0, 10, 0), usr, cuser, ns);
                        if (pstate.Value == null)
                        {
                            return;
                        }
                        var msg = await ReplyEmbedPriorityAsync(ToTranslate(BotTranslationString.UpdateRequestReceived, GetLanguage(), mention), pstate);
                        if (!string.IsNullOrWhiteSpace(usr.EpicId))
                        {
                            if (usr.GameUserMode == GameUserMode.PVE)
                            {
                                FortnitePVEProfile fortniteProfile = Context.Repo.Db <FortnitePVEProfile>()
                                                                     .All()
                                                                     .FirstOrDefault(f => f.EpicId == usr.EpicId);
                                await SetNewNameViaMode <FortnitePVEProfile>(cuser, usr, msg, fortniteProfile);
                            }
                            else
                            {
                                FortnitePVPProfile fortniteProfile = Context.Repo.Db <FortnitePVPProfile>()
                                                                     .All()
                                                                     .FirstOrDefault(f => f.EpicId == usr.EpicId);
                                await SetNewNameViaMode <FortnitePVPProfile>(cuser, usr, msg, fortniteProfile);
                            }
                        }
                        else
                        {
                            await msg.SetErrorAsync();
                        }
                    }
                }
                else
                {
                    ReplyEmbedErrorAsync($"invalid user mention.").Wait();
                }
            }));
        }