egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Multi-line output.

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Froberg
Voice


Joined: 27 Aug 2009
Posts: 10

PostPosted: Fri Sep 25, 2009 9:49 pm    Post subject: Multi-line output. Reply with quote

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:
# 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?
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Sep 26, 2009 12:25 pm    Post subject: Reply with quote

Check this out.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Froberg
Voice


Joined: 27 Aug 2009
Posts: 10

PostPosted: Sat Sep 26, 2009 3:59 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Sep 26, 2009 8:27 pm    Post subject: Reply with quote

How did you use it?
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Froberg
Voice


Joined: 27 Aug 2009
Posts: 10

PostPosted: Sat Sep 26, 2009 8:36 pm    Post subject: Reply with quote

Put it at the top, before everything else.
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sat Sep 26, 2009 9:32 pm    Post subject: Reply with quote

Code:
-> 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.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
Froberg
Voice


Joined: 27 Aug 2009
Posts: 10

PostPosted: Sun Sep 27, 2009 1:41 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber