crackededed / Xtra

Xtra is a Twitch player and browser for Android.
GNU Affero General Public License v3.0
1.25k stars 48 forks source link

Improve emotes search with regex #421

Closed E-Bosher closed 10 months ago

E-Bosher commented 10 months ago

Currently typing emotes in chat through leading ":" is extremely uncomfortable since you have to start with the first letter and type most part of emote name in and most emotes in a channel have the same prefix, sometimes quite a long one.

If replaced with regex comparison you can make this a lot more flexible by typing a few random letters from the emote name. It will drastically improve the simplicity of emotes usage.

For example, the search for abcde input should be through this regex:

/a\S*?b\S*?c\S*?d\S*?e/i

I am not familiar with Kotlin, so the next example is provided in JavaScript, it can be copied and pasted in browser console.

// example array of emote names
var teststrarray = [
    "docReadyToFaint",
    "doctorWTF",
    "docAlmostFaint"
];

// letters printed in chat after colon for emote search
var inputstr = "dcfn";

// building regex from chat input
var regphrase="";
for (let i=0, len=inputstr.length; i<len; i++) {
    regphrase+=inputstr[i]+"\\S*?";
}
var reg = new RegExp(regphrase, "i");

// testing emotes vs regex
for (let i=0, len=teststrarray.length; i<len; i++) {
    if (reg.test(teststrarray[i])) {
        console.log(inputstr + " found in " + teststrarray[i]);
    } else {
        console.log(inputstr + " not found in " + teststrarray[i]);
    }
}

The output is: dcfn found in docReadyToFaint dcfn not found in doctorWTF dcfn found in docAlmostFaint

crackededed commented 10 months ago

i've added this regex now