On/Off script

By Keon191 on Aug 14, 2010

Simple on/off script.
!ucmd on/off
Chane the input/message to anything you like easy to edit.

I don't take full credit because the 1st half of this script belongs to napa182. It just so happens he had what i needed so i used it. I just change some little things.

I'm not very good so any suggestions on what i could do better would be nice ;)

on *:TEXT:!commandhere:#: {
  if ($($+(%,ucmd,#),2) != $false) { code here }
  else { msg $nick Private Msg -> $nick -> I'm silent in # }
}

on $@*:TEXT:/^(!ucmd on|!ucmd off)$/S:#: { 
  if ($nick isop #) {
    if ($regml(1) == !ucmd off) {
      set $+(%,ucmd,#) $false
      msg # User commands are now off.
      /timer1 1 1 msg # Want to turn them back on? Type !ucmd on
    }
    elseif ($regml(1) == !ucmd on) && $($+(%,ucmd,#),2) != $false {
      msg # User Commands are already on.
    }
    else { 
      unset $+(%,ucmd,#)
      msg # User Commands are now on.      
    }
  }
}

Comments

Sign in to comment.
turbuiance   -  Dec 07, 2011

would there be a way to add this to !weather script? this is what i have tried but doesnt seem to work...

on *:TEXT:!weather:#: {
  if ($($+(%,weather,#),2) != $false) { code here }
  else { msg $nick Private Msg -> $nick -> I'm silent in # }
}

on $@*:TEXT:/^(!weather on|!weather off)$/S:#: { 
  if ($nick isop #) {
    if ($regml(1) == !weather off) {
      set $+(%,weather,#) $false
      msg # User commands are now off.
      /timer1 1 1 msg # Want to turn them back on? Type !ucmd on
    }
    elseif ($regml(1) == !weather on) && $($+(%,weather,#),2) != $false {
      msg # User Commands are already on.
    }
    else { 
      unset $+(%,weather,#)
      msg # User Commands are now on.      
    }
  }
}

on *:SOCKOPEN:YahooWeather:{
  tokenize 32 $sock($sockname).mark
  if ($sockerr) { $1 $false | halt }

  sockwrite -n $sockname GET /forecastrss?w= $+ $2 $+ $iif($3,&u= $+ $3) HTTP/1.1
  sockwrite -n $sockname Host: weather.yahooapis.com
  sockwrite -n $sockname Connection: Close
  sockwrite -n $sockname $crlf
}

on *:SOCKREAD:YahooWeather:{
  tokenize 32 $sock($sockname).mark
  if ($sockerr) { $1 $false | halt }

  var %read
  sockread %read

  %read = $regsubex(%read,/ +/g,$chr(32))
  if ($regex(%read,/<title>City not found<\/title>/i)) { 
    $1 $false 
    sockclose YahooWeather
    halt 
  }

  if ($regex(%read,/<yweather:(\S+)(.*)\/>/)) {
    var %prefix = $iif($regml(1) == forecast,$iif($hget(Weather,today_day),tomorrow,today),$regml(1))
    noop $regex($regml(2),/\b(.*?)="(.*?)"/g))
    var %num_match = $regml(0)
    while (%num_match) {
      wadd $+(%prefix,_,$regml($calc(%num_match - 1))) $regml(%num_match)
      dec %num_match 2
    }
  }

  elseif ($regex(%read,/<title>(.*?)<\/title>/i)) {
    wadd title $regml(1)
  }
  elseif (%read == </rss>) { 
    $1 $true
    sockclose $sockname
    halt
  }
}

on *:SOCKOPEN:WOEID:{
  tokenize 32 $sock($sockname).mark
  if ($sockerror) { $1 $false | halt }

  sockwrite -n $sockname GET /v1/places.q(' $+ $urlencode($2-) $+ ')?appid= $+ $Y_APPID HTTP/1.1
  sockwrite -n $sockname Host: where.yahooapis.com
  sockwrite -n $sockname Connection: Close
  sockwrite -n $sockname $crlf
}

on *:SOCKREAD:WOEID:{
  tokenize 32 $sock($sockname).mark
  if ($sockerror) { $1 $false | halt }

  var %read
  sockread %read

  If ($regex(%read,/yahoo:total="0"\/>/)) { $1 $false | halt }

  Elseif ($regex(%read,/<woeid>(.*)<\/woeid>/)) { 
    $1 $regml(1) 
    sockclose $sockname
    halt 
  }
}

on *:text:*:*:{
  if ($regex($1-,/^[!.@&]w(?:eather)? (.*)$/i)) {
    if (%weather.flood == 2) {
      msg # Flood Protection Activated.
      inc -u10 %weather.flood 1
    }
    Elseif (%weather.flood > 2) {
      return
    }
    elseif (%weather.channel) {
      msg # Another weather lookup is already in progress, please try again  momentarly
      inc -u5 %weather.flood 1
    }
    Else {
      getWOEID UpdateWeather $regsubex($regml(1),/\b(c(elcius)?|f(arenheit)?)\b/i,)
      set %weather.u $lower($left($regml(1),1))
      set %weather.channel #
      inc -u5 %weather.flood 1
    }
  }
}

alias weatherReplace { return $regsubex($1,/&(\S+?)&/g,$hget(Weather,\1)) }
alias -l wADD { hadd -m Weather $1- }
alias -l Y_APPID { return L8j7ok7V34GTI61wyDk20Uy5PazMYrKUEAHruXNndmOzvkOHgQfVlOz6Az8R9Ib_1A-- }
alias urlEncode { return $regsubex($$1,/([\W\D])/g,$+(%,$base($asc(\t),10,16))) }
alias GetWeather {
  if ($regex($1-,/^\S+ \S+( [fc])?$/i)) {
    if $hget(Weather) { hfree Weather }
    if ($sock(YahooWeather)) { sockclose YahooWeather }
    sockopen YahooWeather weather.yahooapis.com 80
    sockmark YahooWeather $1-
  }
}
alias GetWOEID {
  if ($sock(GetWOEID)) { sockclose GetWOEID }
  if ($2) {
    sockopen WOEID where.yahooapis.com 80
    sockmark WOEID $1-
  }
}
alias UpdateWeather {
  if ($1) {
    getWeather DisplayWeather $1 %weather.u
  }
  else {
    msg %weather.channel Unable to find location, please try again!
    unset %weather.*
  }
}
alias DisplayWeather {
  if ($1) {
    msg %weather.channel $weatherreplace(&title&)
    var %x = Today, High: &today_high&&units_temperature& Low: &today_low&&units_temperature& Cur: &condition_text& &condition_temp&&units_temperature&
    .timer 1 1 msg %weather.channel $weatherreplace(%x)
    var %x = Tomorrow, High: &tomorrow_high&&units_temperature& Low: &tomorrow_low&&units_temperature& &tomorrow_text&
    .timer 1 2 msg %weather.channel $weatherreplace(%x)

  }
  else {
    msg %weather.channel Unable to find weather report, please try a different location.
  }
  unset %weather.*
}
; ############################################
; ## DISPLAY VARIABLES and Examples         ##
; ############################################

/*
&astronomy_sunrise&     = 6:46 am
&astronomy_sunset&      = 6:40 pm
&atmosphere_humidity&   = 54
&atmosphere_pressure&   = 982.05
&atmosphere_rising&     = 0 ;// 0 is steady, 1 is rising, 2 is falling
&atmosphere_visibility& = 16.09
&condition_code&        = 28
&condition_date&        = Wed, 29 Sep 2010 11:53 am PDT ;// Last time weather was update
&condition_temp&        = 27
&condition_text&        = Mostly Cloudy
&location_city&         = Beverly Hills
&location_country&      = United States
&location_region&       = CA
&title&                 = Conditions for Beverly Hills, CA at 11:53 am PDT
&today_code&            = 30
&today_date&            = 29 Sep 2010
&today_day&             = Wed
&today_high&            = 30
&today_low&             = 18
&today_text&            = Partly Cloudy
&tomorrow_code&         = 30
&tomorrow_date&         = 30 Sep 2010
&tomorrow_day&          = Thu
&tomorrow_high&         = 28
&tomorrow_low&          = 18
&tomorrow_text&         = Partly Cloudy
&units_distance&        = km
&units_pressure&        = mb
&units_speed&           = km/h
&units_temperature&     = C
&wind_chill&            = 27
&wind_direction&        = 210 ;// 0-359, 0 is north, 180 is south
&wind_speed&            = 9.66
*/

Thanks guys

 Respond  
Keon191   -  Aug 16, 2010

Oh ok guys thanks ^.^

 Respond  
Sorasyn   -  Aug 14, 2010

browse forums

 Respond  
loves.enough   -  Aug 14, 2010

Hello guys ...
i want to may mirc on tray how i can do ?
when i minize

 Respond  
Jethro   -  Aug 14, 2010

Keon191, the code you've posted is what we call it a pseudo code. (at least for the upper part of your text event) It's an informal mock-up of description in a scripting language. You can post this in a scripting tutorial section of the forum. A submitted snippet should be fully functional.

WorldDMT is French, so his English may sometimes get you mistaken for something else. :p

SunnyD, his regex, as you can see, is sort of redundant. It can be improved as such:

on $@*:text:/^!ucmd o(n|ff)$/iS:#:{

Then use > if $regml(1) == n { and > if $regml(1) == ff { to reference the regex matches.

P.S. His script can further be refined to check whether it's already turned on or off, rather than just for the on switch. A trigger control may be needed in case of spam or flood.

 Respond  
Sorasyn   -  Aug 14, 2010

One suggestion I noticed on your trigger that you have (!ucmd on|!ucmd off) could be cleaned up

on $@*:TEXT:/^[!]ucmd/Si:#: { 

and call

 if ($regml(1) == !ucmd off) { 

those events with

 if ($2 == off) { 

Again just a suggestion, if anything its to make your code easier to read

 Respond  
Keon191   -  Aug 14, 2010

um what? i know this is not the forums. What does the forums have to do with this?

 Respond  
WorldDMT   -  Aug 14, 2010

!!!!!!!!!!!!????????

this is not a forum here!!!!

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.