tmijs / tmi.js Goto Github PK
View Code? Open in Web Editor NEW๐ฌ Javascript library for the Twitch Messaging Interface. (Twitch.tv)
Home Page: https://tmijs.com
License: MIT License
๐ฌ Javascript library for the Twitch Messaging Interface. (Twitch.tv)
Home Page: https://tmijs.com
License: MIT License
I think I've already wrote about this...
When trying to make a command to timeout users who say a certain word, I get [object Object] instead of their username
client.addListener('chat', function (channel, username, message) {
//timeout users who get salty about giveawyas
else if (message.indexOf('reroll') === 0){
client.say(channel, "/t " + username + " 30")
client.say(channel, "Please no PJSalt about the giveaways " + username + ". 30 second Timeout.")
}
});
Here's the responce:
[11:28pm] info: [#rbrockers] <rbrockers>: reroll
[11:28pm] info: [#rbrockers] Executing command: /t [object Object] 30
[11:28pm] info: [#rbrockers] <rbrockbot>: Please no PJSalt about the giveaways [
object Object]. 30 second Timeout.
[11:28pm] warn: Could not parse NOTICE from tmi.twitch.tv:
[11:28pm] warn: @msg-id=unrecognized_cmd :tmi.twitch.tv NOTICE #rbrockers :Unrec
ognized command: /t
TMI itself doesn't prevent this, so the library shouldn't either. This makes it pretty useless for balancing outgoing messages.
Also, the current behavior breaks the whisper command because it tries sending a command to the channel #jtv, which you're not in, and it just silently drops it.
Silently dropping things is also a pretty bad idea. At least log a warning about trying to send a message to a channel you're not in.
While I am able to get this simple example working:
#!/usr/bin/env coffee
irc = require 'tmi.js'
options =
options:
debug: true
connection:
reconnect: true
channels: [ '#grubbins2' ]
client = new (irc.client)(options)
client.addListener 'message', (channel, user, message, self) ->
console.log "#{user.username}: #{message}"
client.connect()
I am unable to get authentication to work at all. I am using a known good username/oauth password combo (i.e. known to work with hubot) and I have even generated a new oauth password. Both fail in the same way.
#!/usr/bin/env coffee
irc = require 'tmi.js'
options =
options:
debug: true
connection:
reconnect: true
identity:
username: 'cl4ptp2'
password: 'oauth:REDACTED'
channels: [ '#grubbins2' ]
client = new (irc.client)(options)
client.addListener 'message', (channel, user, message, self) ->
console.log "#{user.username}: #{message}"
client.connect()
Produces the error:
{ [Error: Cannot find module './build/Release/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
{ [Error: Cannot find module './build/default/DTraceProviderBindings'] code: 'MODULE_NOT_FOUND' }
[09:46pm] info: Connecting to 192.16.64.145 on port 443..
[09:46pm] info: Sending authentication to server..
[09:46pm] error: Login unsuccessful.
This looks like a great module and I am excited about supporting it! ๐ thanks!
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.
When trying to use the timeout function I'm getting this error
[12:50pm] info: [#matax91] <matax91>: google.com
/Users/jordanriser/workspace/twitch_bot/routes/api/bot.js:85
chatBot.timeout("matax91", "matax91", 1);
^
TypeError: object is not a function
at client.<anonymous> (/Users/jordanriser/workspace/twitch_bot/routes/api/bot.js:85:15)
at client.emit (events.js:118:17)
at client.handleMessage (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/lib/client.js:468:30)
at /Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/lib/client.js:602:18
at Array.forEach (native)
at client._onMessage (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/lib/client.js:600:11)
at WebSocket.onMessage (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/WebSocket.js:414:14)
at WebSocket.emit (events.js:110:17)
at Receiver.ontext (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/WebSocket.js:797:10)
at /Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:473:18
at Receiver.applyExtensions (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:360:5)
at /Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:462:14
at Receiver.flush (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:336:3)
at Receiver.opcodes.1.finish (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:478:12)
at Receiver.expectHandler (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:453:31)
at Receiver.add (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/node_modules/ws/lib/Receiver.js:91:24)
7 Sep 12:50:39 - [nodemon] app crashed - waiting for file changes before starting...
My code looks like this
chatBot.on('chat', function(channel, user, message, self){
if(self){
return true;
}
// Return if there is not a command
if(!message.match(/!\w+/g)){
// Moderate messages
if(urlRegex.test(message)){
chatBot.timeout(channel, user.username, 1);
chatBot.say(channel, "Please do not post URL's in the chat.");
}
return true;
}
...
});
Is anyone else seeing the following:
[05:23pm] error: Ping timeout.
[05:23pm] error: Sorry, we were unable to connect to chat. Reconnecting in 0 seconds..
This happens once a minute (for as long as my bot is running). TMI immediately reconnects, but I'd rather it didn't error out in the first place.
Also, it often reconnects to a different IP/port, but presumably that is expected behavior.
Here's a full dump of my app idling (note this still happens even if there is chat going on in the channel I'm in, and I haven't tried connecting to multiple rooms or no rooms):
[05:22pm] info: Connecting to 192.16.64.155 on port 80..
[05:22pm] info: Sending authentication to server..
[05:22pm] info: Connected to server.
[05:22pm] info: Joined #channelname
[05:23pm] error: Ping timeout.
[05:23pm] error: Sorry, we were unable to connect to chat. Reconnecting in 0 seconds..
[05:23pm] info: Connecting to 192.16.64.145 on port 443..
[05:23pm] info: Sending authentication to server..
[05:23pm] info: Connected to server.
[05:23pm] info: Joined #channelname
[05:24pm] error: Ping timeout.
[05:24pm] error: Sorry, we were unable to connect to chat. Reconnecting in 0 seconds..
[05:24pm] info: Connecting to 192.16.64.145 on port 443..
[05:24pm] info: Sending authentication to server..
[05:24pm] info: Connected to server.
[05:24pm] info: Joined #channelname
[05:25pm] error: Ping timeout.
[05:25pm] error: Sorry, we were unable to connect to chat. Reconnecting in 0 seconds..
Is there a way to check the connection status (timed out, connected, etc)?
Can i do something like this:
client = new irc.client({..})
//...
if (client.status == "timed_out")
client.connect();
//...
//do my other stuff here
Thanks!
By silently I mean disconnected
is not fired. Also affects the connection.reconnect
option
Case 1: start as normal then disconnect my wifi (works as expected)
CONNECTING EVENT
CONNECTED EVENT
[09:15am] error: Ping timeout.
DISCONNECTED EVENT
[09:15am] error: Sorry, we were unable to connect to chat.
Process finished with exit code 0
Case 2: Began script with wifi unplugged
[09:20am] error: Server is not accepting WebSocket connections.
Process finished with exit code 0
Script for reference
var tmi = require('tmi.js');
var client = new tmi.client({
connection: {random: 'chat'},
});
client.connect();
client.on('connecting', function() {
console.log('CONNECTING EVENT');
});
client.on('connected', function() {
console.log('CONNECTED EVENT');
});
client.on('disconnected', function() {
console.log('DISCONNECTED EVENT');
});
Seems like I need your help once more (and I couldn't register on the forums - sent you a message about that), so here goes:
I have managed to join several chats (no matter which server), and I am connected to both servers (chat and events) through:
clientEvents.connect();
clientChat.connect();
Now, when a user performs a certain action, I call the following function:
function update_chat(newchannel, oldchannel){
alert('Parting ' + oldchannel);
clientChat.part(oldchannel);
alert('Joining ' + newchannel);
clientChat.join(newchannel);
}
The variables newchannel and oldchannel are passed onto the function correctly (I see the alerts with the names of the channels) but nothing happens in the chat.
Because I figured it may have something to do with the order in which everything is declared and loaded, the order of all the code is as follows:
tmi.js is loaded in the header.
There, in a document-ready, the trigger-on-user-action part is also scripted (displayed here in a simplified version):
$('.loadstream').click( function() {
var newchannel = $(this).attr('channel');
var oldchannel = $('player_' . $(this).attr('id')).attr('channel');
// Part where the twitch player loads the new channel...
update_chat(newchannel, oldchannel);
});
Then the div id="#chat" and the main.js are loaded.
And at the bottom of the page, the aforementioned function is located.
What am I doing wrong :)? Again: the variables newchannel and oldchannel are passed on to the function correclty, so I know that for example
clientChat.part('esl_csgo');
and
clientChat.join('esl_sc2');
are being executed. However, nothing happens in the chat.There is nothing happening in the console.log either, so it seems either the clientChat.join() command doesn't reach tmi, or tmi ignores it.
(obviously, I have two functions, one update_chat for channels that are on the chat server, and one update_events with clientEvents.join() for channels that are on the events server, so that's not it either).
Since I have put some things in a function now (to facilitate multiple servers), I have also tried to make clientChat and clientEvents global variables, but this also didn't help...
window.clientChat = new irc.client(optionsChat);
However, I can send chat messages from within the update_chat function...
chatNotice('[MANUAL CHAT NOTICE] Parted ' + capitalize(dehash(oldchannel)), 1000, -1, 'chat-room-part');
clientChat.part(oldchannel);
This actually outputs the manual chat notice... Not the real one (without [MANUAL CHAT NOTICE]) though, and it doesn't actually part the channel :(
UPDATE1: I can confirm that clientChat is actually set (because if I change it back to client, I get a console error saying that client is not defined). So it's the join(channel) action that's not working...
I've been looking through tmi.js (being the javascript noob that I am, and I can see where the join() function is declared, and what it does...)
join: function join(channel) {
return this._sendCommand(null, "JOIN " + utils.normalizeChannel(channel));
}
And I can't help but wonder (since Dreamweaver colours the function green, indicating that it is an existing function) how javascript knows that join() should do something with tmi, in stead of the regular join(), which is to join two arrays together if I'm not mistaken.
UPDATE2: I've tried some other commands such as .clear(oldchannel), they also all don't work... :(
I had to change the name of the module because it is a new protocol and "IRC" doesn't make sense anymore. We are supporting WebSocket for regular chat and event chat servers. Twitch is still using IRC for group chat and we will add support for this too but we will change it to WebSocket as soon as possible.
It is supported in the most recent browsers (will post a compatibility table later) and it is better than IRC. We will be offering a version for Node.js / io.js and a standalone javascript version that you can use in your browser. Since the group chat isn't supporting WebSocket yet, this is the only thing that will not work in the browser. Take a look at the tests folder in this repository to see how to use it in a web page.
Will be deprecated and I will redirect everyone to this new module. Moving your project won't be too hard and I will post what needs to be changed so your applications don't break.
Yes.
I know, but you can still use the twitch-irc documentation and take a look at the tests folder in this repository, you will see the new configuration options. Most of the events and commands are the same as twitch-irc. The user object has changed for the "chat" and "action" events, we are now returning exactly what Twitch is sending to the client, the only thing that we are changing is the way you receive the "emotes" tag. This mean no more "specials" array. Refer to the Twitch API documentation for the IRCv3 tags being returned.
It's just better for you and for me. When Twitch change the IRCv3 tags, I have to update the module just for this minor change and sometimes, it breaks others application. Now if Twitch change the tags, you will notice it in your application and will be able to change your code on your end, not the module.
Working hard on it, but no ETA. Maybe this week ? Or next week ?
When logging the user variable from the chat
event as a broadcaster in the channel it returns null for the user-type
, mods are correctly returning mod
.
reconnect: true
behaves as expected for chats added to the initial channels
array when creating a client. However if another chat is later joined, this particular channel doesn't seem to recover after a network failure.
I reproduced with this demo, happened every time
var tmi = require('tmi.js');
var client = new tmi.client({
options: {debug: false},
connection: {random: 'chat', timeout: 10000, reconnect: true},
channels: ['yamuda', 'sqmp']
});
client.connect();
client.once('connected', function() {
console.log('Connected, now joining a new channel.');
client.join('k3nt0456');
console.log('Please trigger a network failure...');
client.once('connected', function() {
console.log('Reconnected, #k3nt0456 doesn\'t receive messages anymore...');
console.log('The other two channels are fine.');
})
});
client.on('connecting', l('connecting'));
client.on('connected', l('connected'));
client.on('disconnected', l('disconnected'));
client.on('chat', l('chat'));
function l(event) {
return function() {
console.log('EVENT: ' + event, arguments);
}
}
Thanks schmoopiie & friends ๐
Whenever I try to start my node app I get this error:
/root/node/node_modules/tmi.js/lib/client.js:177
this.log.warn(`Could not parse message with no prefix:\n${
^
SyntaxError: Unexpected token ILLEGAL
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/root/node/node_modules/tmi.js/index.js:2:9)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
18 Oct 08:13:07 - [nodemon] app crashed - waiting for file changes before starting...
I tried replacing all the ` with ' and that seems to work but then I get another error:
/root/node/node_modules/tmi.js/lib/client.js:205
this.pingLoop = setInterval(() => {
^
SyntaxError: Unexpected token )
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/root/node/node_modules/tmi.js/index.js:2:9)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
18 Oct 08:14:46 - [nodemon] app crashed - waiting for file changes before starting...
Hey! I've implemented tmi.js with the examples provided by AlcaDesign (thanks for those! huge help!) and everything seems to be working fine. Except... when I try to join one of the ESL channels (for example esl_csgo or esl_sc2, the messages don't come through.
On ESL's main channel (twitch.tv/esl) however, it works just fine...
See screenshots.
It works fine for 99% of the other channels as well. esl_csgo and esl_sc2 are the only 2 that I've found so far that didn't work...
The first sometimes happens unpredictably when using client.say(chan, message)
to send a message to a channel on the group chat servers. Even trying to send the exact same message, it'll sometimes fail every time in a row, and other times succeed every time in a row.
/path/tmi.js/node_modules/irc/lib/irc.js:923
if (c.match(/\s/)) {
^
TypeError: Cannot read property 'match' of undefined
at Client._splitLongLines (/path/tmi.js/node_modules/irc/lib/irc.js:923:10)
at /path/tmi.js/node_modules/irc/lib/irc.js:960:36
at Array.forEach (native)
at Client._speak (/path/tmi.js/node_modules/irc/lib/irc.js:959:12)
at Client.say (/path/tmi.js/node_modules/irc/lib/irc.js:946:10)
at /path/tmi.js/lib/client.js:890:22
at Object.Promise (/path/tmi.js/node_modules/vow/lib/vow.js:308:9)
at client._sendMessageIRC (/path/tmi.js/lib/client.js:888:12)
at client._sendMessage (/path/tmi.js/lib/client.js:817:21)
at client.say (/path/tmi.js/lib/client.js:1026:17)
The second sometimes happens unpredictably when receiving messages from the channel, using the following hook:
client.addListener('chat', function (channel, user, message) {
// do something
});
/path/tmi.js/node_modules/irc/lib/irc.js:748
throw err;
^
TypeError: Cannot set property 'message-type' of undefined
at client.handleGroupMessage (/path/tmi.js/lib/client.js:584:66)
at Client.<anonymous> (/path/tmi.js/lib/client.js:697:14)
at Client.emit (events.js:129:20)
at iterator (/path/tmi.js/node_modules/irc/lib/irc.js:745:26)
at Array.forEach (native)
at Socket.<anonymous> (/path/tmi.js/node_modules/irc/lib/irc.js:740:15)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)
Everything works fine when using the twitch-irc
package for the group chat servers.
Here's my example that I just wrote: https://gist.github.com/AlcaDesign/742d8cb82e3e93ad4205 It's not the cleanest and I haven't commented anything, really. There's some options at line #221 and plenty of css to adjust the notices. It does emotes, badges, multiple chats, random colors (from the official palette) where needed, time-outs, chat clearing, slight chat fading (can be adjusted in CSS), hosting, and all connection events. Should look like this in operation: This handles incoming events, though. Didn't want to add input. It's more like something you'd use in a CLR browser in OBS on your stream.
Hello all.
I had a user of my app ask, "Why don't my emotes show up?" I told them about the api and how it doesn't know which emotes you're sending, so I'd like to ask, how does anyone else work around the issue?
I would like to avoid download the >30MB file of all twitch emotes and parsing them myself, if I can.
It would be easiest if twitch sent us the message back with all the emote information. I thought that was how it worked internally, but maybe they don't resend that info.
Thoughts?
Hello!
I've been perusing the latest commits, and noticed that there is a raffle manager built-in. Are there plans to include any other type of stream-specific functionality, such as bank heists, betting, etc? Or would you leave that up to pull requests?
Upon banning someone:
@msg-id=ban_success :tmi.twitch.tv NOTICE #
channel
:username
is now banned from this room.
Unbanning:
@msg-id=unban_success :tmi.twitch.tv NOTICE #
channel
:username
is no longer banned from this room.
Unbanning when not banned:
@msg-id=bad_unban_no_ban :tmi.twitch.tv NOTICE #
channel
:username
is not banned from this room.
Timing-out:
@msg-id=timeout_success :tmi.twitch.tv NOTICE #
channel
:username
has been timed out forlength
seconds.
Attempting to run a commercial when offline:
@msg-id=bad_commercial_error :tmi.twitch.tv NOTICE #
channel
:Failed to start commercial.
(I'll try to get an example when the channel is online when I can)
I suggest this being a recommended thread for posting undocumented notice messages. ๐
I'm getting a weird error here all of a sudden with a little periodic messages script I am trying to get working.
Here is what the script looks like
minutes = 0;
messagesInterval = setInterval(function(){
minutes++;
var Messages;
Message.find({active: true}).$where(minutes+' % this.interval === 0').exec(function(err,docs){
if(err){
console.log(err);
return true;
}
if(docs.length > 0){
for(var i in docs){
chatBot.say(config.channels[0], docs[i].messageContent);
}
}
});
},60000);
In an interval of 1 minute each I am increasing the minute variable, and then with Mongoose I am finding records that are active and have an interval that is equal to the number of minutes passed. This part works.
Then inside I am just trying to loop over each record returned and say the messages content. Oddly enough it sends the message and then crashes after. Here is the full error output
[09:53am] info: [#matax91] <tax_bot>: Test message content
/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/lib/commands.js:61
if (startsWith(message.toLowerCase(), "/me ") || startsWith(message.to
^
TypeError: Cannot read property 'toLowerCase' of undefined
at client.say (/Users/jordanriser/workspace/twitch_bot/node_modules/tmi.js/lib/commands.js:61:31)
at /Users/jordanriser/workspace/twitch_bot/routes/api/bot.js:49:19
at Query.<anonymous> (/Users/jordanriser/workspace/twitch_bot/node_modules/mongoose/lib/query.js:2112:28)
at /Users/jordanriser/workspace/twitch_bot/node_modules/mongoose/node_modules/kareem/index.js:177:19
at /Users/jordanriser/workspace/twitch_bot/node_modules/mongoose/node_modules/kareem/index.js:109:16
at process._tickCallback (node.js:355:11)
7 Sep 09:53:03 - [nodemon] app crashed - waiting for file changes before starting...
I thought maybe that the model field name was conflicting with something internally because it was named message
first so I renamed to messageContent
to make sure where wasn't any conflicts with naming happening.
Here is what is being returned from my database
[ { _id: 55ed9600a9db3e9454b60954,
title: 'test',
messageContent: 'Test message content',
interval: 2,
active: true,
__v: 0 } ]
We are now providing the library on a CDN in 49 different locations with SSL support.
Use the non-minified version for better debugging and error(s) reporting:
<script src="//d2g2wobxbkulb1.cloudfront.net/0.0.17/tmi.js"></script>
Minified version (use this in production):
<script src="//d2g2wobxbkulb1.cloudfront.net/0.0.17/tmi.min.js"></script>
The Full output when trying to launch it is
[08:51am] info: Connecting to 192.16.64.145 on port 80..
[08:51am] info: Sending authentication to server..
[08:51am] warn: Could not parse NOTICE from tmi.twitch.tv:
[08:51am] warn: :tmi.twitch.tv NOTICE * :Login unsuccessful
[08:51am] error: Login unsuccessful.
And the code i'm using is
var irc = require("tmi.js");
var options = {
options: {
'debug': true
},
connection: {
'random': 'chat'
},
identity: {
'username': "<bot name>",
'password': "<oauth>"
}
};
var client = new irc.client(options);
client.connect();
i'm using versions node 0.12.7 , npm 2.11.3 and tmi.js 0.0.18 on ubuntu....any ideas on what i'm doing wrong?
I need beta testers for the current version of tmi.js. There is a documentation with all the important changes. Make a backup of your application!
I am looking for any kind of bugs you may encounter or missing features. Please post your issues here. Keep this GitHub issue for bugs and missing features only, it is not for general discussion
If you are running it without any problems, post your feedback here.
Hi, today someone just resubscribed to my channel but I couldn't catch the event with the "subscription" listener. Is there a way to catch this events ?
Thanks for your time
Hello,
I've been trying to make a simple bot. It just connects to my channel. That's it.
But when I start it up, it can't connect to the chat.
It says:
info: Connecting to 192.12.64.145 on port 443..
info: Sending authentication to server..
warn: Could not parse NOTICE from tmi.twitch.tv:
warn: tmi.twitch.tv NOTICE : Error logging in
How would I be able to get the list of users in chat? I know this may be outside of the scope of the module but if there are any tips on the best way to accomplish this it would be greatly appreciated!
After the bot connects the the channel, and even says the greeting message that we set it to do upon entering a channel, it crashes and we're given this as the error in console.
*PATH TO THE BOT*\node_modules\tmi.js\lib\client.js:608
self.userstate[utils.normalizeChannel(channel)]["message-type"] = "chat";
^
TypeError: Cannot set property 'message-type' of undefined
at *PATH TO THE BOT*\node_modules\tmi.js\lib\client.js:608:81
at Object.Promise (*PATH TO THE BOT*\node_modules\tmi.js\node_modules\vow\lib\vow.js:308:9)
at client._sendMessage (*PATH TO THE BOT*\node_modules\tmi.js\lib\client.js:594:12)
at client.say (*PATH TO THE BOT*\node_modules\tmi.js\lib\commands.js:67:21)
at client.<anonymous> (*PATH TO THE BOT*\rbrockbot.js:26:12)
at client.emit (events.js:110:17)
at client.handleMessage (*PATH TO THE BOT*\node_modules\tmi.js\lib\client.js:354:22)
at client._onMessage (*PATH TO THE BOT*\node_modules\tmi.js\lib\client.js:509:10)
at WebSocket.onMessage (*PATH TO THE BOT*\node_modules\tmi.js\node_modules\ws\lib\WebSocket.js:414:14)
at WebSocket.emit (events.js:110:17)
When trying to connect to a random group server, running the bot in Chrome, using the following options:
var options = {
options: {
debug: true
},
connection: {
random: "group",
reconnect: false
},
identity: {
username: "my_bot_name",
password: "oauth:my_oauth"
},
channels: ["#my_channel"]
};
The Chrome console gives me the following errors:
Connecting to a random chat server gives:
The bot seems to log in, and it shows chat messages in the console, however listeners for chat messages don't trigger.
For instance:
"Currently live & upcoming streams: V_Nome Stream ( http://www.twitch.tv/v_nome ) at Sun 11:00 AM PDT (3 hours ago), KinoGaming with KinoGami ( www.twitch.tv/KinoGami ) at Sun 12:00 PM PDT (2 hours ago), Culture Clash Podcast ft. Lambmower, CantWearHats & HPBraincase ( www.twitch.tv/cantwearhats ) at Sun 12:00 PM PDT (2 hours ago), UPickVG [After Hours] Rehearsal ( www.twitch.tv/upickvg ) at Sun 01:00 PM PDT (an hour ago), HPBraincase - Solo Stream ( www.twitch.tv/hpbraincase ) at Sun 03:00 PM PDT (in an hour)"
This appears to be too long to send. The node.js module "irc" would split that message and send it as two, but it seems that tmi.js is just dropping the message without error. Some kind of splitting and repeating option would be very nice for this kind of thing.
Most of our commands are supporting promises but they all return true (resolved) all the time. As of 0.0.22
, we are now returning "real" promises (resolved or rejected) when you are using the client.ban() command. Any issue regarding this change should be posted here. If there are no issues, we will do the same thing with the other commands.
Example of usage:
client.ban(channel, user.username).then(function() {
console.log("Successfully banned " + user.username + " on " + channel + "!");
}, function(err) {
console.log(err);
});
If you need help with the error codes, all of them are available in the documentation.
It just started about 10 minutes ago, where my bot was getting all the way up to the "connecting" event, but would not receive a "connected" event, or even a "connectfail" event, it would appear to just sit there. It, also, does not receive any other messages.
With Debug set to true, it should the exact same thing. It gets to the "connecting" event, but nothing after that.
I added a console.log to line 102 of client.js, right before the switch statement, to log what command was being sent by the server. The ONLY command that comes thru is 001
To make this even weirder, my bot IS able to talk in the channel if I force it to, but it does not react to anything coming back from the channel because, from the looks of it, nothing is coming back to it from the server, at least nothing I can see in any of my logs.
This issue started at around 10:00PM Eastern, Wednesday July 22nd. I had made no significant changes to my bot other than a restart, and it had been working fine with TMI.js since porting it over and getting some of the alterations done.
My best guess is there are some issues with Twitch's IRC system.
This is the error I get with the current latest codebase (d8c2e47) on Windows 8.1, running node 0.12.7 on npm 2.11.3
with this code
var irc = require('tmi.js');
var clientOptions = {
options: {
'debug': true,
},
connection: {
'random': 'chat'
},
identity: {
'username': 'ozbt',
'password': 'oauth:oauthtoken'
},
'channels': ['#ozbt']
};
// Calling a new instance..
var client = new irc.client(clientOptions);
// Connect the client to the server..
client.connect();
client.on('connected', function(channel, username, message){
client.say(channel, 'hello');
});
I've tried fixing the code myself, but I'm awful at fixing other people's code, especially when I don't know what it's doing or trying to do. Any suggestions would lovely. Any more information needed, let me know.
I was just curious, does anyone have a better method of parsing the message with the emotes array? Here's how I do it, wondering how everyone else does it.
function parseMessage(message, emotes) {
var emoteArray = _.chain(emotes)
.map(function(emote, index) {
var charIndex = _.map(emote, function(chars) {
var indexes = chars.split("-");
return {
url: "http://static-cdn.jtvnw.net/emoticons/v1/" + index + "/1.0",
startIndex: parseInt(indexes[0]),
endIndex: parseInt(indexes[1]) + 1
};
});
return charIndex;
})
.flatten()
.sortBy(function(item) {
return -1 * item.startIndex;
})
.value();
if(emoteArray.length === 0) {
return message;
}
var newMessage = message;
_.each(emoteArray, function(emote) {
var emoteName = newMessage.substring(emote.startIndex, emote.endIndex);
var leftPart = newMessage.substring(0, emote.startIndex);
var middlePart = makeImage(emoteName, emote.url);
var rightPart = newMessage.substring(emote.endIndex);
newMessage = leftPart + middlePart + rightPart;
});
return newMessage;
}
function makeImage(name, url) {
return _s.sprintf("<img alt='%1$s' title='%1$s' src='%2$s' />", name, url);
}
It works by splitting the emote positions into a flattened array with every instance of said emote. Then I work backwards for every emote and string replace the position into an anchor tag (makeImage method).
Please, update to the latest version of Node.js if you haven't done that already as we will be using ES6 features only supported in this major version. If for some reasons you can't update to Node.js 4.x, you will have to use a transpiler like Babel or try running your application using the --harmony
flag. You may ignore this if you are using the built .js file. (the one available on our CDN)
The non-minified built .js version on our CDN will no longer be available as we will be providing you with a SourceMap instead. To prevent any errors, we will still provide a tmi.js
and tmi.min.js
but both of them will be minified. If you are not familiar with SourceMaps, you may want to read this guide.
We will be moving our website to a dedicated server provided by SoftLayer next month. We will do our best to keep the website up and running. The website source-code (everything but the forums) will be available in this repository so that everyone can contribute to it. We are also changing a few things regarding the documentation to fix this issue.
Thank you,
Schmoopiie!
Hello,
I was reading about some of the membership functionality, https://github.com/justintv/Twitch-API/blob/master/IRC.md#membership. In here we have to explicitly request functionality from twitch, does tmi.js do any of this natively? If not, can we add commands or something to the configuration object to do it automatically on join?
[12:09am] warn: Could not parse NOTICE from tmi.twitch.tv:
[12:09am] warn: @msg-id=msg_ratelimit :tmi.twitch.tv NOTICE #<channelremoved> :Your message was not sent because you are sending messages too quickly.
As mentioned on the forums, when using .say() the emotes data isn't updated and is always null.
client.on('chat', function(channel, user, message, self) {
client.say(channel, 'i heard you');
});
results in this:
[02:21pm] info: [#d1nky] <xslimbotx>: i heard you
...
[02:21pm] info: [#d1nky] <xslimbotx>: i heard you
[02:21pm] info: [#d1nky] <xslimbotx>: i heard you
[02:21pm] info: [#d1nky] <xslimbotx>: i heard you
[02:21pm] info: [#d1nky] <xslimbotx>: i heard you
undefined:0
(null)
RangeError: Maximum call stack size exceeded
This works fine with the twitch-irc
module.
All the codes:
var irc = require('twitch-irc'); // switch to 'tmi.js' to break
var options = {
options: {
debug: true,
debugIgnore: ['ping', 'chat', 'action']
},
identity: {
username: "xslimbotx",
password: "oauth:<redacted>"
},
channels: ["#d1nky"]
};
var client = new irc.client(options);
// Connect the client to the server..
client.connect();
client.on('chat', function(channel, user, message, self) {
client.say(channel, 'i heard you');
});
if you do client.say('some_channel', 'yo') and you haven't joined the channel it crashes, but still sends the message to the channel. A highly avoidable scenario but error nonetheless...
Error message:
C:\Program Files\nodejs\node_modules\tmi.js\lib\client.js:738
self.userstate[utils.normalizeChannel(channel)]["message-type"] = "chat";
TypeError: Cannot set property 'message-type' of undefined
So I started testing tmi.js to move with my bot soon. Here are two problems I found:
The moderators of a channel are not sent via PRIVMSG but via NOTICE now. That means if you request the moderators via /mods you will never trigger the event for "mods" when you are connected to a chat server. Same goes for color (which is nobody triggered yet). This results in this warn messages.
[01:56pm] warn: Could not parse NOTICE from tmi.twitch.tv:
[01:56pm] warn: @msg-id=room_mods :tmi.twitch.tv NOTICE #efficiencyvi :The moderators of this room are: annikenly, generalm13, mythiey, yaybotio
[01:56pm] warn: Could not parse NOTICE from tmi.twitch.tv:
[01:56pm] warn: @msg-id=color_changed :tmi.twitch.tv NOTICE #efficiencyvi :Your color has been changed.
Another problem I found. Connecting to a group server is not really reliable, resulting in warnings like this:
[02:18pm] warn: Could not parse message with no prefix:
[02:18pm] warn: {"command":"HTTP/1.1","rawCommand":"HTTP/1.1","commandType":"normal","args":["400","Bad","Request"]}
The only solution is to stop and reinitialize the connection to get another group server. However tmi.js should stop the connection on this error and try another server by itself because the connection will never be established.
Not sure if this happens if you check the logging somewhere else (I think there is a way but the documentation wasn't clear on it the last time I checked) but this is from the console itself. It might also happen with other parsing errors, but this is the one I ran into anyway.
If you run into an parsing error, this is what is shown.
[11:59pm] warn: Could not parse NOTICE from tmi.twitch.tv:
[object Object]
As you can see, I can't see what the NOTICE actually is because Node truncates it. I can actually find out what it is though if I go into client.js and add a console.log(message)
, which logs the object properly.
This might just be a Node thing, but I thought I'd post it as an issue anyway.
Here's the notice I was getting in my case, so it can be added:
{ raw: '@msg-id=not_hosting :tmi.twitch.tv NOTICE #CHANNEL :No channel is currently being hosted.',
tags: { 'msg-id': 'not_hosting' },
prefix: 'tmi.twitch.tv',
command: 'NOTICE',
params: [ '#CHANNEL', 'No channel is currently being hosted.' ] }
...and here's another hosted relating one I realised wasn't in there but can still happen (and would be useful in my case):
{ raw: '@msg-id=bad_host_rate_exceeded :tmi.twitch.tv NOTICE #CHANNEL :Host target cannot be changed more than 3 times every half hour.',
tags: { 'msg-id': 'bad_host_rate_exceeded' },
prefix: 'tmi.twitch.tv',
command: 'NOTICE',
params:
[ '#CHANNEL',
'Host target cannot be changed more than 3 times every half hour.' ] }
Not sure what happened, but about a day or so ago, our bot started reporting "Server is not accepting WebSocket connections. Reconnecting in 10 seconds" and is no longer able to connect to Twitch IRC.
Has anything happened with the Twitch IRC systems that is just not playing nice with TMI.js?
I have checked the oauth keys that I use for our Bot account and Primary account, as well as regenerated them, and they are still unable to connect.
Basically, I dynamically make an array of the top 100 channels on twitch in order to listen in chat for driveby malware links, however, this keeps happening:
And it happens fore a couple of channels in sequence then stops. Later on, I get disconnected from twitch chat as if I am joining channels too fast. I'm not really sure what's causing it...
var channelCount = 0;
client.on('join', function (channel, username) {
channelCount++;
console.log("[" + channelCount + "/" + channels.length + "] Joined " + channel);
});
That is the code I'm using for the prints, and channels.length is 100 in that context.
I'm trying to do command, that will get number of viewers and say that number into the chat. But when i trying to do this, i get:
G:\Program Files\nodejs\node_modules\tmi.js\lib\api.js:39
callback(err, res, body);
^
TypeError: undefined is not a function
at Request._callback (G:\Program Files\nodejs\node_modules\tmi.js\lib\api.js:39:13)
at Request.self.callback (G:\Program Files\nodejs\node_modules\tmi.js\node_modules\request\request.js:198:22)
at Request.emit (events.js:110:17)
at Request.<anonymous> (G:\Program Files\nodejs\node_modules\tmi.js\node_modules\request\request.js:1057:14)
at Request.emit (events.js:129:20)
at IncomingMessage.<anonymous> (G:\Program Files\nodejs\node_modules\tmi.js\node_modules\request\request.js:1003:12)
at IncomingMessage.emit (events.js:129:20)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
The code is
client.on("chat", function (channel, user, message, self) {
if (message.toLowerCase() == '!v') {
client.api({
url: "https://api.twitch.tv/kraken/streams/" + channel,
methon: "GET",
headers: {
"Accept": "application/vnd.twitchtv.v3+json",
"Authorization": "OAuth ",
"Client-ID": ""
}
}), function (err, res, body) {
console.log(body);
}
}
});
How can i fix this?
I updated the guidelines for contributing. This change is for the website (only the frontpage is available at this time). We are using webhooks on GitHub to retrieve all the commits in realtime and push it in the changelog. Changes to the documentation in this repository will also appear on the website automatically. If you have any questions about this, contact me on Twitter.
Trying to get the message-type
value but it comes out as undefined. I can see it's there when just logging the user object, but it can't be reached otherwise.
Using a deep clone in jQuery, you can see that it doesn't see it either:
client.on('chat', function(channel, user, message) {
console.log(jQuery.extend(true, {}, user), user);
});
In just Node.js
client.on('chat', function(channel, user, message) {
console.log(user['message-type']);
});
Adding message-type
myself ...
tmi.on('action', function(channel, user, message) {
user['message-type'] = 'action';
handleChat(channel, user, message);
});
tmi.on('chat', function(channel, user, message) {
user['message-type'] = 'chat';
handleChat(channel, user, message);
});
Works just fine
Spent an hour trying to figure out what was wrong with my app, but turns out it also happens with this really simple demo
Steps to reproduce:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="//d2g2wobxbkulb1.cloudfront.net/0.0.23/tmi.js"></script>
</head>
<body>
<script>
var client = new irc.client({
options: {debug: false},
connection: {random: 'chat', timeout: 10000, reconnect: true},
channels: ['k3nt0456']
});
client.connect();
client.on('connecting', l('connecting'));
client.on('connected', l('connected'));
client.on('disconnected', l('disconnected'));
client.on('chat', l('chat'));
function l(event) {
return function() {
console.log('EVENT: ' + event, arguments);
}
}
</script>
</body>
</html>
Hi!
I'm finally getting around to porting Streen over to tmi.js. For what it's worth, twitch-irc is still pretty stable so I haven't felt a huge amount of pressure to port (good job!).
Things seem to mostly be working well, however I'm getting a large amount of spammed join/part events. I'm not sure why. It seems like every 30 seconds or so I get about 10 join/part events that all print at once for most (but not all) channels that my bot is in. Any thoughts on why this might be happening, and where I should look to further troubleshoot?
P.S. I tried to register an account on the tmi.js forums to post this there instead, but every attempt resulted in the following error:
Thanks!
Lange
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.