/* BlackJac's stuff */
alias cat {exec -o cat $*}
alias cls clear
alias cecho {echo $cparse("$*")}
alias channels {xecho -b Current channels: $(hwht)$mychannels()$(cl)}
alias chans channels
alias cme {me $cparse("$*")}
alias cmsg if ([$0]) {msg $0 $cparse("$1-")}
alias csay {say $cparse("$*")}
alias dir ls -lF
alias eecho {eval echo $*}
alias fakeop mode $C +o-o $0 $0
alias get if ([$0]) {dcc get $0}
alias internic {exec whois -h whois.internic.net $0}
alias signoff quit
alias awaytime if (u) {
    xecho -b You have been set away for: $tdiff2(${time() - u})
}{echo $G You are not set away.}
/* End BlackJac section */

alias unflash msg ${[$0] ? [$0] : C} $chr(155)40\;37m$chr(155)8]
alias ansibomb msg ${[$0] ? [$0] : C} $chr(155)5\;1\;31\;42m$chr(155)8]
alias chanstats //chans
alias pingme {ping $N}
alias key if ([$0]) {mode $C +k $0}
alias page if ([$0]) {ctcp $0 page $1-}
alias reop {
    @ ch1 = [$0] ? [$0] : C
    if (ischanop($N $ch1)) {
	fe ($chops()) o1 o2 o3 o4 {mode $ch1 +oooo $o1 $o2 $o3 $o4}
    }
}
alias coreban {mode $C +b-b *!%n@* *!%n@*}
alias allop if ([$0]) {
    fe ($mychannels()) ch1 {
	if (ischanop($N $ch1) && !ischanop($0 $ch1) && match($0 $chanusers($ch1))) {
	mode $ch1 +o $0
    }
}
}{pecho Usage: /allop <nick>}
alias jchans if (user_chans) {
    fe ($user_chans) ch1 {
	if (!chanusers($ch1)) {
	    join $ch1;wait
	}
    }
}
alias mme ame
alias ame if ([$0]) {
    me $*
    fe ($mychannels() - $C) ch1 {^describe $ch1 $*}
}

/* window aliases */
alias wj if ([$0]) {wc;window swap last;join $0-;window double on}{pecho Usage: /wj <channel>}
alias msgwin {wc;wn;window level msgs,notices;window name messages}
alias dccwin {wc;wn;window level dcc;window name dcc}
alias wlk {part $C;wk}
alias lwk wkl
alias wc {^window new double on hide;reset}
alias wk window kill
alias ws window list
alias wh window help
alias wn window next
alias wp window previous

on #-dcc_request 981 * {
    if (dcc_log) {
	@ :open_dcc_logfile = open($dcc_logfile W T)
	switch ($tolower($1)) {
	    (send) {
		@ write($open_dcc_logfile [$Z]: $0 [$userhost()] requested DCC $1 [$2] $3 bytes)
	    }
	    (chat) {
		@ write($open_dcc_logfile [$Z]: $0 [$userhost()] requested DCC $1)
	    }
	    (*) {
		@ write($open_dcc_logfile [$Z]: $0 [$userhost()] requested DCC $1 [$2] $3)
	    }
	}
	@ close($open_dcc_logfile)
    }
}
on #-ctcp 981 "% % email *" {
    if (email) {
	^notice $0 [p] E-mail: [$(email)]
    }
}
on #-join 981 * {
    if (autoop_operators && ischanop($N $1) && !ischanop($0 $1) && [$0] != N) {
	@ ch1 = [$1]
	userhost $0 -cmd if ([$1] == [+]) {mode $ch1 +o $0}
    }
}
on #-join 981 '$N *' {@ p.channel_sync = [1]}
on #-channel_signoff 981 * {
    if (auto_cycle && !p.channel_sync && numonchannel($0) <= 2 && [$1] != N && !ischanop($N $0)) {
	pecho Auto-cycle gaining ops in $fix.c1($0)
	cycle $0
    }
}
on #-leave 981 * {
    if (auto_cycle && !p.channel_sync && numonchannel($1) <= 2 && [$0] != N && !ischanop($N $1)) {
	pecho Auto-cycle gaining ops in $fix.c1($1)
	cycle $1
    }
}
on #-timer 981 * if (keepnick && S && !p.getnick) {
    if (keepnick_nick != N) {
	pecho Keepnick has detected the wrong nick. Running getnick...
	getnick $keepnick_nick
    }
}

on ^mail * {xecho -b You have $cparse("%W[%n$0%W]%n new email") message$fix.pl($0), $cparse("%W[%n$1%W]%n total") message$fix.pl($1).}

on ^timer "00:00" if (dcc_log) {
    @ :open_dcc_logfile = open($dcc_logfile W T)
    @ write($open_dcc_logfile TimeStamp [$stime($time())])
    @ close($open_dcc_logfile)
}

on -invite * if (pattern($1 $auto_join_on_invite)) {
    pecho Auto-joining $fix.c1($1)
    join $1
}

/* this function is courtesy of shade */
alias numdots {@ function_return = repeat(${[$0] - strlen($1-)} $(hblk).$(cl)) ## [$1-]}

alias chanlist {
    pecho Channels: $fix.c1($user_chans)
    pecho Type /jchans to join them
}

alias addchan if ([$#0]) {
    fe ($*) ap {if (!match($ap $user_chans)) {@ push(user_chans $ap)}}
    pecho Added $fix.c1($*) to channel list
    chanlist
}{pecho Usage: /addchan <channel>}

alias remchan if ([$#0]) {
    fe ($*) rm {@ user_chans = remw($rm $user_chans)}
    pecho Removed $fix.c1($*) from channel list
    chanlist
}{pecho Usage: /remchan <channel>}

alias checkwho {
    @ user.n = user.h = user.s = []
    ^stack push on who
    ^on ^who "*" {@ user.n = [$1];@ user.h = [$4];@ user.s = [$5]}
    wait for who $0
    ^on ^who -"*"
    ^stack pop on who
    @ function_return = user.h ? 1 : 0
}
alias checkhost {
    wait for userhost $0 -cmd {
	@ user.n = [$0];@ user.h = [$4];@ user.f = [$3@$4]
	@ function_return = (user.h != [<UNKNOWN>]) ? [1] : [0]
    }
}

alias pecho echo [$(hwht)p$(cl)] $*

alias fix.oo1 @ function_return = [$0] == [1] ? [on] : [$0] == [0] ? [off] : [$*]
alias fix.oo2 @ function_return = [$0] == [on] ? [1] : [$0] == [off] ? [0] : [$*]

alias fix.yn @ function_return = [$0] ? [yes] : [no]
alias fix.off @ function_return = [$0] ? [$0] : [off]

alias fix.c1 @ function_return = [$(hblk)[$(cyn)$*$(hblk)]$(cl)]

alias fix.pl @ function_return = [$0] != 1 ? [s] :

#alias fix.s1 @ function_return = [$0] == chr(145) ? [OFF] : [ON]
#alias fix.s2 @ function_return = [$0] == [0] ? chr(145) : toupper($0) == [OFF] ? chr(145) : [1]
#alias fix.s3 @ function_return = [$0] == chr(145) ? [0] : [$*]

