mIRC Home    About    Download    Register    News    Help

Print Thread
Returning results from called script via alias #181474 24/07/07 10:16 AM
Joined: Sep 2006
Posts: 21
S
sabbath Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Sep 2006
Posts: 21
Yeah, that actually was the best subject I could think of. wink

Anywho, I've written myself a nice little tvrage-alias that works like a charm. So a few other guys wanted to use it too, so I made a remote script that calls the alias, no problem there. However, I can't figure out a way to return the results from the alias to the remote script since the alias calls several events in a chain.

Here's the code so you guys will understand what I'm saying. laugh
Code:
alias tvrage {
  unset %tvrage*
  if (!$1) { /msg $chan You actually need to search for a TV-show you know! | return }
  %tvshow = $replace($1-,$chr(32),% $+ 20)
  }
  sockopen tvrage http://www.tvrage.com 80
}

on *:sockopen:tvrage: {
  sockwrite tvrage GET http://www.tvrage.com/quickinfo.php?show= $+ %tvshow $+ $crlf
}

on *:sockread:tvrage: {
  if ($sockerr) { return }
  var %tvdata
  sockread %tvdata
  set %show_name $gettok(%tvdata,2,64)
  while ((!$sockerr) && ($sockbr)) {
    %tvrage.data = %tvrage.data $+ %tvdata
    sockread %tvdata
    if (country isin %tvdata) { set %show_country $gettok(%data,2,64) }
        if (next isin %tvdata) { set %show_next $gettok(%data,2,64) }
  }
}

on *:sockclose:tvrage:{
  echo -a $time %show_name %show_country %show_next
  unset %tvrage.*
  unset %show_*
}


So when calling this alias from a remote, I get the results echoed. Is it possible to somehow return the data to the remote script instead? Like "return %show.name %show.country %show.next" in another way? It's then easy for me to decide in my remote script whether to echo or announce.

Cheers!

Last edited by sabbath; 24/07/07 10:18 AM.
Re: Returning results from called script via alias [Re: sabbath] #181476 24/07/07 12:06 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Do you mean like this?

Code:
alias tvrage {
  unset %tvrage*
  if (!$1) { 
    msg $chan You actually need to search for a TV-show you know!
    return 
  }
  set %trgt $active
  %tvshow = $replace($1-,$chr(32),% $+ 20)
  sockopen tvrage http://www.tvrage.com 80
}

on *:sockopen:tvrage: {
  sockwrite tvrage GET $+(http://www.tvrage.com/quickinfo.php?show=, %tvshow,$crlf) HTTP/1.1
  sockwrite -n tvrage Host: $+(www.tvrage.com,$crlf,$crlf)
}

on *:sockread:tvrage:{
  if ($sockerr) { return }
  var %tvdata
  sockread %tvdata
  if (!$sockbr) return
  set %show_name $gettok(%tvdata,2,64)
  if (country isin %tvdata) { set %show_country $gettok(%tvdata,2,64) }
  if (next isin %tvdata) { set %show_next $remove($gettok(%tvdata,2,64),^) }
}

on *:sockclose:tvrage:{
  msg %trgt $time %show_name %show_country %show_next
  unset %tvrage.*
  unset %show_*
}

Re: Returning results from called script via alias [Re: SladeKraven] #181480 24/07/07 01:10 PM
Joined: Sep 2006
Posts: 21
S
sabbath Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Sep 2006
Posts: 21
Hmm well that solves the announce problem. But if I run the alias myself, I don't want it to msg the channel, instead I would like it to echo. Meaning I don't want to announce the result in the sockread event. Rather I would like sockread to set a variable for my remote scripts to read.

I tried doing just that (ie %tvresult = %show_name) and then announce those variables in the script above and unset them afterwards. The problem with that is of course that the variables get set after the remote script has resolved them (and I can't re-evaluate variables, or can I? Just identifiers).

Since return won't work I'm guessing I need some work around to delay the resolving of variables set by the tvrage-alias? This is how I'd like it (somehow)

Code:
alias tvrage {
  unset %tvrage
  if (!$1) {
  
.... SNIP ....

on *:sockclose:tvrage:{
  %tvresults = %show_name %show_country %show_next
  unset %tvrage.*
  unset %show_*
}

alias tv {
  tvrage $1-
  echo -a Show: $gettok(%tvresults,1,32) Country: $gettok(%tvresults,2,32)
  unset %tvresults
}

on *:TEXT:!tv*:#chan:{
  tvrage $1-
  msg $chan Show: $gettok(%tvresults,1,32) Country: $gettok(%tvresults,2,32)
  unset %tvresults
}


Meaning I can decide whether to keep the results for myself or spit them out in achan depending on how the tvrage lookup alias is called.

Still not sure I make myself clear though. smile

Re: Returning results from called script via alias [Re: sabbath] #181483 24/07/07 01:31 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
The only thing I can think of is using $event.

It still announces in the sockread event but either echoes or messages.

When calling the alias from an On Text event $event will be text, therefore messages the target. When calling the alias from the editbox $event will be $null thus echoing.

Code:
On *:Text:!tvrage *:*: {
  set %trgt $iif($target ischan,$chan,$nick)
  tvrage $2-
}

alias tvrage {
  unset %tvrage*
  if (!$1) { 
    msg $chan You actually need to search for a TV-show you know!
    return 
  }
  set %tvrage.event $event
  %tvshow = $replace($1-,$chr(32),% $+ 20)
  sockopen tvrage http://www.tvrage.com 80
}

on *:sockopen:tvrage: {
  sockwrite tvrage GET $+(http://www.tvrage.com/quickinfo.php?show=, %tvshow,$crlf) HTTP/1.1
  sockwrite -n tvrage Host: $+(www.tvrage.com,$crlf,$crlf)
}

on *:sockread:tvrage:{
  if ($sockerr) { return }
  var %tvdata
  sockread %tvdata
  if (!$sockbr) return
  set %show_name $gettok(%tvdata,2,64)
  if (country isin %tvdata) { set %show_country $gettok(%tvdata,2,64) }
  if (next isin %tvdata) { set %show_next $remove($gettok(%tvdata,2,64),^) }
}

on *:sockclose:tvrage:{
  $iif(!%tvrage.event,echo -a ,msg %trgt) $time %show_name %show_country %show_next
  unset %tvrage.*
  unset %show_*
}

Re: Returning results from called script via alias [Re: SladeKraven] #181490 24/07/07 02:33 PM
Joined: Sep 2006
Posts: 21
S
sabbath Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Sep 2006
Posts: 21
Nice! That'll work nicely! Thanks a bunch. laugh