Esempio n. 1
0
 public static string StoreCurrencyName(StoreComponent store)
 {
     return(MessageUtil.StripTags(store.CurrencyName));
 }
Esempio n. 2
0
        public static DiscordEmbed GetServerInfo(ServerInfoComponentFlag flag)
        {
            var plugin = DiscordLink.Obj;

            if (plugin == null)
            {
                return(null);
            }

            var config     = DLConfig.Data;
            var serverInfo = NetworkManager.GetServerInfo();

            var builder = new DiscordEmbedBuilder();

            builder.WithColor(EmbedColor);

            if (flag.HasFlag(ServerInfoComponentFlag.Name))
            {
                builder.WithTitle($"**{FirstNonEmptyString(config.ServerName, MessageUtil.StripTags(serverInfo.Description), "[Server Title Missing]")} " + "Server Status" + "**\n" + DateTime.Now.ToShortDateString() + " : " + DateTime.Now.ToShortTimeString());
            }
            else
            {
                DateTime time      = DateTime.Now;
                int      utcOffset = TimeZoneInfo.Local.GetUtcOffset(time).Hours;
                builder.WithTitle("**" + "Server Status" + "**\n" + "[" + DateTime.Now.ToString("yyyy-MM-dd : HH:mm", CultureInfo.InvariantCulture) + " UTC " + (utcOffset != 0 ? (utcOffset >= 0 ? "+" : "-") + utcOffset : "") + "]");
            }

            if (flag.HasFlag(ServerInfoComponentFlag.Description))
            {
                builder.WithDescription(FirstNonEmptyString(config.ServerDescription, MessageUtil.StripTags(serverInfo.Description), "No server description is available."));
            }

            if (flag.HasFlag(ServerInfoComponentFlag.Logo) && !string.IsNullOrWhiteSpace(config.ServerLogo))
            {
                try
                {
                    builder.WithThumbnail(config.ServerLogo);
                }
                catch (UriFormatException e)
                {
                    Logger.Debug("Failed to include thumbnail in Server Info embed. Error: " + e);
                }
            }

            if (flag.HasFlag(ServerInfoComponentFlag.ServerAddress))
            {
                string fieldText = "-- No address configured --";
                if (!string.IsNullOrEmpty(config.ServerAddress))
                {
                    fieldText = config.ServerAddress;
                }
                else if (!string.IsNullOrEmpty(serverInfo.Address))
                {
                    fieldText = serverInfo.Address;
                }
                builder.AddField("Server Address", fieldText);
            }

            if (flag.HasFlag(ServerInfoComponentFlag.PlayerCount))
            {
                builder.AddField("Online Players", $"{UserManager.OnlineUsers.Where(user => user.Client.Connected).Count()}/{serverInfo.TotalPlayers}");
            }

            if (flag.HasFlag(ServerInfoComponentFlag.PlayerList))
            {
                IEnumerable <string> onlineUsers = UserManager.OnlineUsers.Where(user => user.Client.Connected).Select(user => user.Name);
                string playerList = onlineUsers.Count() > 0 ? string.Join("\n", onlineUsers) : "-- No players online --";
                builder.AddField("Online Players", GetPlayerList());
            }

            if (flag.HasFlag(ServerInfoComponentFlag.TimeSinceStart))
            {
                TimeSpan timeSinceStartSpan = new TimeSpan(0, 0, (int)serverInfo.TimeSinceStart);
                builder.AddField("Time Since Game Start", $"{timeSinceStartSpan.Days} Days, {timeSinceStartSpan.Hours} hours, {timeSinceStartSpan.Minutes} minutes");
            }

            if (flag.HasFlag(ServerInfoComponentFlag.TimeRemaining))
            {
                TimeSpan timeRemainingSpan = new TimeSpan(0, 0, (int)serverInfo.TimeLeft);
                bool     meteorHasHit      = timeRemainingSpan.Seconds < 0;
                timeRemainingSpan = meteorHasHit ? new TimeSpan(0, 0, 0) : timeRemainingSpan;
                builder.AddField("Time Left Until Meteor", $"{timeRemainingSpan.Days} Days, {timeRemainingSpan.Hours} hours, {timeRemainingSpan.Minutes} minutes");
            }

            if (flag.HasFlag(ServerInfoComponentFlag.MeteorHasHit))
            {
                TimeSpan timeRemainingSpan = new TimeSpan(0, 0, (int)serverInfo.TimeLeft);
                builder.AddField("Meteor Has Hit", timeRemainingSpan.Seconds < 0 ? "Yes" : "No");
            }

            return(builder.Build());
        }
Esempio n. 3
0
 public static string StoreCurrencyName(StoreComponent store)
 {
     return(MessageUtil.StripTags(store.Parent.GetComponent <CreditComponent>().CreditData.Currency.Name));
 }