mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2014
Posts: 4
M
Self-satisified door
OP Offline
Self-satisified door
M
Joined: Aug 2014
Posts: 4
So I am bit new to this IRC bot and I have looked up many ways to try and change the topic and game, but keep coming up empty and errors. I was wondering if anyone could help me and steer me in the right direction with this.

Thanks,
Sora

Joined: Aug 2014
Posts: 4
M
Self-satisified door
OP Offline
Self-satisified door
M
Joined: Aug 2014
Posts: 4
So far I have cold that looks like and I'm getting the "could not set status, could not get status error". I have gave my bot access permission for editing my account as well. Here is the code I have so far for it thanks to some of the stuff I found on the forums. Also was I supposed to use a localhost key as well?


alias -l twitch.token {
if ($1 == user_name) return auth_key

}

on @*:text:!topic*:#:{
if ($2 != $null) {
if ($nick isop #) twitch.topic # $2-
}
else {
twitch.topic #
}
}

alias twitch.topic {
var %chan = $1, %topic = $2-
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
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[status]= $+ $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

if (* 200 OK iswm $read(%header,1)) msg %chan Status: $json(%data,status)
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

if (* 200 OK iswm $read(%header,1)) msg %chan Status set: $json(%data,status)
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: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Looks like you're passing the channel name to $twitch.token() when it expects user_name:

Code:
hadd %sockname oath.token $twitch.token($mid(%chan,2-))


Should probably be:

Code:
hadd %sockname oath.token $twitch.token(user_name)

Joined: Aug 2014
Posts: 4
M
Self-satisified door
OP Offline
Self-satisified door
M
Joined: Aug 2014
Posts: 4
I tried that, still came up with the same errors. Hmm I need to maybe look at it more or something smirk

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Have you changed it so that $twitch.token() actually does return your auth key rather than the literal text "auth_key" ?

This bit:

Code:
alias -l twitch.token {
if ($1 == user_name) return auth_key

}


Presumably needs to return some kind of user name or authorisation key so that you can login to the twitch.tv website.

The identifier is used here:

Code:
if ($hget($sockname,oath.token) != $null) %a Authorization: OAuth $v1


So it is clearly sending the information that is returned by $twitch.token() to the website there.

You need to make sure it returns your correct logon information.

Joined: Aug 2014
Posts: 4
M
Self-satisified door
OP Offline
Self-satisified door
M
Joined: Aug 2014
Posts: 4
Yeah I have, I just didn't want to put it in there for security reasons.


Link Copied to Clipboard