My !peak script. Rate, review, critique. - 10/11/04 12:42 AM
Original post by me on another forum.
---------------------------------------------------------------------
This is my new !peak script. It really takes advantage of my latest "style", I guess you could say, with using aliases rather that remotes so that I can make the script available to me and everyone else. It's really interesting (to me) how the custom $send-to indetifier works, and the way that I used "echopeaksyntax" to save lines.Not to mention, it uses hash tables too
Now, I'll explain it a bit better.
^ make/load/save/free hash tables^check hash table to see if the current users is large or equal to the peak. I use >= because I want it to use the latest time when the command or alias is used.The parameters $2 $3 are optional, if they're not used, they're automatically set by the first two lines to the current day/month. I made sure to have the day specified first so that you didn't need the month. $4 and $5 are only set if the remote is used, $4 being the channel, and $5 being the nickname. This way the following identifier can tell where the script is coming from. Channel > Pm > echo. It's pretty handy for scripts that can be used in chanel or PM.A quick alias to save linesThe crown jewel of the whole script ^. $1 == $chan, $2 == $nick. If $1 is set, it automatically returns it, with the prefix of "msg" for use. If $1 is not set, and $2 is, it returns $2 with the same prefix. If neither are set, it assumes that the remote is being used via the alias itself (user), and uses echo! Genious!^the actual remote part, notice how it uses "| else" ( the | makes sure it treats the else as if it was on a new line) to set %c, %m, or %d only if the user specifies it, or else it uses the default. Of course, there are a few bugs, but they can easily be fixed with isnum.
----------------------------------------------------
What do you think. How could I improve? What do you like? What do you dislike?
FYI, syntax:
remote: !peak #channel [DD] [MM]
alias: /peak #channel [DD] [MM]
[..] - optional
---------------------------------------------------------------------
This is my new !peak script. It really takes advantage of my latest "style", I guess you could say, with using aliases rather that remotes so that I can make the script available to me and everyone else. It's really interesting (to me) how the custom $send-to indetifier works, and the way that I used "echopeaksyntax" to save lines.Not to mention, it uses hash tables too
Code:
on *:start { hmake peak 200 | hload peak peak.hsh } on *:exit { hsave peak peak.hsh | hfree peak } on *:unload { hsave peak peak.hsh | hfree peak } on *:join:* { if (($nick($chan,0) >= $+($chan,.,$asctime(dd),.,$asctime(mm))) || (!$+($chan,.,$asctime(dd),.,$asctime(mm)))) { hadd peak $+($chan,.,$asctime(dd),.,$asctime(mm)) The peak number of users for $chan is $nick($chan,0) on $asctime(mmmm doo $+ $chr(44) yyyy) $+ . } } alias peak { if (!$2) { var %m = $asctime(mm) } | else { var %m = $2 } if (!$3) { var %d = $asctime(dd) } | else { var %d = $3 } if ($left($1,1) != $chr(35)) { echopeaksyntax $4 $5 | halt } if ($1) { if ($hget(peak,$+($1,.,%d,.,%m))) { $send-to($4,$5) $hget(peak,$+($1,.,%d,.,%m)) } else { $send-to($4,$5) There are no records for this channel. } } else { echopeaksyntax $4 $5 } } alias echopeaksyntax { $send-to($1,$2) Syntax: !peak [#channel] [DD] [MM] } ALIAS send-to { if ($1) { return msg $1 } elseif ($2) { return msg $2 } else { return echo 4 -at } } on *:TEXT:!peak*:* { if (!$2) { var %c = $chan } | else { var %c = $2 } if (!$3) { var %m = $asctime(mm) } | else { var %m = $3 } if (!$4) { var %d = $asctime(dd) } | else { var %d = $4 } peak %c %m %d $chan $nick }
Now, I'll explain it a bit better.
Code:
on *:start { hmake peak 200 | hload peak peak.hsh } on *:exit { hsave peak peak.hsh | hfree peak } on *:unload { hsave peak peak.hsh | hfree peak }
Code:
on *:join:* { if (($nick($chan,0) >= $+($chan,.,$asctime(dd),.,$asctime(mm))) || (!$+($chan,.,$asctime(dd),.,$asctime(mm)))) { hadd peak $+($chan,.,$asctime(dd),.,$asctime(mm)) The peak number of users for $chan is $nick($chan,0) on $asctime(mmmm doo $+ $chr(44) yyyy) $+ . } }
Code:
alias peak { if (!$2) { var %m = $asctime(mm) } | else { var %m = $2 } if (!$3) { var %d = $asctime(dd) } | else { var %d = $3 } if ($left($1,1) != $chr(35)) { echopeaksyntax $4 $5 | halt } if ($1) { if ($hget(peak,$+($1,.,%d,.,%m))) { $send-to($4,$5) $hget(peak,$+($1,.,%d,.,%m)) } else { $send-to($4,$5) There are no records for this channel. } } else { echopeaksyntax $4 $5 } }
Code:
alias echopeaksyntax { $send-to($1,$2) Syntax: !peak [#channel] [DD] [MM] }
Code:
ALIAS send-to { if ($1) { return msg $1 } elseif ($2) { return msg $2 } else { return echo 4 -at } }
Code:
on *:TEXT:!peak*:* { if (!$2) { var %c = $chan } | else { var %c = $2 } if (!$3) { var %m = $asctime(mm) } | else { var %m = $3 } if (!$4) { var %d = $asctime(dd) } | else { var %d = $4 } peak %c %m %d $chan $nick }
----------------------------------------------------
What do you think. How could I improve? What do you like? What do you dislike?
FYI, syntax:
remote: !peak #channel [DD] [MM]
alias: /peak #channel [DD] [MM]
[..] - optional