mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2014
Posts: 10
A
Pikka bird
OP Offline
Pikka bird
A
Joined: Nov 2014
Posts: 10
I'm trying to make a bot that auto unhosts when a chanel goes online. I think I have everything down exept for actually checking the channel.
I want to use the api "https://api.twitch.tv/kraken/streams/username"
to check. If the page displays
Quote:
"_links":{"self":"https://api.twitch.tv/kraken/streams/username","channel":"https://api.twitch.tv/kraken/channels/username"},"stream":null}
i know its offline. Sockets baffle me though, so I'm not sure how to pull this info. My code so far is down below.

Code:
on *:TEXT:!check:#: { 
  /timerCheck1 0 60 check
}

on *:TEXT:!esd:#: {
  /timerCheck1 off
  msg $chan Timer off
}

alias host {
  msg # .host $read(target.txt)
  set %h = 1
}

alias unhost {
  msg # .unhost
  set %h = 0
}

alias justhosted {
set %jht = 1
/timerJht 1 60 set %jht = 0
}

on *:TEXT:!host*:#:{
  .write target.txt $2
  host
  justhosted
}

on *:TEXT:!unhost:#:{
  unhost
}

alias auh {
  if (%host = 1) {
    if (%online = 1) {
      if (%jht = 0) {
        unhost
      }
    }
  }
}

;check will be the alias for checking to see if stream is online, if it is online it will set %onlin to 1.


Any help will be much appreciated.

Last edited by Anubisxhades; 05/11/14 11:59 PM.
Joined: Nov 2014
Posts: 10
A
Pikka bird
OP Offline
Pikka bird
A
Joined: Nov 2014
Posts: 10
here's my attempt at a socket:

Code:
on *:TEXT:!sts:#: { 
  if ($sock(st)) .sockclose st
  sat 
}

alias sat {
  sockopen st api.twitch.tv 443
  echo t0
}

on *:SOCKOPEN:st: {
  sockwrite -nt $sockname GET /kraken/streams/anubisxhades HTTP/1.1
  sockwrite -nt $sockname Host: api.twitch.tv
  sockwrite $sockname $crlf
  echo t1
}

on *:SOCKREAD:st: {
  if (!$sockerr) { echo -a SOCKET ERROR: $sockerr }
  else {
    var %sockreader
    sockread %sockreader
    sockclose st
    echo t2
  }
}

Joined: Nov 2014
Posts: 10
A
Pikka bird
OP Offline
Pikka bird
A
Joined: Nov 2014
Posts: 10
Nvm, got it all working, for some reason the api kept giving me an error three on the read, so I just opened a socket to nightdev instead. Will drop the code for the auto-unhost program if anyone wants it.

Joined: Apr 2014
Posts: 170
Vogon poet
Offline
Vogon poet
Joined: Apr 2014
Posts: 170
I'd like it please. Might be helpful for the auto host script I'm working on.

Joined: Nov 2014
Posts: 10
A
Pikka bird
OP Offline
Pikka bird
A
Joined: Nov 2014
Posts: 10
make sure to replace my username/channel name anubisxhades, with yours(in three places)
Code:
; ________Auto Unhost Program and uptime__________________

ON ME:*:JOIN:#: {
/timerCheck1 0 30 check
}

on *:TEXT:!auh:#: { 
 if ($nick isop #) {
  /timerCheck1 0 30 check
}
}

on *:TEXT:!muh:#: {
 if ($nick isop #) {
  check
}
}

on *:TEXT:!esd:#: {
 if ($nick isop #) {
  /timerCheck1 off
  msg $chan Timer off
}
}

alias host {
  msg # .host $read(target.txt)
  set %h 1
}

alias unhost {
  msg #anubisxhades .unhost
  set %h 0
}

alias justhosted {
  set %jht 1
  /timerJht 1 60 set %jht 0
}

on *:TEXT:!host*:#:{
  if ($nick == anubisxhades) {
    .write -c target.txt $2
    host
    justhosted
  }
}

on *:TEXT:!unhost:#:{
  if ($nick == anubisxhades) {
    unhost
  }
}

alias check {
  if (%h = 1) {
    online
    if (%o  = 1) {
      if (%jht = 0) {
        unhost
        echo now unhosting
      }
    }
  }
}


on *:text:!uptime*:#:{
  set -u10 %target $iif($2,$2,$mid(#,2-))
  set -u10 %channel #
  uptime 
}

alias uptime {
  sockclose uptime
  sockopen uptime nightdev.com 80
}

on *:sockopen:uptime:{
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -n $sockname GET /hosted/uptime.php?channel= $+ %target HTTP/1.1
  sockwrite -n $sockname Host: www.nightdev.com 
  sockwrite -n $sockname $crlf
}

on *:sockread:uptime:{
  if ($sockerr) { sockclose $sockname }
  var %data
  sockread %data
  tokenize 32 %data
  if ($1 isnum) && ($2) { msg %channel %target has been online for $1- }
  elseif (%data == The channel is not live.) msg %channel %target is currently not online.
}

on *:text:!online*:#:{
  set -u10 %target $iif($2,$2,$mid(#,2-))
  set -u10 %channel #
  online 
}

alias online {
  sockclose online
  sockopen online nightdev.com 80
}

on *:sockopen:online:{
  if ($sockerr) { sockclose $sockname | halt }
  sockwrite -n $sockname GET /hosted/uptime.php?channel= $+ %target HTTP/1.1
  sockwrite -n $sockname Host: www.nightdev.com 
  sockwrite -n $sockname $crlf
}

on *:sockread:online:{
  if ($sockerr) { sockclose $sockname }
  var %data
  sockread %data
  tokenize 32 %data
  if ($1 isnum) && ($2) { set %o 1 }
  elseif (%data == The channel is not live.) set %o 0
}


Joined: Apr 2014
Posts: 170
Vogon poet
Offline
Vogon poet
Joined: Apr 2014
Posts: 170
Thanks, hoping to create an auto host script and some of the stuff in here might help with avoiding channels that aren't on. Appreciate it.


Link Copied to Clipboard