public string ToTable() { var dataTable = new DataTable(); dataTable.Columns.Add("Key", typeof(string)); dataTable.Columns.Add("Value", typeof(string)); var row = dataTable.NewRow(); row[0] = nameof(Name); row[1] = Name; dataTable.Rows.Add(row); row = dataTable.NewRow(); row[0] = nameof(ExactName); row[1] = ExactName; dataTable.Rows.Add(row); row = dataTable.NewRow(); row[0] = nameof(Rate); row[1] = Rate.ToString(); dataTable.Rows.Add(row); row = dataTable.NewRow(); row[0] = nameof(Snaps); row[1] = Snaps.ToString(); dataTable.Rows.Add(row); row = dataTable.NewRow(); row[0] = nameof(Handicap); row[1] = Handicap.ToString(); dataTable.Rows.Add(row); row = dataTable.NewRow(); row[0] = nameof(TimeNudge); row[1] = TimeNudge.ToString(); dataTable.Rows.Add(row); row = dataTable.NewRow(); row[0] = nameof(DiscordId); row[1] = DiscordId; dataTable.Rows.Add(row); row = dataTable.NewRow(); row[0] = nameof(Guid); row[1] = Guid; dataTable.Rows.Add(row); return(AsciiTableGenerator.CreateAsciiTableFromDataTable(dataTable)?.ToString()); }
public string PlayersToTable() { var dataTable = new DataTable(); dataTable.Columns.Add("Name", typeof(string)); dataTable.Columns.Add("Score", typeof(int)); dataTable.Columns.Add("Ping", typeof(int)); foreach (var player in Players) { var row = dataTable.NewRow(); row[0] = player.Name; row[1] = player.Score; row[2] = player.Ping; dataTable.Rows.Add(row); } return(AsciiTableGenerator.CreateAsciiTableFromDataTable(dataTable)?.ToString()); }
public async Task Servers() { using (Context.Channel.EnterTypingState()) { var servers = await _serverRepository.List(Context.Guild.Id); var sb = new StringBuilder(); var enumerable = servers as Server[] ?? servers.ToArray(); if (enumerable.IsNullOrEmpty()) { sb.AppendLine("No servers have been added yet.") .AppendLine("Talk to an admin if you wish to add your server.") .AppendLine("Or if you are an admin you can add servers using the `!server add` command."); } else { var continents = enumerable.Select(s => s.Continent).OrderBy(c => c).Distinct(); foreach (var continent in continents) { sb.AppendLine($"**{continent}**") .AppendLine("```markdown") .AppendLine(AsciiTableGenerator.CreateAsciiTableFromDataTable( ContinentToTable(enumerable.Where(s => s.Continent == continent) .OrderBy(s => s.Country) .ThenBy(s => s.City)) )?.ToString()) .AppendLine("```"); } } await ReplyAsync(embed : new EmbedBuilder { Title = "Servers", Description = sb.ToString(), Color = Color.Green }.Build()); } }