mIRC Home    About    Download    Register    News    Help

Print Thread
More questions about uptime #128459 25/08/05 01:42 PM
Joined: Apr 2005
Posts: 12
A
anarres Offline OP
Pikka bird
OP Offline
Pikka bird
A
Joined: Apr 2005
Posts: 12
I have a uptime addon made by this forum (thanx), but I'm trying to make it bigger.
By now, when I type !scan10 it scan the channel and sends to chan the 10 nicks with the longest uptime, but now I'm trying to save the best uptime of each nick: When a !scan10 is done, if the nick shown have a better uptime that the last time record it for the next in a text file (I've done a example in the 1rst one).

alias -l topXnumber { return 10 }
;
;Designed to be run on multiple channels but only one at any one time.
;
on *:input:#:{ if ($1- == .scan10) { mass.whois $chan } }
on 10:text:!scan10:#:{ if ($timer(scan)) { notice $nick Espere't una estona, falten $duration($timer(scan).secs) per poder tornar a escanejar } | else { notice $nick escanejant | mass.whois $chan | /timerscan 1 3600 /notice $me ja ta } }
;
; $1 = $chan
alias mass.whois {
if (!%mass.whois) {
set $+(-u,$calc($nick($1,0) * 2 + 4)) %mass.whois $true
.timer.mass.whois.result 1 $calc($nick($1,0) * 2 + 2) mass.whois.results $1
var %i = $nick($1,0)
while (%i) {
.timer 1 $calc(%i * 2) whois $nick($1,%i) $nick($1,%i)
dec %i
}
set %uptime.topX
}
}
;
;$2 = nick
;$4 = connect time?
raw 317:*:{ set -s %uptime.topX $gettok($replace($gettok($sorttok($str($cr $+ $chr(32),$topXnumber) %uptime.topX $+($right($+(0000000000,$calc($ctime - $4)),10),@,$2),32),$+(-,$topXnumber,-),32),$cr,$chr(32)),1-,32) }
;
; $1 = $chan
; %uptime.topX = [email]0000000001@nickA[/email] [email]0000000002@nickB[/email] [email]0000000003@nickC[/email] [email]0000000004@nickD[/email] (maybe less than X nicks total)
alias mass.whois.results {
set %uptime.topX.nicks
set %uptime.topX.times
var %i = $numtok(%uptime.topX,32)
while (%i) {
set %uptime.topX.times %uptime.topX.times $calc($gettok($gettok(%uptime.topX,%i,32),1,64))
set %uptime.topX.nicks %uptime.topX.nicks $gettok($gettok(%uptime.topX,%i,32),2,64)
dec %i
}
unset %uptime.topX
echo -s Top X uptimes on $1 are %uptime.topX.times amb un temps de $duration($calc(%uptime.topX.times))
echo -s Top X uptime nicks on $1 are %uptime.topX.nicks
write -c c:\stadistiques\up.txt Uptimes
write c:\stadistiques\up.txt 1r - $gettok(%uptime.topX.nicks,1,32) --> $duration($calc($gettok(%uptime.topX.times,1,32))) | if ($read(c:\stadistiques\nicks\$gettok(%uptime.topX.nicks,1,32).txt, 1) < $gettok(%uptime.topX.times,1,32)) { write -c c:\stadistiques\nicks\$gettok(%uptime.topX.nicks,1,32).txt $gettok(%uptime.topX.times,1,32) }
write c:\stadistiques\up.txt 3r - $gettok(%uptime.topX.nicks,3,32) --> $duration($calc($gettok(%uptime.topX.times,3,32)))
write c:\stadistiques\up.txt 4rt - $gettok(%uptime.topX.nicks,4,32) --> $duration($calc($gettok(%uptime.topX.times,4,32)))
write c:\stadistiques\up.txt 5e - $gettok(%uptime.topX.nicks,5,32) --> $duration($calc($gettok(%uptime.topX.times,5,32)))
write c:\stadistiques\up.txt 6e - $gettok(%uptime.topX.nicks,6,32) --> $duration($calc($gettok(%uptime.topX.times,6,32)))
write c:\stadistiques\up.txt 7e - $gettok(%uptime.topX.nicks,7,32) --> $duration($calc($gettok(%uptime.topX.times,7,32)))
write c:\stadistiques\up.txt 8e - $gettok(%uptime.topX.nicks,8,32) --> $duration($calc($gettok(%uptime.topX.times,8,32)))
write c:\stadistiques\up.txt 9e - $gettok(%uptime.topX.nicks,9,32) --> $duration($calc($gettok(%uptime.topX.times,9,32)))
write c:\stadistiques\up.txt 10e - $gettok(%uptime.topX.nicks,10,32) --> $duration($calc($gettok(%uptime.topX.times,10,32)))

var %m = $numtok(%uptime.topX,32), %i = 1
while (%i <= %m) {
write c:\up.txt # $+ %i lloc hi ha $gettok(%uptime.topX.nicks,%i,32) amb un temps de $duration($calc($gettok(%uptime.topX.times,%i,32)))
inc %i
}
play #la_penya_del_pollastre c:\stadistiques\up.txt 500
; ^ do what you well here
}

Re: More questions about uptime #128460 27/08/05 08:28 PM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
I'll just be blunt here. Your code looks like total mushWhat you are basically doimng wrong is cramming as many executions into as few functions as possibhle. And your also cramming many operations into single line of code.

Here look at this.

A sample of your existing code.


write c:\stadistiques\up.txt 1r - $gettok(%uptime.topX.nicks,1,32) --> $duration($calc($gettok(%uptime.topX.times,1,32))) | if ($read(c:\stadistiques\nicks\$gettok(%uptime.topX.nicks,1,32).txt, 1) < $gettok(%uptime.topX.times,1,32)) { write -c c:\stadistiques\nicks\$gettok(%uptime.topX.nicks,1,32).txt $gettok(%uptime.topX.times,1,32) }

Now let's break it down and make it easier to read and comprehend.

; --------------------

alias nameoffunction {
var %top.nick = $gettok(%uptime.topX.nicks,1,32)
var %top.time = $gettok(%uptime.topX.times,1,32)
var %file1 = c:\stadistiques\nicks\ $+ %top.nick $+ .txt

var %compare = $read(%file1)
var %result = $iif(%compare < %top.time,1,0)

if %result {
write -c %file1
write %file1 %top.time
}
}

;-----------------

I didn't bother adding comments but I was simply trying to show you just how much easier it is to work with code that breaks things down into many small steps rather than one or two big ones.

You may not even care about what i'm trying to demonstrate to you. I really don't see much clean code on display in these forums. It's why I only wisit hem once in a blue moon.


Beware of MeStinkBAD! He knows more than he actually does!