public int SP_TABLE_FortnitePVEProfile_Update(FortnitePVEProfile user) { var EpicId = new SqlParameter("@EpicId", user.EpicId); var PlayerName = new SqlParameter("@PlayerName", user.PlayerName); var AccountPowerLevel = new SqlParameter("@AccountPowerLevel", user.AccountPowerLevel); var Map = new SqlParameter("@Map", user.Map); var CommanderLevel = new SqlParameter("@CommanderLevel", user.CommanderLevel); var CollectionBookLevel = new SqlParameter("@CollectionBookLevel", user.CollectionBookLevel); var NumMythicSchematics = new SqlParameter("@NumMythicSchematics", user.NumMythicSchematics); var EliteFortnite2019 = new SqlParameter("@EliteFortnite2019", user.EliteFortnite2019); return(CallStoredProcedure("dbo.SP_TABLE_FortnitePVEProfile_Update @EpicId, @PlayerName, @AccountPowerLevel, @Map, @CommanderLevel, @CollectionBookLevel, @NumMythicSchematics, @EliteFortnite2019", EpicId, PlayerName, AccountPowerLevel, Map, CommanderLevel, CollectionBookLevel, NumMythicSchematics, EliteFortnite2019)); }
public async Task <bool> UpdateDiscordPVEProfileAsync(FortnitePVEProfile mockUser, bool nameTag, IGuildUser guser, IUserMessage msg = null, bool IsNameLocked = false, bool PVEDecimals = true) { if (guser.IsServerOwner()) { return(true); } var gconfig = Guild.GetConfig(guser.Guild.Id.ToString()); var UserRoles = await guser.GetUserRolesAsync(gconfig.Owner.DefaultLanguage); var addRole = true; var curUser = await guser.Guild.GetCurrentUserAsync(CacheMode.AllowDownload, Core.Utils.RequestOption); if (curUser.GuildPermissions.ManageRoles) { try { foreach (var role in UserRoles) { if (role.Key == mockUser.Map) { addRole = false; continue; } guser.RemoveRoleAsync(role.Value, Core.Utils.RequestOption).Wait(); } } catch (Exception e) { } if (!gconfig.Event.MythicSKStates.Active)//mythic storm king role remover { try { ulong msk_roleId = ulong.Parse(gconfig.Event.MythicSKStates.RoleIdToMythicSK); var userRole = guser.RoleIds.Any(id => id == msk_roleId); if (userRole) { var role = guser.Guild.GetRole(msk_roleId); guser.RemoveRoleAsync(role, Core.Utils.RequestOption).Wait(); } } catch (Exception e) { } } if (!gconfig.Event.EliteFrostnite2019s.Active)//elite frostnite 2019 role remover { try { ulong msk_roleId = ulong.Parse(gconfig.Event.EliteFrostnite2019s.RoleId); var userRole = guser.RoleIds.Any(id => id == msk_roleId); if (userRole) { var role = guser.Guild.GetRole(msk_roleId); guser.RemoveRoleAsync(role, Core.Utils.RequestOption).Wait(); } } catch (Exception e) { } } } var mn_NickName = curUser.GuildPermissions.ManageNicknames; var nm_Role = curUser.GuildPermissions.ManageRoles; if (msg != null && IsNameLocked) { await msg.SetLockAsync(); } if ((mn_NickName || nm_Role)) { try { // if (mockUser.NumMythicSchematics > 0 && gconfig.Event.MythicSKStates.Active) { ulong msk_roleId = ulong.Parse(gconfig.Event.MythicSKStates.RoleIdToMythicSK); var userRole = guser.RoleIds.Any(id => id == msk_roleId); if (!userRole) { var guild_msk_role = guser.Guild.GetRole(msk_roleId); guser.AddRoleAsync(guild_msk_role).Wait(); } } if (mockUser.EliteFortnite2019 && gconfig.Event.EliteFrostnite2019s.Active) { ulong msk_roleId = ulong.Parse(gconfig.Event.EliteFrostnite2019s.RoleId); var userRole = guser.RoleIds.Any(id => id == msk_roleId); if (!userRole) { var guild_efn_role = guser.Guild.GetRole(msk_roleId); guser.AddRoleAsync(guild_efn_role).Wait(); } } // var newPowerName = ModifyPVETag(mockUser.PlayerName, mockUser.AccountPowerLevel, nameTag, PVEDecimals); var sameName = newPowerName != guser?.Nickname; if (!addRole && !sameName) { return(true); } else if (!addRole && IsNameLocked) { return(true); } guser.ModifyAsync((o) => { if (curUser.GuildPermissions.ManageNicknames && IsNameLocked == false) { o.Nickname = newPowerName; } if (addRole && curUser.GuildPermissions.ManageRoles) { var CurrentGuildMapRoles = guser.Guild.GetMapRolesAsync(gconfig.Owner.DefaultLanguage).Result; var rl = CurrentGuildMapRoles.FirstOrDefault(p => p.Key == mockUser.Map); if (rl.Value != null) { guser.AddRoleAsync(rl.Value, Core.Utils.RequestOption).Wait(); } } }, Core.Utils.RequestOption).Wait(); if (msg != null && guser.Id == guser.Guild.OwnerId) { await msg.SetErrorAsync(); } } catch (Exception e) { if (msg != null) { await msg.SetErrorAsync(); return(false); } } } return(true); }
public async Task <bool> UpdateDatabasePVEProfileAsync(KeyValuePair <string, IQueryProfile> profile, IGuildUser guser, IUserMessage msg = null, bool nameTag = false, bool IsNameLocked = false, bool PVEDecimals = true) { if (_uow.Db <BlackListUser>().Where(p => p.Id == guser.Id.ToString()).Any()) { return(false); } var svvrs = await profile.Value.GetSurvivors(); var svvrsResource = await svvrs.CalcSurvivorFORTs(); var resources = await profile.Value.CalcResearchFORTs(); var AccountPowerLevel = await SurvivorStaticData.CalcEnergyByFORT(svvrsResource + resources); var mSchematics = profile.Value.AmountOfMythicSchematics(); var frostnite2019 = profile.Value.DoneEliteFrostnite2019(); var mockPveProfile = new FortnitePVEProfile { EpicId = profile.Value.profileChanges.First().profile.accountId, PlayerName = profile.Key, AccountPowerLevel = AccountPowerLevel, NumMythicSchematics = mSchematics, EliteFortnite2019 = frostnite2019 }; if (AccountPowerLevel < 16) { mockPveProfile.Map = MapRoles.Stonewood; } else if (AccountPowerLevel < 46) { mockPveProfile.Map = MapRoles.Plankerton; } else if (AccountPowerLevel < 70) { mockPveProfile.Map = MapRoles.CannyValley; } else { mockPveProfile.Map = MapRoles.TwinePeaks; } StatAttribute stats = profile.Value.profileChanges.First().profile.stats["attributes"]; if (stats.rewards_claimed_post_max_level.HasValue) { if (stats != null) { mockPveProfile.CommanderLevel = (stats.level + stats.rewards_claimed_post_max_level.Value); } } else { if (stats != null) { mockPveProfile.CommanderLevel = stats.level; } } if (stats.collection_book != null) { mockPveProfile.CollectionBookLevel = stats.collection_book.maxBookXpLevelAchieved; } UpdateDatabaseUserProfile(mockPveProfile.EpicId, guser, msg, nameTag, GameUserMode.PVE); StoredProcedure.SP_TABLE_FortnitePVEProfile_Update(mockPveProfile); await UpdateDiscordPVEProfileAsync(mockPveProfile, nameTag, guser, msg, IsNameLocked, PVEDecimals); 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(); } })); }