public static void PushDiscordById(this FTNPower.Core.Interfaces.IRedisService redisService, IFTNPowerRepository repository, string queueName, string discordId) { var ReadyToUpdateList = repository.Db <NameState>() .All() .AsNoTracking() .Where(f => f.LockName == false && f.InQueue == false && f.DiscordServerId == discordId && f.FortniteUser.IsValidName && f.FortniteUser.EpicId != null) .Select(c => new ReadyToUpdate() { DiscordServerId = c.DiscordServerId, EpicId = c.FortniteUser.EpicId, FortniteUserId = c.FortniteUserId, GameUserMode = c.FortniteUser.GameUserMode, NameTag = c.FortniteUser.NameTag }); List <Task> tList = new List <Task>(); foreach (var readyToUpdate in ReadyToUpdateList) { tList.Add(Task.Run(() => { redisService.ListLeftPush(queueName, readyToUpdate, flags: CommandFlags.FireAndForget); })); } Task.WaitAll(tList.ToArray()); tList.Clear(); }
/// <summary> /// Initializes a new instance of the <see cref="Context"/> class. /// </summary> /// <param name="client"> /// The client param. /// </param> /// <param name="message"> /// The message param. /// </param> /// <param name="queueManager"></param> public Context(DiscordShardedClient client, SocketUserMessage message, IFTNPowerRepository fTNPowerRepository, IDiscordRestApi discordRestApi) : base(client, message) { DiscordRestApi = discordRestApi; Repo = fTNPowerRepository; GuildConfig = Repo.Guild.AddOrGetGuildConfig(Guild.Id.ToString()); DiscordUser = Repo.User.AddOrGetUserAsync(User.Id.ToString(), Guild.Id.ToString()).Result; AccountPowerLevel = 1; if (DiscordUser.IsValidName) { if (DiscordUser.GameUserMode == GameUserMode.PVE) { var pveuser = Repo.Db <FortnitePVEProfile>() .Where(f => f.EpicId == DiscordUser.EpicId) .Select(x => new { x.PlayerName, x.EpicId, x.AccountPowerLevel }) .FirstOrDefault(); PlayerName = pveuser?.PlayerName; if (pveuser != null) { AccountPowerLevel = Model.Utils.GetIntegerPower(pveuser.AccountPowerLevel); } else { AccountPowerLevel = 0; } } else { var pvpUser = Repo.Db <FortnitePVPProfile>() .Where(f => f.EpicId == DiscordUser.EpicId) .FirstOrDefault(); PlayerName = pvpUser?.PlayerName; TotalPVPRankedWins = pvpUser.PvpCurrentModeWins(DiscordUser.GameUserMode); } } else { PlayerName = null; } }