Fix lodestone character id extraction

This commit is contained in:
Stefan Berg
2022-08-03 22:43:11 +02:00
parent aebb7fdbb0
commit 60439535e7
5 changed files with 93 additions and 6 deletions

View File

@@ -302,14 +302,16 @@ namespace MareSynchronosServer.Discord
return auth;
}
private int? ParseCharacterIdFromLodestoneUrl(string lodestoneUrl)
private int? ParseCharacterIdFromLodestoneUrl(string lodestoneUrl)
{
var isLodestoneUrl = Regex.Match(lodestoneUrl, @"https:\/\/(na|eu|de|fr|jp)\.finalfantasyxiv\.com\/lodestone\/character\/\d+").Success;
if (!isLodestoneUrl) return null;
var regex = new Regex(@"https:\/\/(na|eu|de|fr|jp)\.finalfantasyxiv\.com\/lodestone\/character\/\d+");
var matches = regex.Match(lodestoneUrl);
var isLodestoneUrl = matches.Success;
if (!isLodestoneUrl || matches.Groups.Count < 1) return null;
lodestoneUrl = lodestoneUrl.Split('/', StringSplitOptions.RemoveEmptyEntries).Last();
if (!int.TryParse(lodestoneUrl, out int lodestoneId))
{
lodestoneUrl = matches.Groups[0].ToString();
var stringId = lodestoneUrl.Split('/', StringSplitOptions.RemoveEmptyEntries).Last();
if (!int.TryParse(stringId, out int lodestoneId)) {
return null;
}