This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Multi-line output.

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
F
Froberg
Voice
Posts: 10
Joined: Thu Aug 27, 2009 9:35 pm

Multi-line output.

Post by Froberg »

Hi all..

I have a script by Flash, which I've modified to only be turned on in a single channel and other very simple things.

I'm using it to display quotes with, however, it doesn't like quite large ones.

I made a techsupport one, and that's got a few long ones - and they end before the "punchline.."

Here's the code:

Code: Select all

# techsupportie script by Flash___, based on Steinsky's quote script.
# ircflash@digdilem.org - #3am at irc.quakenet.org - Flash____
# Modified by Froberg to handle other stuff.. yup.. 
#
# Adds channel commands: !techsupport
# This picks a line at random from a plain ascii file (one quote per line) and
# puts it in the same channel !techsupport was called from. Would be trivial to change
# for any other set of random quotes. Just change the bind and the quotes...
#
# To install: Place this .tcl and techsupport.txt into the scripts/ dir of your eggdrop
# and add the line to your eggdrop.conf file:
#
# source scripts/techsupport.tcl
#
# .rehash or reload your bot and job's done.


# Where are the techsupports ganna be kept? (Relative or absolute path to ascii file)
set techsupportfile scripts/techsupport.txt

# Which channels it's active on.. 
set activechannel [list #DSRack]

# 0 = display techsupports in channel
# 1 = display techsupports via private notice.
set techsupportvianotice 0

#------- Nothing else needs to be twiddled with --------

if { ![info exists toolbox_loaded] } { source scripts/alltools.tcl }

# Change !techsupport to something else if you need a different trigger
bind pub - !techsupport techsupport:pub:techsupport

proc techsupport:pub:techsupport {nick uhost hand chan arg} {
 global techsupportfile techsupportvianotice
 set techsupports ""
  if {[lsearch -exact $::activechannel $chan] == -1} {
 return 0
}
 if { [file exists $techsupportfile] } { set file [open $techsupportfile r] 
 } else {
  if { $techsupportvianotice == 0 } { putmsg $chan "$techsupportfile does not exist. You'll need to add techsupports to the database first by typing \002!addtechsupport <a techsupport>\002" }
  if { $techsupportvianotice == 1 } { putnotc $nick "$techsupportfile does not exist. You'll need to add techsupports to the database first by typing \002!addtechsupport <a techsupport>\002" }
  return 0
 }
 while { ![eof $file] } {
  set techsupport [gets $file]
  if { $techsupport != "" } {
   set techsupports [linsert $techsupports end $techsupport]
  }
 }
 close $file
 if { $arg != "" } {
  set pattern [string tolower $arg]
  set atechsupports ""
  set techsupport ""
  foreach techsupport $techsupports {
   set lowtechsupport [string tolower $techsupport]
   if { [string match $pattern $lowtechsupport] } {
    set atechsupports [linsert $atechsupports end $techsupport]
   }
   set techsupports ""
   set techsupports $atechsupports
  }
 }
 set row [rand [llength $techsupports]]
 if { [expr $row >= 0] && [expr $row < [llength $techsupports]] } {
  set techsupport [lindex $techsupports $row]
 }
 if { $techsupport != "" } {
  if { $techsupportvianotice == 0 } {
   putmsg $chan "Poor Tech Guys: $techsupport"
  }
  if { $techsupportvianotice == 1 } {
   putnotc $nick "$techsupport"
  }
 }
 return 1
}

putlog "techsupport.tcl By Flash! modified by Froberg running. !techsupport to invoke."
I read this thread; http://forum.egghelp.org/viewtopic.php?t=16942 however I didn't want to necro it.. so I'm asking again.
I tried using the code provided, but I couldn't make it work.

Here's a sample of it in action:
[03:47:44] <Froberg> !techsupport
[03:47:46] <DSRack> Poor Tech Guys: I can't connect with the network, remote user tells help desk. "After several minutes of troubleshooting, it was clear that the problem was the user's modem, which basically died," tech reports. Impatient user's next question: "Where can I download another modem?"

And here's a sample of a random line that's too long:
[03:49:56] <Froberg> !techsupport
[03:49:58] <DSRack> Poor Tech Guys: Customer: "My keyboard is not working anymore." Helpdesk: "Are you sure it's plugged into the computer?" Customer: "No. I can't get behind the computer." Helpdesk: "Pick up your keyboard and walk 10 paces back." Customer: "Okay." Helpdesk: "Did the keyboard come with you?" Customer: "Yes." Helpdesk: "That means the keyboard is not plugged in. Is there another keyboard?" Customer: "Yes, there's another one here. Ah, that o

--
If you wanted all of it;

Customer: "My keyboard is not working anymore." Helpdesk: "Are you sure it's plugged into the computer?" Customer: "No. I can't get behind the computer." Helpdesk: "Pick up your keyboard and walk 10 paces back." Customer: "Okay." Helpdesk: "Did the keyboard come with you?" Customer: "Yes." Helpdesk: "That means the keyboard is not plugged in. Is there another keyboard?" Customer: "Yes, there's another one here. Ah, that one works!"

Anyway - I kinda love these tech support things, and I'd hate having to shorten them down, or keep them out because of length :/

Can someone be my saviour?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Check this out.
F
Froberg
Voice
Posts: 10
Joined: Thu Aug 27, 2009 9:35 pm

Post by Froberg »

I tried putting in the data, it didn't break.. the script, but it didn't appear to solve anything either..

Now it just doesn't display the lines that exceed the character limit..

Bot is on Quakenet, by the way.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

How did you use it?
F
Froberg
Voice
Posts: 10
Joined: Thu Aug 27, 2009 9:35 pm

Post by Froberg »

Put it at the top, before everything else.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

-> Add this part to the bottom of your script.

proc msg {type dest data} {
   set len [expr {512-[string len ":$::botname $type $dest :\r\n"]}]
   foreach line [wordwrap $data $len] {
      puthelp "$type $dest :$line"
   }
} 
# wordwrap proc that accepts multiline data
# (empty lines will be stripped because there's no way to relay them via irc)
proc wordwrap {data len} {
   set out {}
   foreach line [split [string trim $data] \n] {
      set curr {}
      set i 0
      foreach word [split [string trim $line]] {
         if {[incr i [string len $word]]>$len} {
            lappend out [join $curr]
            set curr [list $word]
            set i [string len $word]
         } {
            lappend curr $word
         }
         incr i
      }
      if {[llength $curr]} {
         lappend out [join $curr]
      }
   }
   set out
} 


-> Then change this part:
  if { $techsupportvianotice == 0 } {
   putmsg $chan "Poor Tech Guys: $techsupport"
  }
  if { $techsupportvianotice == 1 } {
   putnotc $nick "$techsupport"
  } 

-> To this:
  if { $techsupportvianotice == 0 } {
   msg "privmsg" $chan "\002Poor Tech Guys:\002 $techsupport"
  } else {
   msg "notice" $nick "$techsupport"
  }
Sir_Fz was assuming you had experience with tcl this is all you need to do.
F
Froberg
Voice
Posts: 10
Joined: Thu Aug 27, 2009 9:35 pm

Post by Froberg »

I just combined all the .tcl's in to one, and it's given me a bit of trouble. Thanks for the info, I'll try it out when the script is working again.
Post Reply