Skhmt / tapic

Twitch API & Chat. A javascript library for doing things with twitch chat, APIs, and pubsub. Can be used to make a HTML or Node.js bot. Or something.
MIT License
18 stars 5 forks source link

TAPIC.emit Invalid Parameters #8

Closed Chifilly closed 7 years ago

Chifilly commented 7 years ago

If I try and use TAPIC.emit, I get;

Invalid parameters. Usage: TAPIC.emit(eventName, eventDetail);

except if I use the follow and host events. I tested follow, sub, bits and host. I'm assuming it wants a JSON.stringify entry for eventDetails since it fails if I use an object, but it makes things inconsistent because if you fire the event manually, it only works if you send a string, and then the event itself returns a string instead of an object, but if the event is fired normally, it returns an object (at least I assume it returns an object, I don't have a way of testing it, and in the example, it indexes into an object and there's no JSON.parse).

The reason this is an issue for me is when the event fires, I want to store a JSON.stringify version in a file, but if you JSON.stringify a string, it comes out all weird with a lot of escaped characters, and it needs parsing twice

Skhmt commented 7 years ago

You mean TAPIC.emit ?

Can you paste in some code that doesn't work as intended and explain what exactly you're trying to do with it?

I made TAPIC.emit() to be complete in the API, but I didn't think anyone else would use it to be honest, although I do use it internally for all the events.

Skhmt commented 7 years ago

Although eventDetail really shouldn't have a string type check.

Chifilly commented 7 years ago

This is an example I am sending to TAPIC.emit (yes I did mean emit, dunno why I put event)

TAPIC.emit('sub', {
    name       : 'chifilly',
    user_id    : 25634037,
    user_type  : 'streamer',
    room_id    : 25634037,
    months     : 24,
    resub      : true,
    plan       : 'Prime',
    planName   : 'Twitch Prime',
    sysMsg     : 'chifilly\shas\ssubscribed\sfor\s6\smonths!',
    joinedText : 'best stream ever!'
});

This returns the error

Invalid parameters. Usage: TAPIC.emit(eventName, eventDetail);

But if I JSON.stringify the object, it works fine, but it causes the side-effect explained in my first post. And the reason I'm using TAPIC.emit is because it's really useful for testing callbacks.

Skhmt commented 7 years ago

I know what's wrong but can't fix it for a day or so, sorry. It's just the type checking as I thought.

Chifilly commented 7 years ago

No worries, thanks for the super fast response though :)

Skhmt commented 7 years ago

should be fixed

Chifilly commented 7 years ago

Is the NPM package updated, or do I need to include the git repo manually?

Skhmt commented 7 years ago

Oh I knew I forgot something. Npm isn't updated but GitHub is.

Skhmt commented 7 years ago

NPM updated, let me know if it works

Chifilly commented 7 years ago

Just got around to testing it, and it works perfectly now, thanks very much :)