mIRC Homepage

Twitch groups + sockets = pain

Posted By: splinny

Twitch groups + sockets = pain - 06/06/15 06:15 AM

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.
Posted By: westor

Re: Twitch groups + sockets = pain - 06/06/15 08:15 AM

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.
Posted By: splinny

Re: Twitch groups + sockets = pain - 06/06/15 08:21 AM

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
}
Posted By: westor

Re: Twitch groups + sockets = pain - 06/06/15 08:33 AM

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.
Posted By: splinny

Re: Twitch groups + sockets = pain - 06/06/15 08:48 AM

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
Posted By: westor

Re: Twitch groups + sockets = pain - 06/06/15 09:45 AM

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) }
}
© 2019 mIRC Discussion Forums