Adjust character info lodestone api
This commit is contained in:
parent
1f41e7cf46
commit
588093bef6
@ -25,32 +25,7 @@ namespace ChaosBot.Discord.Modules
|
||||
{
|
||||
CharacterDetailed character = LodestoneManager.GetCharacter(id);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
var embed = new EmbedBuilder();
|
||||
|
||||
embed.WithColor(new Color(255, 255,0));
|
||||
embed.Title = $"Character Information";
|
||||
embed.Url = $"https://na.finalfantasyxiv.com/lodestone/character/{character.Character.ID}/";
|
||||
embed.ImageUrl = character.Character.Avatar;
|
||||
embed.Footer = new EmbedFooterBuilder().WithText($"Lodestone ID {character.Character.ID}");
|
||||
|
||||
char genderIcon = character.Character.Gender == 1 ? '♂' : '♀';
|
||||
sb.AppendLine($"{character.Character.Name} {genderIcon} ({character.Character.Server})");
|
||||
sb.AppendLine($"Bio: {character.Character.Bio}");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"Current Job: {character.Character.ActiveClassJob.Name} (level {character.Character.ActiveClassJob.Level})");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("All Jobs:");
|
||||
foreach (CharacterClassJob characterClassJob in character.Character.ClassJobs.ToArray())
|
||||
{
|
||||
if (characterClassJob.Level == 0) continue;
|
||||
sb.AppendLine($"{characterClassJob.Name} (level {characterClassJob.Level})");
|
||||
}
|
||||
|
||||
/*
|
||||
* Add the string to the Embed
|
||||
*/
|
||||
embed.Description = sb.ToString();
|
||||
var embed = BuildEmbedFromCharacter(character);
|
||||
|
||||
/*
|
||||
* Reply with the Embed created above
|
||||
@ -68,22 +43,9 @@ namespace ChaosBot.Discord.Modules
|
||||
{
|
||||
try
|
||||
{
|
||||
Character character = LodestoneManager.GetCharacter(server, string.Join(" ", name));
|
||||
CharacterDetailed character = LodestoneManager.GetCharacter(server, string.Join(" ", name));
|
||||
|
||||
var sb = new StringBuilder();
|
||||
var embed = new EmbedBuilder();
|
||||
|
||||
embed.WithColor(new Color(255, 255,0));
|
||||
embed.Title = $"Character Information";
|
||||
embed.Url = $"https://na.finalfantasyxiv.com/lodestone/character/{character.ID}/";
|
||||
embed.ImageUrl = character.Avatar;
|
||||
embed.Footer = new EmbedFooterBuilder().WithText($"Lodestone ID {character.ID}");
|
||||
sb.AppendLine($"{character.Name} ({character.Server})");
|
||||
|
||||
/*
|
||||
* Add the string to the Embed
|
||||
*/
|
||||
embed.Description = sb.ToString();
|
||||
var embed = BuildEmbedFromCharacter(character);
|
||||
|
||||
/*
|
||||
* Reply with the Embed created above
|
||||
@ -152,18 +114,33 @@ namespace ChaosBot.Discord.Modules
|
||||
{
|
||||
try
|
||||
{
|
||||
FreeCompany freeCompany = LodestoneManager.GetFreeCompany(server, name);
|
||||
FreeCompanyDetailed freeCompany = LodestoneManager.GetFreeCompany(server, name);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
var embed = new EmbedBuilder();
|
||||
|
||||
embed.WithColor(new Color(255, 255,0));
|
||||
embed.Title = $"Free Company Information";
|
||||
embed.Url = $"https://na.finalfantasyxiv.com/lodestone/freecompany/{freeCompany.ID}/";
|
||||
embed.ImageUrl = freeCompany.Crest.First();
|
||||
embed.Footer = new EmbedFooterBuilder().WithText($"Lodestone ID {freeCompany.ID}");
|
||||
embed.Url = $"https://na.finalfantasyxiv.com/lodestone/freecompany/{freeCompany.FreeCompany.ID}/";
|
||||
embed.ImageUrl = freeCompany.FreeCompany.Crest.First();
|
||||
embed.Footer = new EmbedFooterBuilder().WithText($"Lodestone ID {freeCompany.FreeCompany.ID}");
|
||||
|
||||
sb.AppendLine($"{freeCompany.Name} ({freeCompany.Server})");
|
||||
sb.AppendLine($"{freeCompany.FreeCompany.Name} ({freeCompany.FreeCompany.Server}, rank {freeCompany.FreeCompany.Rank})");
|
||||
sb.AppendLine($"{freeCompany.FreeCompany.Slogan}");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"{freeCompany.FreeCompany.ActiveMemberCount} active members.");
|
||||
sb.AppendLine($"Company estate {freeCompany.FreeCompany.Estate.Plot}");
|
||||
sb.AppendLine($"Pledged to Grand Company {freeCompany.FreeCompany.GrandCompany}");
|
||||
sb.AppendLine();
|
||||
|
||||
var rankCounts = freeCompany.FreeCompanyMembers.GroupBy(m => m.Rank).Select(g => new {Rank = g.Key, Count = g.Count()})
|
||||
.OrderBy(x => x.Rank);
|
||||
|
||||
foreach (string rank in new List<string>{"Council", "Mentor", "Member", "Initiate"})
|
||||
{
|
||||
var rankCount = rankCounts.First(e => e.Rank == rank);
|
||||
sb.AppendLine($"{rankCount.Count} members are of rank {rankCount.Rank} ");
|
||||
}
|
||||
|
||||
/*
|
||||
* Add the string to the Embed
|
||||
@ -180,5 +157,61 @@ namespace ChaosBot.Discord.Modules
|
||||
_logger.Error($"InfoCommands.InfoCommand: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
||||
}
|
||||
}
|
||||
|
||||
private static EmbedBuilder BuildEmbedFromCharacter(CharacterDetailed character)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
var embed = new EmbedBuilder();
|
||||
|
||||
embed.WithColor(new Color(255, 255, 0));
|
||||
embed.Title = $"Character Information";
|
||||
embed.Url = $"https://na.finalfantasyxiv.com/lodestone/character/{character.Character.ID}/";
|
||||
embed.ImageUrl = character.Character.Avatar;
|
||||
embed.Footer = new EmbedFooterBuilder().WithText($"Lodestone ID {character.Character.ID}");
|
||||
|
||||
char genderIcon = character.Character.Gender == 1 ? '♂' : '♀';
|
||||
sb.AppendLine($"{character.Character.Name} {genderIcon} ({character.Character.Server})");
|
||||
sb.AppendLine($"Bio: {character.Character.Bio}");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(
|
||||
$"Current Job: {LodestoneManager.Classes.GetValueOrDefault(character.Character.ActiveClassJob.UnlockedState.Name)?.Item1.ToString()} {character.Character.ActiveClassJob.Level}");
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("All Jobs:");
|
||||
|
||||
sb.Append("```");
|
||||
List<Tuple<string, ClassType, int>> classInfoList = new List<Tuple<string, ClassType, int>>();
|
||||
foreach (CharacterClassJob characterClassJob in character.Character.ClassJobs.ToArray())
|
||||
{
|
||||
if (characterClassJob.Level == 0) continue;
|
||||
Tuple<string, ClassType> classInfo =
|
||||
LodestoneManager.Classes.GetValueOrDefault(characterClassJob.UnlockedState.Name);
|
||||
classInfoList.Add(new Tuple<string, ClassType, int>(classInfo.Item1, classInfo.Item2, characterClassJob.Level));
|
||||
}
|
||||
|
||||
foreach (var classTypeList in classInfoList.GroupBy(ci => ci.Item2)
|
||||
.Select(group => new {ClassType = @group.Key, classList = @group.ToArray()}).OrderBy(g => g.ClassType))
|
||||
{
|
||||
sb.Append($"{classTypeList.ClassType.ToString()}:");
|
||||
|
||||
for (int i = 0; i < classTypeList.classList.Length; i++)
|
||||
{
|
||||
if ((i % 4) == 0)
|
||||
sb.AppendLine();
|
||||
|
||||
Tuple<string, ClassType, int> classItem = classTypeList.classList[i];
|
||||
sb.Append(String.Format(" {0,3}: {1,2}", classItem.Item1, classItem.Item3));
|
||||
}
|
||||
|
||||
sb.AppendLine("\n");
|
||||
}
|
||||
|
||||
sb.Append("```");
|
||||
|
||||
/*
|
||||
* Add the string to the Embed
|
||||
*/
|
||||
embed.Description = sb.ToString();
|
||||
return embed;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,18 +15,61 @@ namespace ChaosBot.Services
|
||||
{Endpoints.FREECOMPANY_SEARCH, "freecompany/search"},
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, Tuple<string, ClassType>> Classes = new Dictionary<string, Tuple<string, ClassType>>
|
||||
{
|
||||
{ "Marauder", new Tuple<string, ClassType>("MRD", ClassType.Tank) },
|
||||
{ "Warrior", new Tuple<string, ClassType>("WAR", ClassType.Tank) },
|
||||
{ "Gladiator", new Tuple<string, ClassType>("GLA", ClassType.Tank) },
|
||||
{ "Paladin", new Tuple<string, ClassType>("PLD", ClassType.Tank) },
|
||||
{ "Lancer", new Tuple<string, ClassType>("LNC", ClassType.Dps) },
|
||||
{ "Dragoon", new Tuple<string, ClassType>("DRG", ClassType.Dps) },
|
||||
{ "Pugilist", new Tuple<string, ClassType>("PGL", ClassType.Dps) },
|
||||
{ "Monk", new Tuple<string, ClassType>("MNK", ClassType.Dps) },
|
||||
{ "Rogue", new Tuple<string, ClassType>("ROG", ClassType.Dps) },
|
||||
{ "Ninja", new Tuple<string, ClassType>("NIN", ClassType.Dps) },
|
||||
{ "Archer", new Tuple<string, ClassType>("ARC", ClassType.Dps) },
|
||||
{ "Bard", new Tuple<string, ClassType>("BRD", ClassType.Dps) },
|
||||
{ "Thaumaturge", new Tuple<string, ClassType>("THM", ClassType.Dps) },
|
||||
{ "Black Mage", new Tuple<string, ClassType>("BLM", ClassType.Dps) },
|
||||
{ "Arcanist", new Tuple<string, ClassType>("ACN", ClassType.Dps) },
|
||||
{ "Summoner", new Tuple<string, ClassType>("SMN", ClassType.Dps) },
|
||||
{ "Scholar", new Tuple<string, ClassType>("SCH", ClassType.Healer) },
|
||||
{ "Conjurer", new Tuple<string, ClassType>("CNJ", ClassType.Healer) },
|
||||
{ "White Mage", new Tuple<string, ClassType>("WHM", ClassType.Healer) },
|
||||
{ "Blue Mage (Limited Job)", new Tuple<string, ClassType>("BLU", ClassType.Dps) },
|
||||
{ "Dark Knight", new Tuple<string, ClassType>("DRK", ClassType.Tank) },
|
||||
{ "Astrologian", new Tuple<string, ClassType>("AST", ClassType.Healer) },
|
||||
{ "Machinist", new Tuple<string, ClassType>("MCH", ClassType.Dps) },
|
||||
{ "Samurai", new Tuple<string, ClassType>("SAM", ClassType.Dps) },
|
||||
{ "Red Mage", new Tuple<string, ClassType>("RDM", ClassType.Dps) },
|
||||
{ "Gunbreaker", new Tuple<string, ClassType>("GNB", ClassType.Tank) },
|
||||
{ "Dancer", new Tuple<string, ClassType>("DNC", ClassType.Dps) },
|
||||
{ "Miner", new Tuple<string, ClassType>("MIN", ClassType.Gathering) },
|
||||
{ "Botanist", new Tuple<string, ClassType>("BTN", ClassType.Gathering) },
|
||||
{ "Fisher", new Tuple<string, ClassType>("FSH", ClassType.Gathering) },
|
||||
{ "Alchemist", new Tuple<string, ClassType>("ALC", ClassType.Gathering) },
|
||||
{ "Armorer", new Tuple<string, ClassType>("ARM", ClassType.Crafting) },
|
||||
{ "Blacksmith", new Tuple<string, ClassType>("BSM", ClassType.Crafting) },
|
||||
{ "Carpenter", new Tuple<string, ClassType>("CRP", ClassType.Crafting) },
|
||||
{ "Culinarian", new Tuple<string, ClassType>("CUL", ClassType.Crafting) },
|
||||
{ "Goldsmith", new Tuple<string, ClassType>("GSM", ClassType.Crafting) },
|
||||
{ "Leatherworker", new Tuple<string, ClassType>("LTW", ClassType.Crafting) },
|
||||
{ "Weaver", new Tuple<string, ClassType>("WVR", ClassType.Crafting) }
|
||||
};
|
||||
|
||||
public static string GetEndpointPaths(Endpoints endpoint, params object[] parameters)
|
||||
{
|
||||
return string.Format(EndpointPaths.GetValueOrDefault(endpoint, string.Empty)!, parameters);
|
||||
}
|
||||
|
||||
public static Character GetCharacter(string server, string name)
|
||||
public static CharacterDetailed
|
||||
GetCharacter(string server, string name)
|
||||
{
|
||||
Dictionary<string,string> parameters = new Dictionary<string, string>
|
||||
{{"name", name}, {"server", server}};
|
||||
|
||||
PaginationWrapper<Character> characterWrapper = LodestoneHttpProxy.Fetch<PaginationWrapper<Character>>(GetEndpointPaths(Endpoints.CHARACTER_SEARCH), parameters);
|
||||
return characterWrapper.Results.First();
|
||||
return GetCharacter(characterWrapper.Results.First().ID);
|
||||
}
|
||||
|
||||
public static CharacterDetailed GetCharacter(long id)
|
||||
@ -37,13 +80,13 @@ namespace ChaosBot.Services
|
||||
return character;
|
||||
}
|
||||
|
||||
public static FreeCompany GetFreeCompany(string server, string name)
|
||||
public static FreeCompanyDetailed GetFreeCompany(string server, string name)
|
||||
{
|
||||
Dictionary<string,string> parameters = new Dictionary<string, string>
|
||||
{{"name", name}, {"server", server}};
|
||||
|
||||
PaginationWrapper<FreeCompany> freeCompanyWrapper = LodestoneHttpProxy.Fetch<PaginationWrapper<FreeCompany>>(GetEndpointPaths(Endpoints.FREECOMPANY_SEARCH), parameters);
|
||||
return freeCompanyWrapper.Results.First();
|
||||
return GetFreeCompanyById(freeCompanyWrapper.Results.First().ID);
|
||||
}
|
||||
|
||||
public static FreeCompanyDetailed GetFreeCompanyById(string id) {
|
||||
@ -61,4 +104,13 @@ namespace ChaosBot.Services
|
||||
FREECOMPANY_SEARCH_BY_ID,
|
||||
FREECOMPANY_SEARCH
|
||||
}
|
||||
|
||||
public enum ClassType
|
||||
{
|
||||
Tank,
|
||||
Dps,
|
||||
Healer,
|
||||
Gathering,
|
||||
Crafting
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user