Script examples


Mass deop

Alias : massdeop : parameters : channel
/<
    if (!$1)<
        @ No channel given...warn the user and halt
        echo $_window Usage : /massdeop $_[ channel $_];
        halt;
    >
    @ We have a channel in $1 , get the list of nicks to deop
    @ removing our nick from there.
    set $list.to.deop $%lst_remove[$_mynick,$%chn_oponchan[$1]];
    @ If the list is not empty , deop :)
    if ($list.to.deop) deop $1 $list.to.deop;
    unset $list.to.deop
>

Alternative mass deop

This one is a bit optimized for speed, memory usage and more intuitive for the user.
We use a local variable and allow not specyfing the channel ,if the alias is executed
from a channel window.
Alias : massdeop : parameters : channel (optional)
/<
    if (!$1)<
        @ No channel given...set it as $_chan if we are on a channel
        if ($_chan) set $1 $_chan;
        else <
            @ Warn the user that we are not on a channel...
            echo $_window You must execute it from a channel window
            echo $_window or add the channel name as parameter
            halt;
       >
    >
    @ We have a channel in $1 get the list of nicks to deop
    @ removing our nick from there.
    @ Use local $2 as variable instead of global $list.to.deop
    set $2 $%lst_remove[$_mynick,$%chn_oponchan[$1]];
    @ If the list is not empty , deop :)
    if ($2) deop $1 $2;
>

My Away

A funny away system
In the myaway command we set the $my.away.message variable.
If someone is talking to us we tell him that the user is away.
If the remote user has urgent messages , he can write to us '.urgent'...
And on this side , we will play a sound to capture attention on what is happening.
Alias : myaway : parameters : away-message (optional)
/<
    @ First check if we're already away
    if ($%ext_isset[$my.away.message])<
        @ We're already away...
        echo $_window You're already away. Use myback.
        halt;
    >
    @ We're not away,check if a message has been provided
    @ If not , ask user...
    if ($0)<
        @ We have a message
        set $my.away.message $0
    > ; else set $my.away.message $%box_input[Enter away message];
    if (!$my.away.message)<
        @ The user entered no text , use default
        set $my.away.message Away since $_time $_date
    >
    away $my.away.message;
>
Alias : myback : parameters : none (ignored)
/<
    @ First check if we re away
    if (!$%ext_isset[$my.away.message])<
        @ We're not away...
        echo $_window You're not away.
        halt;
    >
    @ We're away...just back and unset the message
    back;
    unset $my.away.message;
>
Event : Event_OnMePrivmsg : parameters : $1 = source nick
/<
    @ First check if we re away
    if ($%ext_isset[$my.away.message])<
        @ Check if the talker has urgent messages
        if ($%str_equal[$2,.urgentmsg])<
            @ Urgent message : play the sound...
            play urgentmessage.wav;
            say $1 Your request has been delivered.Please wait for answer.;
            halt;
        >
        @ We're away and no urgent messages waiting,
        @ warn the nick that talk to us...
        say $1 Sorry , I'm currently away : $my.away.message.
        say $1 If you have an urgent message , you can write : .urgentmsg
        say $1 and I will hear a sound playing...maybe I'll answer
    >
>
We may consider it as finished , but if we want to be pedantic there is another work to be done.
In KVirc there is a built in AWAY command that can be used instead of myaway.
If someone use away, the reply system will not work.
So we're going to handle the Event_OnMeAwayChange.
If the server replies an away state change we will know it.
Event : Event_OnMeAwayChange : parameters : $0 = away message from server or $_null if we're back
/<
    @ First check if we re away or back
    if ($0)<
        @ We're going away
        if (!$%ext_isset[$my.away.message])<
            @ Need to set it...use a default one
            set $my.away.message Away since $_time $_date;
            halt;
        >
    > ; else <
        @ We're back,unset it anyway...
        unset $my.away.message;
    >
>

Binary rappresentation of numbers

This is a slightly different example.
This alias is in fact a function , and returns a string that is the binary rappresentation
of a positive number (on 16 bits).

Alias : GETBININTERNAL param : a number
/if (!$1)halt;
set $cnt 16
set $num $1
while ($cnt)<
    set $mod $%cal_mod[$1,2]
    set $1 $%cal_div[$1,2]
    set $result $mod$result
    dec $cnt
>
return $result
unset $cnt
unset $num
unset $mod
unset $result

Now the interface alias.
Alias : GETBIN param : a number
/if (!$%str_isnum[$1])<
    echo $_window No number to rappresent!;
    halt
>
echo $_window $1 = $%ext_alias[GETBININTERNAL $1]

Now try to call /GETBIN 256 :).

Index