menu channel {
-
$iif(($calc($nick($chan,0) -1)),Greet all $v1 users of $chan)
."Hello" : greetall Hello
."See you later" : greetall See you later
.-
.<other> : greetall
}
alias greetall {
; ---- SETUP START ----
; add nicks (e.g. of Bots) you want to exclude after "$me" (separated by spaces)
var %exclude = $me
; delay in ms for multiple lines (to prevent flood in case a long greeting / a greeting of many nicks exceeds a line length of aprox. 260 chars)
var %delay = 500
; ---- SETUP END ----
; active window is a joined channel
if ($me ison $active) {
; there are other users in the channel
if ($calc($nick($active,0) -1)) {
; prompt for greet message (if no message provided as parameter of the alias)
var %t = $v1, %greeting = $$iif(($1- != $null),$v1,$input(Enter greet message:,eog,Greet all %t users of channel $active,Hello))
; make sure the tempfile is empty
write -c greetall.txt
; loop all nicknames - build a string of nicknames
var %n = 1, %nickstring
while ($nick($active,%n)) {
var %nick = $v1
; don't greet yourself or nicknames specified above
if (!$istok(%exclude,%nick,32)) {
; add this nickname to the string
var %nickstring = %nickstring %nick
; greeting+string reached a certain length (avoid a too long line)
if ($len(%greeting %nickstring) > 250) {
; write this line to the tempfile "greetall.txt", the line will be "greet message" + "formatted string of nicks"
; formatting: insert 1) "and" as second-last word and 2) commas after nicknames, up to the second-last nickname
write greetall.txt %greeting $+ $chr(15) $iif(($numtok(%nickstring,32) == 1),%nickstring, $&
$replace($gettok(%nickstring,1--2,32),$chr(32),$+($chr(44),$chr(32))) and $gettok(%nickstring,-1,32))
; clear string
var %nickstring
}
}
inc %n
}
; if nicks are left in the string: write line to tempfile
if (%nickstring) {
write greetall.txt %greeting $+ $chr(15) $iif(($numtok(%nickstring,32) == 1),%nickstring, $&
$replace($gettok(%nickstring,1--2,32),$chr(32),$+($chr(44),$chr(32))) and $gettok(%nickstring,-1,32))
}
; play tempfile (send greetings to the channel) and remove it
.play -p $active greetall.txt $iif((%delay isnum 0-),$int($v1),500)
.remove greetall.txt
}
; there are no other users in the channel
else { echo -agc info * /greetall: Taking care of yourself? o_O }
}
; active window is no joined channel
else { echo -agc info * /greetall: Cannot greet here ( $+ $active is not a joined channel) }
}