public async Task EcoStatus(CommandContext ctx)
        {
            var plugin = DiscordLink.Obj;

            if (plugin == null)
            {
                await ctx.RespondAsync(
                    "The plugin was unable to be found on the server. Please report this to the plugin author.");

                return;
            }

            var pluginConfig = plugin.DiscordPluginConfig;
            var serverInfo   = NetworkManager.GetServerInfo();

            string name        = FirstNonEmptyString(pluginConfig.ServerName, serverInfo.Name);
            string description = FirstNonEmptyString(pluginConfig.ServerDescription, serverInfo.Description,
                                                     "No server description is available.");

            IPAddress addr          = IPUtil.GetInterNetworkIP().FirstOrDefault();
            string    serverAddress = String.IsNullOrEmpty(pluginConfig.ServerIP)
                ? addr == null ? "No Configured Address"
                : addr + ":" + serverInfo.WebPort
                : pluginConfig.ServerIP;

            string players = serverInfo.OnlinePlayers + "/" + serverInfo.TotalPlayers;

            var    timeRemainingSpan = new TimeSpan(0, 0, (int)serverInfo.TimeLeft);
            string timeRemaining     = String.Format("{0} Days, {1} hours, {2} minutes",
                                                     timeRemainingSpan.Days, timeRemainingSpan.Hours, timeRemainingSpan.Minutes);

            var    timeSinceStartSpan = new TimeSpan(0, 0, (int)serverInfo.TimeSinceStart);
            string timeSinceStart     = String.Format("{0} Days, {1} hours, {2} minutes",
                                                      timeSinceStartSpan.Days, timeSinceStartSpan.Hours, timeSinceStartSpan.Minutes);

            string leader = String.IsNullOrEmpty(serverInfo.Leader) ? "No leader" : serverInfo.Leader;

            DiscordEmbedBuilder builder = new DiscordEmbedBuilder()
                                          .WithColor(EmbedColor)
                                          .WithTitle("**" + name + " Server Status**")
                                          .WithDescription(description)
                                          .AddField("Online Players", players)
                                          .AddField("Address", serverAddress)
                                          .AddField("Time Left until Meteor", timeRemaining)
                                          .AddField("Time Since Game Start", timeSinceStart)
                                          .AddField("Current Leader", leader);

            builder = String.IsNullOrWhiteSpace(pluginConfig.ServerLogo)
                ? builder
                : builder.WithThumbnailUrl(pluginConfig.ServerLogo);

            await ctx.RespondAsync("Current status of the server:", false, builder.Build());
        }
Beispiel #2
0
        public async Task EcoStatus(CommandContext ctx)
        {
            try
            {
                var plugin = DiscordLink.Obj;
                if (plugin == null)
                {
                    await ctx.RespondAsync(
                        "The plugin was unable to be found on the server. Please report this to the plugin author.");

                    return;
                }

                var pluginConfig = plugin.DiscordPluginConfig;
                var serverInfo   = NetworkManager.GetServerInfo();

                var name        = FirstNonEmptyString(pluginConfig.ServerName, serverInfo.Name);
                var description = FirstNonEmptyString(pluginConfig.ServerDescription, serverInfo.Description,
                                                      "No server description is available.");

                var addr          = IPUtil.GetInterNetworkIP().FirstOrDefault();
                var serverAddress = String.IsNullOrEmpty(pluginConfig.ServerIP)
                    ? addr == null ? "No Configured Address"
                    : addr + ":" + serverInfo.WebPort
                    : pluginConfig.ServerIP;

                var players = $"{serverInfo.OnlinePlayers}/{serverInfo.TotalPlayers}";

                var timeRemainingSpan      = new TimeSpan(0, 0, (int)serverInfo.TimeLeft);
                var meteorHasHit           = timeRemainingSpan.Seconds < 0;
                var timeRemainingFieldName = "Time Left until Meteor";
                timeRemainingSpan = meteorHasHit ? new TimeSpan(0, 0, 0) : timeRemainingSpan;
                var timeRemaining =
                    $"{timeRemainingSpan.Days} Days, {timeRemainingSpan.Hours} hours, {timeRemainingSpan.Minutes} minutes";

                var timeSinceStartSpan = new TimeSpan(0, 0, (int)serverInfo.TimeSinceStart);
                var timeSinceStart     =
                    $"{timeSinceStartSpan.Days} Days, {timeSinceStartSpan.Hours} hours, {timeSinceStartSpan.Minutes} minutes";

                var leader = String.IsNullOrEmpty(serverInfo.Leader) ? "No leader" : serverInfo.Leader;

                var builder = new DiscordEmbedBuilder()
                              .WithColor(EmbedColor)
                              .WithTitle($"**{name} Server Status**")
                              .WithDescription(description)
                              .AddField("Online Players", players)
                              .AddField("Address", serverAddress)
                              .AddField(timeRemainingFieldName, timeRemaining)
                              .AddField("Time Since Game Start", timeSinceStart)
                              .AddField("Current Leader", leader);

                //Add the Server Logo Thumbnail
                try
                {
                    builder = String.IsNullOrWhiteSpace(pluginConfig.ServerLogo)
                        ? builder
                        : builder.WithThumbnailUrl(pluginConfig.ServerLogo);
                }
                catch (UriFormatException e)
                {
                    Logger.Info("Warning: The Configured Server Logo is not a valid URL.");
                }


                await ctx.RespondAsync("Current status of the server:", false, builder.Build());
            }
            catch (Exception e)
            {
                LogCommandException(e);
            }
        }