Open melon-ggenkov opened 2 years ago
It looks like the Search Categories
API endpoint does not make any guarantees about the order of returned results. I haven't verified but it's possible they are sorted by id instead of by relevance which is what the searchbar does.
Right now the bot simply takes the first result, I'm not sure if there's something we can reasonably do to figure out the best match ourselves. We could hardcode some inputs to resolve to the correct category name before the request gets sent (e.g. transforming "GTA 5" into "Grand Theft Auto V"), which is a very hacky way around the issue, but it's the best I came up with on the spot. https://github.com/udoprog/OxidizeBot/blob/828580c980cc5ad61668c1f8a874c5add345b819/bot/src/module/misc.rs#L167-L175
I have now checked and the API call results are sorted by ID. Unless someone at Twitch feels like making an endpoint that would search by relevance, the best option is probably to hack together something to dig through the results.
Hm. How about presenting alternatives to the user?
!game GTA V
udoprog -> Your request matches more than one category;
1) GTA III,
2) GTA V.
udoprog -> Please type !game followed by the number of the category you want, like !game 1 for "GTA V" above.
I'd be worried about this polluting the chat too much. For something like "GTA 5" there are already 7 results, for "Art" it is over 20 (I didn't bother paging through all of them). Some can also get really long like "Grand Theft Auto: Vice City – The Definitive Edition" which doesn't even fit on one line.
A good compromise might be to look for the exact match first and if there isn't one either give the user some alternatives or an error message in case there are too many. The unfortunate thing in that case is that doing !game GTA 5
still wouldn't give the desired result, but that's something we might have to live with considering the Twitch API doesn't support our use case.
The !game command seems to pick weird categories. I'm not sure if this is the bot's fault or Twitch's. It doesn't seem to follow neither closest match nor the way the search results are ranked when using Twitch's searchbar.
ArtRageous! isn't even on the list on Twitch's searchbar.
Self explanatory
I would expect it to potentially confuse it with GTA Vice City here (like Twitch search does) but III is even weirder.
Twitch's searchbar correctly shows Grand Theft Auto V here