NielsHeltner / wowhead-quick-link

World of Warcraft Addon that allows you to quickly look up anything on Wowhead without having to manually search for it.
GNU General Public License v3.0
7 stars 4 forks source link

Generated Armory link is invalid #25

Open tflo opened 1 year ago

tflo commented 1 year ago

It seems Blizz's Armory is using the normalized realm name nowadays in their URIs (i.e. without "-", as returned by GetNormalizedRealmName()).

The addon generates a link with a non-normalized realm name, which doesn't work, at least not in my region (EU):

:warning:

https://worldofwarcraft.com/en-GB/character/Azjol-Nerub/Zaviak

This works:

https://worldofwarcraft.com/en-GB/character/AzjolNerub/Zaviak
vaindil commented 1 year ago

I took a look at this, it appears to only be an issue with Azjol-Nerub specifically (or at least it's not a global thing). This random character was on my screen today when I logged in, and its URL uses a hyphen, so I'm not sure what the pattern is here.

I'll mess with it some more tonight to see if I can figure it out. If not, I can add a manual override for Azjol-Nerub specifically and go from there.

tflo commented 1 year ago

This random character was on my screen today when I logged in, and its URL uses a hyphen

Weird, yes. As said, I'm in the EU region, so maybe they have really different URI standards in the different regions. I think I remember, but am not 100% sure, that some years ago Azjol-Nerub (with the hyphen) also worked here, i.e. for the en-GB Armory.

vaindil commented 1 year ago

Azjol-Nerub in the US region also doesn't use a hyphen in the URL, whereas Moon Guard does, sorry, I forgot to clarify that I checked that. I have no idea what logic is being used behind the scenes, but I'll see if I can find a pattern later today.

tflo commented 1 year ago

Even weirder then ;)

tflo commented 1 year ago

It seems it depends on what the non-normalized form is: Azjol-Nerub vs Moon Guard. The first one has a hyphen in the non-normalized form, the latter has a space.

So maybe the pattern is that a hyphen gets removed, and a space gets replaced by a hyphen?

Just tried with a random name on another realm name with space:

https://worldofwarcraft.blizzard.com/en-gb/character/eu/Aerie-Peak/Rat

…works, whereas with AeriePeak it doesn't. The non-normalized form is Aerie Peak.

Replacing en-GB with en-us shows the same behavior.

vaindil commented 1 year ago

Finally dug into this a bit tonight. The addon calls GameTooltip:GetUnit() followed by UnitFullName(unit), but the latter function always returns the normalized realm name, there doesn't seem to be a way to get the non-normalized realm name from the tooltip. This is a problem because of what the Armory URLs require. Moon Guard has a space so it needs to be Moon-Guard, but Azjol-Nerub needs to become AzjolNerub. Their normalized realm names are MoonGuard and AzjolNerub, however, so I have no way of knowing whether the capital letter in the middle of the string is due to a removed space or hyphen.

I'll have to table this for now, but I'll see if I can come up with a workaround in the future.

tflo commented 1 year ago

I just looked up how LeatrixPlus is doing it – and they are also hardcoding the "special" names:

Leatrix_Plus.lua, lines 12611–12661 ```lua if not realm then realm = GetNormalizedRealmName() end if name and realm then -- Debug -- local realm = "StrandoftheAncients" -- Debug -- Chinese armory not available if GameLocale == "zhCN" then return end -- Fix non-standard names if realm == "Area52" then realm = "Area-52" elseif realm == "AzjolNerub" then realm = "AzjolNerub" elseif realm == "Chantséternels" then realm = "Chants-Éternels" elseif realm == "ConfrérieduThorium" then realm = "Confrérie-du-Thorium" elseif realm == "ConseildesOmbres" then realm = "Conseil-des-Ombres" elseif realm == "CultedelaRivenoire" then realm = "Culte-de-la-Rive-noire" elseif realm == "DerRatvonDalaran" then realm = "Der-Rat-von-Dalaran" elseif realm == "DieewigeWacht" then realm = "Die-ewige-Wacht" elseif realm == "FestungderStürme" then realm = "Festung-der-Stürme" elseif realm == "KultderVerdammten" then realm = "Kult-der-Verdammten" elseif realm == "LaCroisadeécarlate" then realm = "La-Croisade-Écarlate" elseif realm == "MarécagedeZangar" then realm = "Marécage-de-Zangar" elseif realm == "Pozzodell'Eternità" then realm = "Pozzo-dellEternità" elseif realm == "Templenoir" then realm = "Temple-noir" elseif realm == "VanCleef" then realm = "Vancleef" elseif realm == "ZirkeldesCenarius" then realm = "Zirkel-des-Cenarius" -- Fix Russian names elseif realm == "СвежевательДуш" then realm = "Свежеватель-Душ" elseif realm == "СтражСмерти" then realm = "Страж-Смерти" elseif realm == "Ревущийфьорд" then realm = "Ревущий-фьорд" elseif realm == "ТкачСмерти" then realm = "Ткач-Смерти" elseif realm == "Борейскаятундра" then realm = "Борейская-тундра" elseif realm == "Ясеневыйлес" then realm = "Ясеневый-лес" elseif realm == "ПиратскаяБухта" then realm = "Пиратская-Бухта" elseif realm == "ВечнаяПесня" then realm = "Вечная-Песня" elseif realm == "ЧерныйШрам" then realm = "Черный-Шрам" elseif realm == "ВестникРока" then realm = "Вестник-Рока" -- Fix all other names else -- Realm name is not one of the above so fix it realm = realm:gsub("(%l[of])(%u)", "-%1-%2") -- Add hyphen after of if capital follows of (CavernsofTime becomes Cavernsof-Time) realm = realm:gsub("(ofthe)", "-of-the-") -- Replace ofthe with -of-the- (ShrineoftheDormantFlame becomes Shrine-of-the-DormantFlame) realm = realm:gsub("(%l)(%u)", "%1 %2") -- Add space before capital letters (CavernsofTime becomes Cavernsof Time) realm = realm:gsub(" ", "-") -- Replace space with hyphen (Cavernsof Time becomes Cavernsof-Time) realm = realm:gsub("'", "") -- Remove apostrophe realm = realm:gsub("[(]", "-") -- Replace opening parentheses with hyphen realm = realm:gsub("[)]", "") -- Remove closing parentheses end -- print(realm) -- Debug LeaPlusLC:ShowSystemEditBox(LeaPlusLC.BlizzardLock .. strlower(realm) .. "/" .. strlower(name)) realm = realm:gsub("-", " ") -- Replace hyphen with space LeaPlusLC.FactoryEditBox.f:SetText(escapeColor .. L["Player"] .. ": " .. name .. " (" .. realm .. ")") return end ```