mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2014
Posts: 13
S
Shakar Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2014
Posts: 13
Hello there,
I have been working on some features for a twitch mIRC bot and I have come across a problem with the subscription check.

Firstly, I would like to point out that, whereas I know about the TWITCHCLIENT 2 command, I would not like to use it.

I have managed to get an incomplete list of a subscribers (Twitch limits a maximum of 100 entries per page and I have not been able to find out a solution to run the query more than once in the same socket)

And even with this list, when I try to $json($read(datafile.txt), subscriptions, user, %i) I get an error: * Line too long: $replace (line 8, json.mrc)

I am using this as part of the socket to fetch the subscriber's list
Code:
hadd %sockname request /kraken/channels/ $+ $mid(%chan,2-) $+ /subscriptions?limit=100
hadd %sockname method GET

And as a result it writes the information to a file that I named datafile.txt. Having them stored locally is just a temporary solution, as I am planning to have them on a MySQL database

So, my questions are:

  • 1) How would it be possible to run hadd %sockname request /kraken/channels/ $+ $mid(%chan,2-) $+ /subscriptions?limit=100&offset=0
    and then
    hadd %sockname request /kraken/channels/ $+ $mid(%chan,2-) $+ /subscriptions?limit=100&offset=100
    in the same socket
  • 2) How would it be possible to read the content from the data file using $json to check if the user is subscribed?


Thank you very much in advance,

Last edited by Shakar; 02/05/14 07:28 PM.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
That code looks familiar :p

For the first point, at the moment I just open another socket after the first is complete. If you want, you can try adding a Connection: Keep-Alive header and keeping track of how many bytes you receive (to know when to send the next request and close the socket).

For the second point, the $json alias handles reading the file. Just supply the file name, don't use $read.

I have some code that retrieves a full list of followers, getting subscribers would be done the same way: https://gist.github.com/memnochxx/5676bef5707a8019f0ca

Joined: May 2014
Posts: 13
S
Shakar Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2014
Posts: 13
Haha Indeed, I based it on your code for the twitch commercial socket from another thread

I tried without $read in the $json but then I get a
Code:
/echo: insufficient parameters
when I try to echo it to test

This is what I am trying to run when I get the insufficient parameters error
Code:
//echo -a $json(%testfile, subscriptions, user, display_name, 1)

And according to https://github.com/justintv/Twitch-API/blob/master/v2_resources/subscriptions.md#example-response the example response should fit this /echo

And thank you very much for that code

Last edited by Shakar; 02/05/14 08:27 PM.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
Subscriptions is an array so the next argument should be the index you want to reference (0 based):
Code:
//echo -a $json(%testfile, subscriptions, 0, user, display_name)

Joined: May 2014
Posts: 13
S
Shakar Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2014
Posts: 13
Thank you very much, Loki!

Joined: May 2014
Posts: 13
S
Shakar Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2014
Posts: 13
Just a question,

Everything was working fine yesterday, but for some reason, today, the bot was reading $json(%data,status) as blank (It would say: Title: )

I was wondering if there was a workaround for it, or if it would work as well if I just set it to $json(https://api.twitch.tv/kraken/channels/<channel>, status).

I checked both the header and data files and everything appears to be fine, but $json won't read the files for some reason

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
I'm not going to say it's impossible, but you would need to edit json identifier (javascript and an activex object) to add the oauth header and support PUT requests. If the header and data files are correct I can't speak as to why the json alias wouldn't be working.

Joined: May 2014
Posts: 13
S
Shakar Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2014
Posts: 13
I have just realized Twitch API Servers were on the fritz yesterday.
It's all good now, thanks =]

Joined: May 2014
Posts: 13
S
Shakar Offline OP
Pikka bird
OP Offline
Pikka bird
S
Joined: May 2014
Posts: 13
Sorry for the constant double post, but this is my final question.

I am running the bots on a Windows Server 2008
One of the bots is being run on the Administrator account
For some reason, the bots are only able to use $json in a local file if they are being run on the Administrator account even if the other accounts are members of the administrator group. If I use $json pointing to an URL it runs fine, but when it tries to run $json(%data, subscriptions).count, or any of the other files for that matter, it says * /echo: insufficient parameters, but if I try an URL it runs fine.

I checked the data.txt file and all the information is there

Does this even make sense?

Last edited by Shakar; 04/05/14 10:34 PM.

Link Copied to Clipboard