Beispiel #1
0
 public TempusServerUpdater(DiscordSocketClient client, ConfigDataAccess configDataAccess,
                            TempusDataAccess tempusDataAccess)
 {
     _client           = client;
     _configDataAccess = configDataAccess;
     _tempusDataAccess = tempusDataAccess;
 }
Beispiel #2
0
        private async Task MainAsync()
        {
            _client = new DiscordSocketClient(new DiscordSocketConfig {
                AlwaysDownloadUsers = true
            });
            _commands = new CommandService(new CommandServiceConfig {
                DefaultRunMode = RunMode.Async
            });
            _simplyDataAccess = new SimplyDataAccess();
            _tempusDataAccess = new TempusDataAccess();
            _rankUpdater      = new RankUpdater(_client, _simplyDataAccess);
            _statusUpdater    = new StatusUpdater(_client);

            AddClientEvents();

            await Login();

            BuildServiceProvider();

            await InstallCommands();

            await _client.StartAsync();

            _rankUpdateTimer = new Timer(IntervalFunctions, null, 0, FromMinutes(5));

            // Block this task until the program is closed.
            await Task.Delay(-1);
        }
Beispiel #3
0
        public static async Task <Embed> UpdateStalkTopEmbedAsync(TempusDataAccess tempusDataAccess)
        {
            try
            {
                var servers = (await tempusDataAccess.GetServerStatusAsync()).Where(x => x != null).ToArray();
                var users   = servers.Where(x => x.GameInfo != null &&
                                            (x.GameInfo != null || x.ServerInfo != null ||
                                             x.GameInfo.Users != null) &&
                                            x.GameInfo.Users.Count != 0)
                              .SelectMany(x => x.GameInfo.Users).Where(x => x?.Id != null).ToArray();

                var userIdStrings = (from user in users where user?.Id != null select user.Id.ToString()).ToList();

                var rankTasks = new List <Task <Rank> >();
                rankTasks.AddRange(userIdStrings.Select(tempusDataAccess.GetUserRankAsync));


                var ranks = await Task.WhenAll(rankTasks);

                var rankedUsers = ranks.ToDictionary(rank => users.First(x => x.Id == rank.PlayerInfo.Id), rank =>
                                                     rank.ClassRankInfo.DemoRank.Rank <= rank.ClassRankInfo.SoldierRank.Rank
                        ? rank.ClassRankInfo.DemoRank.Rank
                        : rank.ClassRankInfo.SoldierRank.Rank);

                var output      = rankedUsers.OrderBy(x => x.Value).Take(7);
                var rankedLines = "";
                foreach (var(key, value) in output)
                {
                    if (key == null || value > 100)
                    {
                        continue;
                    }
                    var server = servers
                                 .FirstOrDefault(x =>
                                                 x.GameInfo?.Users != null &&
                                                 x.GameInfo.Users.Count(z => z.Id.HasValue && z.Id == key.Id) != 0);
                    if (server == null || key.Id == null)
                    {
                        continue;
                    }
                    rankedLines +=
                        $"Rank {value} - {DiscordHelper.FormatUrlMarkdown(key.Name.EscapeDiscordChars(), TempusHelper.GetPlayerUrl(key.Id.Value))} on {DiscordHelper.FormatUrlMarkdown(server.GameInfo.CurrentMap.EscapeDiscordChars(), TempusHelper.GetMapUrl(server.GameInfo.CurrentMap))} {DiscordHelper.FormatUrlMarkdown(server.ServerInfo.Shortname, TempusHelper.GetServerUrl(server.ServerInfo.Id))}{Environment.NewLine}";
                }

                var builder =
                    new EmbedBuilder {
                    Title = "**Highest Ranked Players Online** (Top 100)", Description = rankedLines
                }
                .WithCurrentTimestamp().WithColor(ColorConstants.InfoColor);
                CachedStalkTopEmbed = builder.Build();
                return(builder.Build());
            }
            catch (Exception e)
            {
                return(Logger.LogException(e));
            }
        }
Beispiel #4
0
 public static async Task <Embed> GetStalkTopEmbedAsync(TempusDataAccess tempusDataAccess)
 {
     try
     {
         if (CachedStalkTopEmbed == null)
         {
             return(await UpdateStalkTopEmbedAsync(tempusDataAccess));
         }
         return(CachedStalkTopEmbed);
     }
     catch (Exception e)
     {
         return(Logger.LogException(e));
     }
 }
Beispiel #5
0
        private void InitializeVariables()
        {
            _client = new DiscordSocketClient(
                new DiscordSocketConfig {
                AlwaysDownloadUsers = true, MessageCacheSize = 50
            });
            _commands = new CommandService(new CommandServiceConfig {
                DefaultRunMode = RunMode.Async
            });

            var connectionStrings = File.ReadAllLines(DiscordConstants.DatabaseInfoPath);

            _tempusDataAccess = new TempusDataAccess();
            _todoDataAccess   = new TodoDataAccess(connectionStrings[0]);
            _configDataAccess = new ConfigDataAccess(connectionStrings[0]);
            //_justJumpDataAccess = new JustJumpDataAccess(connectionStrings[1]);
            //_simplyHightowerDataAccess = new SimplyHightowerDataAccess(connectionStrings[2]);

            _tempusServerUpdater   = new TempusServerUpdater(_client, _configDataAccess, _tempusDataAccess);
            _tempusActivityUpdater = new TempusActivityUpdater(_client, _configDataAccess, _tempusDataAccess);
            _simplyTFServerUpdater = new SimplyTFServerUpdater(_client, _configDataAccess);
        }