udoprog / OxidizeBot

High performance Twitch bot in Rust
https://setbac.tv
Apache License 2.0
157 stars 23 forks source link

!game command behaving weirdly #144

Open melon-ggenkov opened 2 years ago

melon-ggenkov commented 2 years ago

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.

image ArtRageous! isn't even on the list on Twitch's searchbar.

image Self explanatory

image I would expect it to potentially confuse it with GTA Vice City here (like Twitch search does) but III is even weirder.

image Twitch's searchbar correctly shows Grand Theft Auto V here

pavelpilar commented 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

pavelpilar commented 2 years ago

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.

  1. For queries like "GTA 5", put together a mapping to the correct category name
  2. For "Art", loop through all of the results and look for an exact match
  3. For the rest, either take the first result like now or let the universe decide and pick a random one
udoprog commented 2 years ago

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.
pavelpilar commented 2 years ago

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.