tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.55k stars 214 forks source link

Question about the "random" property. #40

Closed chevcast closed 9 years ago

chevcast commented 9 years ago

Can I get some clarification on what this property is and what the different options mean? Setting it to "chat" seems to work fine but you can't whisper. So setting it to "group" also seems to work fine, and you can whisper. I don't even know what "event" does. The name of this property "random" only confuses me more. I'm new to the Twitch API as well so excuse my ignorance if this is something I should already know.

AlcaDesign commented 9 years ago

"chat", "group", and "event" refers to the type of server to connect to. "random" means a random one of these servers of the chosen type. You can instead specify a specific server and port to just choose which one you want to connect to. A chat server is just for normal chat in most channels. Group servers are for whispers and rooms. The event servers are similar to chat servers but there are fewer channels on them. Event servers are basically load balances for the big channels for events and whatnot.

chevcast commented 9 years ago

Thanks for the quick reply! Is there any reason why I would choose "chat" over "group"? It seems like group works the same way but with more functionality.

chevcast commented 9 years ago

Okay I guess I misspoke. Looks like I can't chat normally in the channel when connected to a group server, but I can whisper. I can't whisper on a chat server, but I can chat in the channel. When I'm on the actual Twitch site I can both whisper with /w and chat in the channel. Is there a way to connect to both a chat and a group server? Do I just need to do that with two clients?

var group = new irc.client(...);
var chat = new irc.client(...);

Maybe I'm still misunderstanding how these work.

AlcaDesign commented 9 years ago

You have to use 2 clients. The Twitch chat also uses both a group and chat/event connection. There's one input that gets interpreted before being sent. So /w <name> <msg> actually gets sent through the group connection.

Can Chat Can Whisper Can Access Chat Rooms
Chat :white_check_mark: :white_large_square: :white_large_square:
Group :white_large_square: :white_check_mark: :white_check_mark:
Event :white_check_mark: :white_large_square: :white_large_square:
AlcaDesign commented 9 years ago

On a bot I'm writing, I'm playing with this: (simplified)

var twitch = {
            clients: {
                    chat: new tmi.client({/* ... chat server ... */}),
                    group: new tmi.client({/* ... group server ... */}),
                    connect: function connectClients() {
                            return {    chat: this.chat.connect(),
                                        group: this.group.connect()
                                };
                        },
                    on: function on(event, callback) {
                            return {    chat: this.chat.on(event, callback),
                                        group: this.group.on(event, callback)
                                };
                        }
                },
            handleChat: function handleChat() {...}
        };

twitch.clients.connect();
twitch.clients.on('message', twitch.handleChat);

Now I can simplify some of the execution.

chevcast commented 9 years ago

Excellent. Thanks for the explanation! Great solution for combining the two clients. Let me know if I'm being a bother, but I have one more question. I see that I can handle the subscription event and get notified of new subscribers to my channel, but how do I get notified of follows? Do I have to keep polling the Twitch API for this?

AlcaDesign commented 9 years ago

As far as I know, you have to keep polling the API. There's no NOTICE for follows.

chevcast commented 9 years ago

Thanks again.