Nakilon's blog

My bot for an EFT category Twitch channel

Yesterday I read news that now half of the internet traffic comes from bots. I didn't read it in details but I can believe it. Though I have been making bots since 2004 or 2005 but still none of them were producing much traffic. I love making useful bots, utility bots, bots that perform simple one-time tasks like if they were your good internet friends. My hobby adds a new meaning to the idiom "to make friends".

Sometimes I make friends for my friends. I made a Twitch bot, and as usual for my bots it has unique functionality (I just basically don't make software without a reason and a common reason is to make a thing that wasn't made yet by anyone else). There is a stupid game Escape from Tarkov and there are "Goons" -- a special kind of strong bots with good loot, and they are "migrating" from one location to another, so volunteers are tracking them, recording their observations to a dedicated website that someone is hosting on Heroku. So my bot tracks the website to announce migrations in a Twitch chat.

I always help people. That's my de facto main life activity, main habit, main hobby, even though it's pretty much absolutely ungrateful. But whenever I see that some job can be automated I automate it to make people happy. Even though they almost never thank me, so I didn't stop on that and made another even more useful feature. People love making and sharing Twitch Clips but I don't know an easy way to find the one you want to share at the moment. So I made a clip title search command. The most trivial and obvious way to match titles with a query is Levenshtein distance. Calculating it in Ruby without installing additional gems is one of my top answers at SO (and btw the implementation is now copied from Gem to DidYouMean). But it does not work well:

  1. "лера машина" expecting "МАШИНА ЛЕРА" but getting "Лера мстит!"
  2. "тильт" expecting "это тильт" but getting "чит"
  3. "буянов" expecting "Алло, Буянов?" but getting "Чудо!"

Because Levenshtein can't swap words around and what a computer sees as "just three characters edit" is transforming the word into absolutely different one. So the algorithm should:

  1. care more about the query, not the title (i.e. rather ignore the word "это" in case 2
  2. swap words around

Finding the best swapping is a sort of so called "Assignment problem" and the most naive approach I've implemented solved all three query cases perfectly.

#algorithms #nakiircbot #ruby #twitch