####################################################
# by wiebe @ QuakeNet
#
# add .ircmotd command to partyline, showing the motd of the irc server
#
####################################################


####################################################
# ircmotd:raw
####################################################
bind raw -|- 372 ircmotd:raw; bind raw -|- 375 ircmotd:raw
bind raw -|- 376 ircmotd:raw; bind raw -|- 422 ircmotd:raw
proc ircmotd:raw { s n t } {
  if {[string equal [lsearch -exact "372 375 376 422" $n] "-1"]} { return 0 }
  global ircmotd
  if {![string equal [lsearch "375 422" $n] "-1"]} {
    if {[info exists ircmotd]} { unset ircmotd }
  }
  set t [string range [join [lrange [split $t] 1 end]] 1 end]
  lappend ircmotd $t
}


####################################################
# ircmotd:dcc
####################################################
bind dcc -|- ircmotd ircmotd:dcc
proc ircmotd:dcc { h i t } {
  global ircmotd
  if {![info exists ircmotd]} {
    putidx $i "ircmotd: motd not cached."
  } else {
    putidx $i "ircmotd: showing motd"
    foreach l $ircmotd { putidx $i "     $l" }
    putidx $i "ircmotd: end of motd"
  }
}


set scriptdb(ircmotd) {
  "provides ircmotd command for showing the bot's IRC server's MOTD"
}

