Uptime contest script.

Release your script here.
State:
- Author
- What it does
- Perhaps a little guide.
- Also, if the snippet is of any use to the community, it has a chance of getting posted on the main page, so don't hesitate to submit/ask!

Uptime contest script.

Postby Cristian » Sun Jun 15, 2008 11:08 am

I hope this uptime contest script, works like it should, if not please report any errors/bugs as fast as possible.

Dandy did the regexp.

When one voiced user remain, the channel will be messaged with the winner nick/time/date, and in the topic as well.
Operators are not included in the "contest"

A user will lose the voice if they part/quit/or gets kicked, if a server splits, the server should give back the voice status.

This script uses eggdrops userflags to turn it on/off/or start the contest.

What to do:
change the channel name
change the trigger name (if you want to)


Commands:
    !trigger on - Prepares the channel, gives voice/autovoice on the channel.
    !trigger start - starts right away.
    !trigger start HH:MM DD/MM-YYYY - Starts on the specified time/date.
    !trigger off - turns it off.
    !trigger status - returns current status.

Two colors is used, well only one. (\003 = mIRC's ctrl+k)

If you change the theme or add something else, you are welcome to post it inhere.
I'm not much of theme maker.



Code: Select all
setudef flag uptime 
setudef flag uptime-start
setudef str uptime-date
setudef str uptime-usrpart


namespace eval uptime {

   namespace eval variable {
      variable channel "#uptime.dk"
      variable trigger "!uptime"
      variable flag "o|o"

      variable c    "\003"
      variable c1 "\00307"
   }

   bind PUBM - "$::uptime::variable::channel $::uptime::variable::trigger*" [namespace current]::public

   proc voiced {channel} {
      set x 0
      foreach user [chanlist $channel] {
         if {[isbotnick $user]} {continue}
         if {[isop $user $channel]} {continue}
         if {[string length $user] == 1} {continue}
         if {[isvoice $user $channel] == 1} {
            incr x
         }
      }
      return $x
   }
   proc voiced.nick {nickname channel} {
      foreach user [chanlist $channel] {
         if {[string match $nickname $user]} {continue}
         if {[isbotnick $user]} {continue}
         if {[isop $user $channel]} {continue}
         if {[string length $user] == 1} {continue}
         if {[isvoice $user $channel] == 1} {
            return $user
         }
      }
   }

   proc public {nickname hostname handle channel text} {
      set s [lindex $text 1]
      switch $s {
         on {
            if {[matchattr $handle $::uptime::variable::flag $channel]} {
               if {![channel get $channel uptime-start]} {

                  if {[channel get $channel uptime]} {
                     putserv "NOTICE $nickname :Uptime is already \002on\002 for $channel."
                  } else {
                     channel set $channel +uptime
                     foreach user [chanlist $channel] {
                        if {[isbotnick $user]} {continue}
                        if {[isop $user $channel]} {continue}
                        if {[string length $user] == 1} {continue}
   
                        pushmode $channel +v $user
                     }
                     putserv "PRIVMSG $channel :\002Preparing Uptime Contest\002. Autovoice is turned on."
                  }
               }
            }
         }
         off {
            if {[matchattr $handle $::uptime::variable::flag $channel]} {
               channel set $channel -uptime
               channel set $channel -uptime-start
               putserv "PRIVMSG $channel :\002Uptime Contest\002 is now turned off for $channel. $::uptime::variable::c1[channel get $channel uptime-usrpart]$::uptime::variable::c User(s) lost the voice. $::uptime::variable::c1[::uptime::voiced $channel]$::uptime::variable::c is still voiced."

               foreach bind [binds time] {
                  if {[string match *contest [lindex $bind 4]]} {
                     unbind TIME - "[lindex $bind 2]" [lindex $bind 4]
                  }
               }
            }
         }
         start {
            if {[matchattr $handle $::uptime::variable::flag $channel]} {

               if {[channel get $channel uptime]} {
   
                  set s [lrange $text 2 end]
                  if {[string match *:* $s]} {
                     # Developed by Dandy - http://www.daasor.info/
                     regexp {([0-9]+):([0-9]+) ([0-9]+)/([0-9]+)-([0-9]+)} "$s" test1 hour minutes day month year
                     set month1 "0[expr $month-1]"
                     if {[string length $month1] > 2} { set month1 "[join [lrange [split $month1 ""] 1 end] ""]" }
                     if {[botisop $channel]} {
                        putserv "TOPIC $channel :\002Uptime Contest\002 will start on \002Time\002: $::uptime::variable::c1$hour:$minutes$::uptime::variable::c \002Date\002: $::uptime::variable::c1$day/$month$::uptime::variable::c \002Year\002: $::uptime::variable::c1$year$::uptime::variable::c."
                     }
                     bind TIME - "[list $minutes $hour $day $month1 $year]" [namespace current]::contest
                     putserv "PRIVMSG $channel :\002Uptime Contest\002 Time is set and will start on \002Time\002: $::uptime::variable::c1$hour:$minutes$::uptime::variable::c \002Date\002: $::uptime::variable::c1$day/$month$::uptime::variable::c \002Year\002: $::uptime::variable::c1$year$::uptime::variable::c."
                  } else {
                     channel set $channel uptime-usrpart 0
                     channel set $channel -uptime
                     channel set $channel +uptime-start
                     channel set $channel uptime-date "[clock format [unixtime] -format "%R %d/%m-%Y"]"
                     if {[botisop $channel]} {
                        putserv "TOPIC $channel :\002Uptime Contest\002 Started. \002Time\002: $::uptime::variable::c1[clock format [unixtime] -format %R]$::uptime::variable::c \002Date\002: $::uptime::variable::c1[clock format [unixtime] -format %d/%m]$::uptime::variable::c \002Year\002: $::uptime::variable::c1[clock format [unixtime] -format %Y]$::uptime::variable::c Starting with $::uptime::variable::c1\002[::uptime::voiced $channel]\002$::uptime::variable::c voiced users."
                     }
                     putserv "PRIVMSG $channel :\002Uptime Contest\002 is now Started. Autovoice is turned \002OFF\002, keep your voice, as long as you can. We are currently \002[::uptime::voiced $channel]\002 voiced users on the channel."
                  }
               } else {
                  putserv "NOTICE $nickname :Uptime is required to be enabled first.."
               }
            }
         }
         status {
            if {[channel get $channel uptime-start]} {
               putserv "PRIVMSG $channel :\002Uptime Contest\002 is \002ON\002 Status: $::uptime::variable::c1[channel get $channel uptime-usrpart]$::uptime::variable::c User(s) lost the voice. $::uptime::variable::c1[::uptime::voiced $channel]$::uptime::variable::c users remain, since $::uptime::variable::c1[channel get $channel uptime-date]$::uptime::variable::c"
            } else {
               if {[channel get $channel uptime]} {
                  putserv "PRIVMSG $channel :\002Uptime Contest Preparing\002 is on, autovoice is \002ON\002."
               } else {
                  putserv "PRIVMSG $channel :\002Uptime Contest Preparing\002 is off, autovoice is \002OFF\002."
               }
            }
         }
         default {
            if {[channel get $channel uptime]} {
               putserv "NOTICE $nickname :Uptime is \002on\002 for $channel"
            } else {
               putserv "NOTICE $nickname :Uptime is \002off\002 for $channel"
            }
         }
      }
   }
   putlog "\00304[string range [info script] 0 end]\00304 \002loaded\003\002. By \002http://sp00fed.org\002"
   proc contest {minute hour day month year} {
      catch { unbind TIME - "$minute $hour $day $month $year" [namespace current]::contest }

      set channel "$::uptime::variable::channel"
      # Developed by Dandy - http://www.daasor.info/
      regexp {([0-9]+):([0-9]+) ([0-9]+)/([0-9]+)-([0-9]+)} "[clock format [unixtime] -format "%R %d/%m-%Y"]" test1 hour minutes day month year
      if {[botisop $channel]} {
         putserv "TOPIC $channel :\002Uptime Contest\002 Started. \002Time\002: $::uptime::variable::c1$hour:$minute$::uptime::variable::c \002Date\002: $::uptime::variable::c1$day/$month$::uptime::variable::c \002Year\002: $::uptime::variable::c1$year$::uptime::variable::c. Starting with $::uptime::variable::c1\002[::uptime::voiced $channel]\002$::uptime::variable::c voiced users."
      }
      channel set $channel uptime-usrpart 0
   
      channel set $channel -uptime
      channel set $channel +uptime-start
      channel set $channel uptime-date "[clock format [unixtime] -format "%R %d/%m-%Y"]"

      putserv "PRIVMSG $channel :\002Uptime Contest\002 is now Started. Autovoice is turned \002OFF\002, keep your voice, as long as you can. We are currently $::uptime::variable::c1\002[::uptime::voiced $channel]\002$::uptime::variable::c voiced users on the channel."
   }


   bind JOIN - * [namespace current]::join
   proc join {nickname hostname handle channel} {
      if {[botisop $channel]} {
         if {[channel get $channel uptime]} {
            pushmode $channel +v $nickname
         }
      }
   }
   bind PART - * [namespace current]::remove
   bind SIGN - * [namespace current]::remove
   bind KICK - * [namespace current]::kick

   proc kick {nickname hostname handle channel target message} {
      ::uptime::remove $target $hostname $handle $channel $message
   }
   proc remove {nickname hostname handle channel message} {
      if {[channel get $channel uptime-start]} {
         if {[isvoice $nickname $channel]} {
            channel set $channel uptime-usrpart [expr [channel get $channel uptime-usrpart]+1]

            if {[expr [::uptime::voiced $channel]-1] == 1} {
               putserv "PRIVMSG $channel :We have a winner, $::uptime::variable::c1[::uptime::voiced.nick $nickname $channel]$::uptime::variable::c."
               # Developed by Dandy - http://www.daasor.info/
               regexp {([0-9]+):([0-9]+) ([0-9]+)/([0-9]+)-([0-9]+)} "[clock format [unixtime] -format "%R %d/%m-%Y"]" test1 hour minutes day month year
               regexp {([0-9]+):([0-9]+) ([0-9]+)/([0-9]+)-([0-9]+)} "[channel get $channel uptime-date]" test1 hour1 minutes1 day1 month1 year1

               if {[botisop $channel]} {
                  putserv "TOPIC $channel :\002Uptime Contest\002 Started on \002Time\002: $::uptime::variable::c1$hour1:$minutes1$::uptime::variable::c \002Date\002: $::uptime::variable::c1$day1/$month1$::uptime::variable::c \002Year\002: $::uptime::variable::c1$year1$::uptime::variable::c. Won by $::uptime::variable::c1\002[::uptime::voiced.nick $nickname $channel]\002$::uptime::variable::c at \002Time\002: $::uptime::variable::c1$hour:$minutes$::uptime::variable::c \002Date\002: $::uptime::variable::c1$day/$month$::uptime::variable::c \002Year\002: $::uptime::variable::c1$year$::uptime::variable::c."
               }
               channel set $channel -uptime-start

            } else {
               putserv "PRIVMSG $channel :$::uptime::variable::c1[expr [::uptime::voiced $channel]-1]$::uptime::variable::c voiced users remain. $::uptime::variable::c1[channel get $channel uptime-usrpart]$::uptime::variable::c user(s) lost the voice."
            }
         }
      }
   }
}


Enjoy
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar

Re: Uptime contest script.

Postby aFaik » Thu Sep 17, 2009 5:53 pm

Great script! I just have one question: my timezone is different from the one on server where I host my bot, so when I start the competition the time in the topic is 2 hours before the real time. How could I adjust this in the tcl? Thanks for your assistance! :D
aFaik
 

Re: Uptime contest script.

Postby Cristian » Thu Sep 17, 2009 6:20 pm

I haven't tested it out, but have you tried changing the setting in your eggdrop.config?
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar

Re: Uptime contest script.

Postby aFaik » Thu Sep 17, 2009 6:29 pm

I'll try it out now!
aFaik
 

Re: Uptime contest script.

Postby aFaik » Thu Sep 17, 2009 6:52 pm

it worked! Thanks for the tip!
aFaik
 

Re: Uptime contest script.

Postby Cristian » Thu Sep 17, 2009 7:00 pm

anytime, mate
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar

Re: Uptime contest script.

Postby aFaik » Fri Sep 18, 2009 2:31 pm

Another question, maybe more general but also in connection with this script: I'm styilng the script output to fit it more with me channel and page theme. For separators in topic I use these 3 signs: ]![, but when put-in your script it gives error on rehash, stating "open brackets". Is there a way to tell the script that this is not expression but "just" a symbol? Sorry if it's stupid question but I'm far from expert in this field. Thanks m8!
aFaik
 

Re: Uptime contest script.

Postby Cristian » Fri Sep 18, 2009 2:42 pm

you have to escape special characters, such as "[ ] { }" like this "\[ \] \{ \}" when you aren't using it for scripting.
Cristian
proof of advance
proof of advance
 
Posts: 282
Joined: Sun Nov 04, 2007 3:02 pm
Location: Denmark
Authnick: Sumsar

Re: Uptime contest script.

Postby aFaik » Mon Oct 05, 2009 6:02 pm

Your advice helped! Thanks!

Now I have this problem: I managed one compo through without any problems, perfect. After that I adjusted a little the theme and tested the script. If I start the compo using !uptime start HH:MM DD/MM-YYYY it schedules OK, but never starts, one time it gave me (through telnet) some "counter" error. OK, maybe I screwed sth with theme adjustments, so I tried the default script, downloaded from the site, and exactly the same problem appeared. So I guess it's eggdrop problem rather than script? Maybe shell? Sorry to bother you with this sh't but I wanted to check with you first, since you are the script creator. Thank you!


If I start the compo using just !uptime start everything is ok.
aFaik
 

Re: Uptime contest script.

Postby r0t3n » Mon Oct 12, 2009 8:52 pm

The usage of bind time in the "start" switch is totally wrong

Bind time is not to be used as a countdown function, its merely there to just run function(s) at a certain time (on a 24hr clock basis)

Your best bet would be to either use a utimer (timer is not highly accurate enough in eggdrop) or to bind a time fuction to every 1 minute and check if the current clock seconds is more than or equal to the seconds calculated at the start switch

Example:

Code: Select all
set started 0
set start [expr {[clock seconds] + (60 * 5) + 35}]; # this makes our start time 5 minutes and 35 seconds in the future

# lets put our code to run in a proc named proc:start

proc proc:start {} {
  global start started
  if {$started} { return }; # lets halt the procedure if uptime is already running
  set started 1 
  # startup code here
}

bind time - "* * * * *" proc:time; # proc:time will be envoked every minute
# we can use "?0 * * * *" for every 10 minutes, and for every 5 minutes also use "?5 * * * *"

proc proc:time {minute hour day month year} {
  global start started
  if {$started} { return }; # if started = 1 then halt
  set result [expr {$start - [clock seconds]}]
  if {$result == "0"} {
    proc:start; # lets evoke the startup procedure
  } elseif {$result > 0 && $result <= 59} {
    # our startup is due in less than a minute, to stay accurate on time, lets now spawn a utimer
    utimer $result [list proc:start]
  }
  # our startup time is more than or equal to a minute, nothing more to do now, next cycle will takeover
}


Hope this helps :)

@aFaik: its a script coding error, not an eggdrop problem
r0t3n
 

Next

Return to TCL Scripting Release

Who is online

Users browsing this forum: No registered users and 1 guest

cron