mIRC Home    About    Download    Register    News    Help

Topic Options
#253257 - 06/06/15 07:15 AM Twitch groups + sockets = pain
splinny Offline
Fjord artisan

Registered: 14/05/15
Posts: 249
Twitch has its own chat groups, and to check which you are invited at (or created) you can check http://chatdepot.twitch.tv/room_memberships?oauth_token=[your_oauth_token_(w\o_"oauth:")]. And this link works fine with JSON.
And i found an old list of commands to manage this groups via sockets, but only DELETE works fine (each requires oauth_token=[your_token]):
to create: POST https://chatdepot.twitch.tv/rooms?irc_channel={irc_channel}&display_name={display_name}
to modify: PUT https://chatdepot.twitch.tv/rooms/{irc_channel}?public_invites_enabled={public_invites_enabled}&display_name={display_name}
({public_invites_enabled} = 1 or 0)
to invite: POST https://chatdepot.twitch.tv/room_memberships?irc_channel={irc_channel}&username={username}
to delete: DELETE https://chatdepot.twitch.tv/rooms/{irc_channel}

I tried firefox plugin to check headers and requests, which are sent when you use twitch`s own interfce to do this actions, and it looks same, but using sockets i get only "400 Bad Request". So is it possible to recreate browser`s actions via sockets? Maybe i am missing something.
_________________________
Dont give a fish - teach to fish!

Top
#253260 - 06/06/15 09:15 AM Re: Twitch groups + sockets = pain [Re: splinny]
westor Offline
Hoopy frood

Registered: 27/12/08
Posts: 1511
Loc: Greece
Well 400 code error is that you are trying to PUT/DELETE/GET/POST an incorrect link, also it would be good to show us your code so it can be more clear.
_________________________
Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-

Top
#253261 - 06/06/15 09:21 AM Re: Twitch groups + sockets = pain [Re: westor]
splinny Offline
Fjord artisan

Registered: 14/05/15
Posts: 249
alias test {
if ($sock(test)) { sockclose test }
sockopen test chatdepot.twitch.tv 80
; sockmark test $1
}

on *:sockopen:test:{
sockwrite -n $sockname POST https://chatdepot.twitch.tv/room_members...e=2nd_user_name HTTP/1.1
sockwrite -n $sockname Host: $sock($sockname).addr
sockwrite -n $sockname user-agent: Mozilla/*
sockwrite -n $sockname Connection: close
sockwrite -n $sockname $crlf
}

on *:sockread:test:{
if ($sockerr > 0) return
:nextread
sockread %temp
if ($sockbr == 0) return
echo -ag 1: %temp
goto nextread
}
_________________________
Dont give a fish - teach to fish!

Top
#253263 - 06/06/15 09:33 AM Re: Twitch groups + sockets = pain [Re: splinny]
westor Offline
Hoopy frood

Registered: 27/12/08
Posts: 1511
Loc: Greece
First of all you are trying to connect into an SSL server but your /sockopen does not has the correct port and did not had -e parameter (/help /sockopen)

Second you dont have to put the HOLE url link into the POST.

And please next code post please use "[ code ] [ /code ]" forum quotes because the copy paste (e.g: the link) was incorrect.

Give a try this:

Code:
alias testt {
  if ($sock(testing)) { sockclose testing }
  sockopen -e testing chatdepot.twitch.tv 443
  ; sockmark test $1
}

on *:sockopen:testing: {
  if ($sockerr) { sockclose $sockname | return }
  sockwrite -nt $sockname POST /room_memberships?oauth_token=my_token&irc_channel=_my_channel_1433531105324&username=2nd_user_name HTTP/1.1
  sockwrite -n $sockname Host: $sock($sockname).addr
  sockwrite -n $sockname User-Agent: Mozilla/*
  sockwrite -n $sockname Connection: close
  sockwrite -nt $sockname $crlf
}

on *:sockread:testing:{
  if ($sockerr) { sockclose $sockname | return }
  sockread %temp
  if ($sockbr) { echo 2 -a READ: $left(%temp,4098) }
}


I cannot full test it because i dont have the oauth token.
_________________________
Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-

Top
#253265 - 06/06/15 09:48 AM Re: Twitch groups + sockets = pain [Re: westor]
splinny Offline
Fjord artisan

Registered: 14/05/15
Posts: 249
READ: HTTP/1.1 400 Bad Request
READ: Server: nginx
READ: Date: Sat, 06 Jun 2015 08:46:47 GMT
READ: Content-Type: text/plain; charset=utf-8
READ: Content-Length: 120
READ: Connection: close
READ:

Code:
To get your token - http://www.twitchapps.com/tmi/
To get channel name - create group at twitch chat and check http://chatdepot.twitch.tv/room_memberships?oauth_token=YOUR_TOKEN
_________________________
Dont give a fish - teach to fish!

Top
#253267 - 06/06/15 10:45 AM Re: Twitch groups + sockets = pain [Re: splinny]
westor Offline
Hoopy frood

Registered: 27/12/08
Posts: 1511
Loc: Greece
Try use this code:

Code:
alias testt {
  if ($sock(testing)) { sockclose testing }
  sockopen -e testing chatdepot.twitch.tv 443
}

on *:sockopen:testing: {
  if ($sockerr) { sockclose $sockname | return }
  var %o = YOUR_OAUTH_TOKEN
  var %c = THE_CHANNEL
  var %n = THE_NICKNAME
  var %u = oauth_token= $+ %o $+ &irc_channel= $+ %c $+ &username= $+ %n
  sockwrite -nt $sockname POST /room_memberships HTTP/1.1
  sockwrite -nt $sockname Host: $sock($sockname).addr
  sockwrite -nt $sockname User-Agent: Mozilla/*
  sockwrite -nt $sockname Accept: application/json, text/javascript, */*; q=0.01
  sockwrite -nt $sockname Content-Type: application/x-www-form-urlencoded; charset=UTF-8
  sockwrite -nt $sockname Authorization: OAuth %o
  sockwrite -nt $sockname Cache-Control: no-cache
  sockwrite -nt $sockname Connection: keep-alive
  sockwrite -nt $sockname Content-Length: $len(%u)
  sockwrite -nt $sockname $+($crlf,%u)
}

on *:sockread:testing:{
  if ($sockerr) { sockclose $sockname | return }
  sockread %temp
  if ($sockbr) { echo 2 -a READ: $left(%temp,4098) }
}
_________________________
Need Online mIRC help or an mIRC Scripting Freelancer? -> http://westor.ucoz.com/contact <-

Top