コード例 #1
0
        private void TimerCallback(object state)
        {
            lock (timerLock)
            {
                try
                {
                    if (discord?.LoginState != LoginState.LoggedIn)
                    {
                        return;
                    }
                    if (server?.ConnectedUsers?.Count == null)
                    {
                        return;
                    }
                    DiscordZkUserCount = discord?.GetGuild(DiscordZkServerID)?.Users?.Count ?? 0;
                    var zkTopic =
                        $"[game: {server.ConnectedUsers.Count} online, {server.MatchMaker.GetTotalWaiting()} in queue, {server.Battles.Values.Where(x => x != null).Sum(x => (int?)x.NonSpectatorCount + x.SpectatorCount) ?? 0} in custom]";

                    if (zkTopic != lastZkTopic)
                    {
                        foreach (var ch in channels)
                        {
                            discordZkRelay?.SetTopic(ch, $"{server.Channels.Get(ch)?.Topic?.Text} {zkTopic}");
                        }
                    }
                    lastZkTopic = zkTopic;
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Error processing relay timer: {0}", ex);
                }
            }
        }