#by wiebe @ QuakeNet

setudef flag broadcast

bind raw -|- "NOTICE" broadcast:raw

proc broadcast:raw { source cmd text } {
  set target [lindex [split $text] 0]
  if { [string match \$* $target] } {
    set nick [lindex [split $source !] 0]
    set uhost ([lindex [split $source !] 1])
    set text [string trimleft [join [lrange [split $text] 1 end]] :]
    foreach chan [channels] {
      if { [channel get $chan broadcast] && [botonchan $chan] } {
        if { [string match *c* [lindex [split [getchanmode $chan]] 0]] } { set text [stripcodes bcru $text] }
        puthelp "PRIVMSG $chan :* broadcast: $nick $uhost to ${target}: $text"
      }
    }
  }
  return 0
}
