# How should we display information to user upon trigger requests?
# 0 = Display results to channel
# 1 = Notice user results
# 2 = Private message the user the results
set nflcom(method) 0

# We have to tell the script what char to split text from.
proc nearestindex {text index {char " "}} {
    set tchar [string index $text $index]
    while {($tchar != $char) && ($index >= 0)} {
      incr index -1
      set tchar [string index $text $index]
    }
    return $index
  }  

# Now we have to split the text into parts to display to the channel or user.
proc nflcom_post {who chan text {idx -1}} {
    global nflcom
    if {$idx != -1} {
      putdcc $idx "$text"
      return
    }
    switch $nflcom(method) {
      0 {set method "PRIVMSG $chan :"}
      1 {set method "NOTICE $who :"}
      2 {set method "PRIVMSG $who :"}
    }
    if {[string length $text] >= 256} {
      while {($text != "") && ([string length $text] >= 256)} {
	set tmp [nearestindex "$text" 256]
	if {$tmp != -1} {
	  set textt [string range $text 0 [expr $tmp - 1]]
	  set text [string range $text [expr $tmp + 1] end]
	} else {
	  set textt [string range $text 0 256]
	  set text [string range $text 257 end]
	}
	puthelp "$method $textt"
      }
    }
    if {$text != ""} {
      puthelp "$method $text"
    }
  }

# Here we display the data to the channel or the user.
bind pub $nflcom(pubflags) $nflcom(pubtrigger) nflcom:pubdata
  proc nflcom:pubdata {nick uhost hand chan text} {
  global nflcom botnick
	nflcom_post $nick $chan "- $nflcom(name) (Last updated: [time_diff [clock seconds] $nflcom(lastupdate)] ago.)"
	foreach element $nflcom(nflcomdata) {
	  set element [split $element |]
	  set date [lindex $element 0]
	  set headline [lindex $element 1]
	  set story [lindex $element 2]
	  set links [lindex $element 3]
	  nflcom_post $nick $chan "- \002$headline\002 -- $story"
	  nflcom_post $nick $chan "- $links"
	}
	nflcom_post $nick $chan "- $nflcom(name) (Completed.)"
	return
      }


EXAMPLE OUTPUT:

[10:41] <scrib> - NFL.Com Headlines. (Modified: 11/24/2004 13:25:28)
[10:41] <scrib> - Going way back for this one -- No, it's not going to be the 1956 Colts against the 1948 Lions. But it will sure seem that way as both teams will don throwback uniforms for their key Thanksgiving Day game. But the jerseys won't be the only thing on
[10:41] <scrib> display. NFL.com fantasy expert Gil Brandt likes Detroit's running game with Kevin Jones against Indy's soft defense. And a win by Detroit will make good for the Turkey Day tie in 1965.
[10:41] <scrib> - http://www.nfl.com/fantasy/story/7924806
[10:41] <scrib> - NFL.Com Headlines. (End.)

It works.

--Mosher
