Gocnak / Botnak

A Java-based IRC chat client with focus on Twitch.tv streams.
https://gocnak.github.io/Botnak
MIT License
68 stars 28 forks source link

FrankerFaceZ Support #77

Closed jbzdarkid closed 9 years ago

jbzdarkid commented 9 years ago

User list: http://frankerfacez.com/users.txt http://frankerfacez.storage.googleapis.com/" + user + "/" + emoteName + ".png

The internal loader uses:

var USERS_FILE_URL = 'users.txt';
var macrosLoaded = false;
window.lines = new Array();
var emotecount = 0;
var usercount = 0;

function parseUsers() {
    $.get(USERS_FILE_URL, function(data) {
        window.lines = data.split(/[\r\n]+/);
    }, 'text').done(function() {
        loadEmotes();
    });
}

function loadEmotes() {
    usercount = 0;
    emotecount = 0;
    $('#emotescontent').empty();
    var finalHTML = '';
    var currentUser = '';
    var search = window.location.hash.replace("#", "").toLowerCase();
    var searchindex = 0;
    var newlines = new Array();
    while (searchindex < lines.length) {
        if (search == "") {
            newlines[0] = "global";
            for (var i = 1; i < lines.length; i++) {
                if (lines[i].charAt(0) != '.') {
                    usercount++;
                } else {
                    emotecount++;
                    if (usercount == 0) {
                        newlines[i] = lines[i];
                    }
                }
            }
            break;
        }
        while (searchindex < lines.length) {
            searchindex++;
            if (searchindex >= lines.length) break;
            if (lines[searchindex].charAt(0) == '.') continue;
            if (lines[searchindex].indexOf(search) == 0) break;
        }
        if (searchindex >= lines.length) break;
        newlines[newlines.length] = lines[searchindex];
        var emotesearch = searchindex + 1;
        while (lines[emotesearch].charAt(0) == '.') {
            newlines[newlines.length] = lines[emotesearch];
            emotesearch++;
        }
    }
    for (var i = 0; i < newlines.length; i++) {
        if (newlines[i].charAt(0) != '.') {
            currentUser = newlines[i];
            if (i > 0) {
                finalHTML += '</div>';
            }
            $('#emotescontent').append(finalHTML);
            finalHTML = '<a id="' + newlines[i] + '" class="emoteanchor"></a><div id="' + newlines[i] + '" class="emotetitle">';
            finalHTML += newlines[i];
            usercount++;
            finalHTML += '</div><div id="' + newlines[i] + '" class="emotecontainer">'
        } else {
            finalHTML += '<div class="emote"><div class="imgcontainer"><img class="lazy" src="images/blank.gif" data-original="http://cdn.frankerfacez.com/channel/' + currentUser + '/' + newlines[i].substring(1) + '.png"></div><p>' + newlines[i].substring(1) + '</p></div>';
            emotecount++;
        }
    }
    finalHTML += '</div>';
    $('#emotescontent').append(finalHTML);
    $("img.lazy").lazyload({
        effect: "fadeIn",
        event: "loadEmote"
    });
    finalHTML = '<h3>Channels: ' + usercount.toString() + '<br />Emotes: ' + emotecount.toString() + '</h3>';
    $('#emotescontent').append(finalHTML);
    $(document).trigger("parseComplete");
}
$(document).on("parseComplete", function() {
    $('.emotetitle').click(function() {
        var container = '#' + this.id + '.emotecontainer';
        $(container).slideToggle('fast');
        $(container + ' img.lazy').trigger('loadEmote');
    });
});
mikesmiffy128 commented 9 years ago

I just discovered the user list is redundant because the API base URL you linked sends an XML which has names of all the files in the CDN, so you just need to parse that with SAX or something, then parse out the last part of each path minus the .png, add that to a map or something and then use that to look for emotes in chat.

mikesmiffy128 commented 9 years ago

And for downloading them of course you just request each path and save the files somewhere. I would suggest implementing on-demand downloading if this is to be integrated though because there are a LOT of emotes which will only sometimes get used. And currently chat emotes which aren't downloaded are never substituted. I should maybe make that a separate issue.

jbzdarkid commented 9 years ago

It would probably be easiest to do both in one patch, since creating an on-demand system is going to involve rewriting a decent bit of the current emote code, as would adding FFZ emotes. FFZ has special Donator and Bot icons. Image url is: http://cdn.frankerfacez.com/channel/global/LilZ.png http://cdn.frankerfacez.com/channel/00greenbean00/BeanAhab.png

jbzdarkid commented 9 years ago

I'm not really clear on how you would actually use FFZ emotes. As far as I see, they only function on the channels they were created for, except for the global emotes.

mikesmiffy128 commented 9 years ago

Well you could add a check to make sure a user is in the correct channel, or of course make it configurable whether or not to just always allow FFZ emotes.

jbzdarkid commented 9 years ago

I'm just wondering why people want them if they can't normally use them. I suspect I'm missing something...

mikesmiffy128 commented 9 years ago

Well, if you use Botnak as a general chat client you be in another channel. Smaller channels might also use Botnak and have their own emotes. Also, I thought it could be an idea to add an option (off by default) to show all emotes in Botnak, although I just realised that may be less useful as other people will not see the emotes.

jbzdarkid commented 9 years ago

So in fact, botnak can just get an array of valid emote names for the channel. There shouldn't even be that many, most channels have 10-30.

Gocnak commented 9 years ago

Just a note: I'm not allowing support for the custom mod icons. Sorry.

Gocnak commented 9 years ago

http://frankerfacez.storage.googleapis.com/ is deprecated. The updated cdn.frankerfacez.com URL is current.

jbzdarkid commented 9 years ago

Yes, but it's private. I was planning on using the googleapis page for the listing and getting images from cdn.frankerfacez.com.

Gocnak commented 9 years ago

In that case use the users.txt URL.

But my idea for the implementation was going to be on a per-channel basis. When you request to join a channel, it'll also throw a request for FFZ to check and download the faces of the channel on another thread.

There's not gonna be a text document saving for this, but rather folders of everyone's FFZ emotes per channel in a "FrankerFaceZ" folder, which will be scanned on boot, and updated on channel join.

jbzdarkid commented 9 years ago

It doesn't really look like the data is available per-channel, so this is going to be referencing the entire users.txt anyways. I see the merit of downloading faces on-demand, though, there are a lot of them.

Gocnak commented 9 years ago

Yeah, I'll be parsing the .css files.

For example: http://cdn.frankerfacez.com/channel/geoff.css

mikesmiffy128 commented 9 years ago

That seems to be awfully complex way of going about it...