Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Emote support for Twitch emotes #4

Closed
dialogik opened this issue Jan 24, 2021 · 6 comments
Closed

Add Emote support for Twitch emotes #4

dialogik opened this issue Jan 24, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@dialogik
Copy link
Member

The message.tag object contains a emote object with information about emotes in the message (id of emote and start/end positions in the message.message string.

Add support for Twitch emotes by adding a TwitchEmote component that can be passed the id of the emote. This id can then be used to fetch emote image path information via the Twitch API. Image (or handled error) should be returned.

Next step is replacing the emote string (e.g. KappaRoss) by the before mentioned TwitchEmote <img> element.

@dialogik dialogik added the enhancement New feature or request label Jan 24, 2021
@dialogik dialogik self-assigned this Jan 24, 2021
@dialogik
Copy link
Member Author

@dialogik
Copy link
Member Author

Browserify above mentioned node package https://wzrd.in/standalone/twitch-emoticons@latest

@dialogik dialogik changed the title Add Twitch emote support Add Emote support for Twitch emotes, BTTV und FrankerFaces Jan 30, 2021
@dialogik
Copy link
Member Author

See @YannickFricke's (a.k.a. isEven 😉) solution on this one https://gist.github.com/YannickFricke/09b6d716fc6490b4ee6bf8d9ebc10cdd

@dialogik
Copy link
Member Author

Let's do this easy peasy (at least for Twitch emotes)

function formatEmotes(text, emotes) {
    var splitText = text.split('');
    for(var i in emotes) {
        var e = emotes[i];
        for(var j in e) {
            var mote = e[j];
            if(typeof mote == 'string') {
                mote = mote.split('-');
                mote = [parseInt(mote[0]), parseInt(mote[1])];
                var length =  mote[1] - mote[0],
                    empty = Array.apply(null, new Array(length + 1)).map(function() { return '' });
                splitText = splitText.slice(0, mote[0]).concat(empty).concat(splitText.slice(mote[1] + 1, splitText.length));
                splitText.splice(mote[0], 1, '<img class="emoticon" src="http://static-cdn.jtvnw.net/emoticons/v1/' + i + '/3.0">');
            }
        }
    }
    return splitText.join('');
}

(Thanks to @Flosing)

@dialogik dialogik changed the title Add Emote support for Twitch emotes, BTTV und FrankerFaces Add Emote support for Twitch emotes Jan 31, 2021
@dialogik
Copy link
Member Author

Moved BTTV and FFZ to #16.

@dialogik
Copy link
Member Author

dialogik commented Feb 1, 2021

There were still some problems with special character emotes (such as :) or :() that have caused the RegExp to fail. This has been fixed in 69690c7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant