/// <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; } }
public bool IsDiscordBotList(IFTNPowerRepository _repo, string discordbotListGuildId) { return(discordbotListGuildId == _repo.Bot.Config.Vars.discordbots_org_Id); }
private Task MessageReceivedAsync(SocketMessage socketMessage) { // Ignore system messages, or messages from other bots if (!(socketMessage is SocketUserMessage Message)) { return(Task.CompletedTask); } if (Message.Source != MessageSource.User) { return(Task.CompletedTask); } SocketGuildChannel guild = (Message.Channel as SocketGuildChannel); if (guild == null) { return(Task.CompletedTask); } var argPos = 0; using (IFTNPowerRepository repo = DIManager.Services.GetRequiredService <IFTNPowerRepository>()) { if (!(Message.HasStringPrefix(repo.Bot.Config.Prefix, ref argPos, StringComparison.InvariantCultureIgnoreCase) || Message.HasMentionPrefix(guild.Guild.CurrentUser, ref argPos))) { return(Task.CompletedTask); } if (guild.Guild.Id.ToString() == repo.Bot.Config.Vars.discordbots_org_Id) { return(Task.CompletedTask); } #if RELEASE if (repo.Bot.Config.Developing) #elif DEBUG if (FTNPower.Data.Utils.USE_LOCAL_DBCONTEXT) #endif { if (!repo.Bot.Config.Vars.DeveloperDiscordIds.Contains(socketMessage.Author.Id)) { return(Task.CompletedTask); } } if (repo.Blacklist.BlacklistGuilds.Where(p => p.Id == guild.Guild.Id.ToString()).Any() || repo.Blacklist.BlacklistUsers.Where(p => p.Id == Message.Author.Id.ToString()).Any()) { return(Task.CompletedTask); } #if RELEASE if (repo.Bot.Config.Vars.IgnoreRequest && repo.Bot.Config.Vars.DeveloperDiscordIds.Contains(Message.Author.Id) && !Message.Content.Contains("f.ignore", StringComparison.InvariantCultureIgnoreCase)) { return(Task.CompletedTask); } #endif Context context = new Context(Client, Message, repo, DIManager.Services.GetRequiredService <IDiscordRestApi>()); try { var result = CommandService.ExecuteAsync(context, argPos, DIManager.Services).Result; if (!result.IsSuccess) { CmdErrorAsync(context, result, argPos).Wait(); } if (context.GuildConfig.Owner.AutoRemoveRequest) { Redis.ListLeftPush("AutoDiscordMsgRemove", new ReadyToRemove(Message.Channel.Id, Message.Id, 10)); } } catch (Exception e) { Global.Log.Exception(e); } } GC.Collect(2, GCCollectionMode.Forced, true); GC.WaitForPendingFinalizers(); return(Task.CompletedTask); }
public UserUpdater(IFTNPowerRepository fTNPowerRepository, IDiscordRestApi discordApi, Fortnite.Api.IEpicApi epicApi) { Repo = fTNPowerRepository; DiscordApi = discordApi; EpicApi = epicApi; }
public PriorityManager(IDiscordRestApi discordRestApi, IFTNPowerRepository fTNPowerRepository, IJsonStringLocalizer translation) { DiscordRestApi = discordRestApi; Translation = translation; Repo = fTNPowerRepository; }
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(); }