mIRC Home    About    Download    Register    News    Help

Print Thread
#249882 22/12/14 01:03 AM
Joined: Dec 2014
Posts: 8
K
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
K
Joined: Dec 2014
Posts: 8
Hey guys, So I am new to MIRC and scripting all together so I am a complete noob at this... So I've copied some parts of peoples scripts to get a !SetTitle command and !SetGame command setup however it doesnt seem to work ("!SetTitle" is currently set to !topic and "!setgame" is currently to !game and would also like them changed)

Pleassseee Help!

Also if someone could tell me how to put the code in boxes on the forum future reference it'd be nice :3


alias -l twitch.token {
if ($1 == KarlosBot) return Bot_AccessToken
}

on $@*:text:/^!(topic|game)/iS:#:{
var %switch $iif($1 == !topic,status,game)
if ($2 != $null) {
if ($nick isop #) twitch.topic # %switch $2-
}
else {
twitch.topic # %switch
}
}

alias twitch.topic {
var %chan = $1, %switch = $2, %topic = $3-
var %sockname = twitch.topic. $+ $ticks
hfree -w %sockname | hmake %sockname
hadd %sockname headerfile %sockname $+ .header.txt
hadd %sockname datafile %sockname $+ .data.txt
hadd %sockname params %chan %switch
hadd %sockname oath.token $twitch.token($mid(%chan,2-))
hadd %sockname request /kraken/channels/ $+ $mid(%chan,2-)
if (%topic != $null) {
hadd %sockname method PUT
hadd %sockname data channel[ $+ %switch $+ ]= $+ $urlencode(%topic)
hadd %sockname signal topic.set
}
else {
hadd %sockname method GET
hadd %sockname signal topic.get
}
sockopen -e %sockname api.twitch.tv 443
}

on *:signal:topic.get:{
var %err = $1, %sockname = $2, %header = $3, %data = $4, %chan = $5, %switch = $6

if (* 200 OK iswm $read(%header,1)) msg %chan Status: $json(%data,%switch)
else msg %chan Could not get status.

hfree -w %sockname
.remove %header | .remove %data
}

on *:signal:topic.set:{
var %err = $1, %sockname = $2, %header = $3, %data = $4, %chan = $5, %switch = $6

if (* 200 OK iswm $read(%header,1)) msg %chan Status set: $json(%data,%switch) else msg %chan Could not set status.

hfree -w %sockname
.remove %header | .remove %data
}

on *:sockopen:twitch.*:{
var %a = sockwrite -n $sockname
%a $hget($sockname,method) $hget($sockname,request) HTTP/1.1
%a Host: api.twitch.tv
%a Connection: close
%a Accept: application/vnd.twitchtv.v2+json
if ($hget($sockname,oath.token) != $null) %a Authorization: OAuth $v1
if ($hget($sockname,data) != $null) {
%a Content-Type: application/x-www-form-urlencoded
%a Content-Length: $len($v1)
}
%a $+($crlf,$hget($sockname,data))
}

on *:sockread:twitch.*:{
var %header
var %headerfile = $hget($sockname,headerfile)
var %datafile = $hget($sockname,datafile)

if (!$hget($sockname,header.complete)) {
sockread %header
while (%header != $null) {
write %headerfile %header
sockread %header
}
if ($sockbr) hadd $sockname header.complete $true
}
if ($hget($sockname,header.complete)) {
sockread &read
while ($sockbr) {
bwrite %datafile -1 -1 &read
sockread &read
}
}
}

on *:sockclose:twitch.*:{
var %header = $hget($sockname,headerfile)
var %data = $hget($sockname,datafile)
var %signal = $hget($sockname,signal)
var %params = $hget($sockname,params)

if (%signal) .signal %signal 0 $sockname %header %data %params
else {
hfree -w $sockname
.remove %header | .remove %data
}
}

alias urlencode return $regsubex($1-,/([^A-Z0-9])/gi,$+(%,$base($asc(\1),10,16)))

Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
Is this

Code:
alias -l twitch.token {
if ($1 == KarlosBot) return Bot_AccessToken
}


In your bot like this?

Joined: Dec 2014
Posts: 8
K
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
K
Joined: Dec 2014
Posts: 8
Sorry mate, what do you mean?

Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
I mean did you change that part of the script before you posted it.

Joined: Dec 2014
Posts: 8
K
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
K
Joined: Dec 2014
Posts: 8
yeah, KarlosBot is the name of my bot :s Haven't got a clue what I am doing here.

Sorry smirk

Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
Bot_AccessToken <---This is suppose to be an oauth token If I'm not mistaken.

Joined: Dec 2014
Posts: 8
K
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
K
Joined: Dec 2014
Posts: 8
still doesnt work frown

Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
Have you done all the stuff with registering the application with twitch?

Joined: Dec 2014
Posts: 8
K
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
K
Joined: Dec 2014
Posts: 8
Yeah I have

Joined: Sep 2014
Posts: 259
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Did you download the JSON parser script and load it?

As I remember, the !topic command didn't work for me when I tried the script, and I had to use something like this for it to work:


Code:
on *:TEXT:!title *:#: {
  if ($nick = sakana && $2 != $null  {
  twitch.topic #sakana $2-
 }
}



Speaking of the JSON parser, someone told me there might be a security problem with it ( http://blog.mindedsecurity.com/2011/08/ye-olde-crockford-json-regexp-is.html ) but that's beyond my comprehension, maybe someone else can comment on it.

Last edited by Sakana; 22/12/14 08:03 PM.
Joined: Sep 2014
Posts: 52
Babel fish
Offline
Babel fish
Joined: Sep 2014
Posts: 52
I decided to give this script a try, and it successfully changes the title and the game of the channel. BUT when it messages the channel, all I get is "Status set:" or when trying to see current title/game, "Status:" Since the information is returned using JSON, it may be my parser. I am using this one and have had no issues with it yet. I tried figuring the issue out, but I couldn't. blush Any help would be appreciated.

Edit: I got it to work the way I wanted with a new alias. smile

Last edited by paper0rplastic; 03/08/15 06:45 PM.

Link Copied to Clipboard