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.

Slap with subject read from file

Help for those learning Tcl or writing their own scripts.
Post Reply
s
starpossen
Op
Posts: 139
Joined: Tue Jan 10, 2006 1:08 am

Slap with subject read from file

Post by starpossen »

I got this slap:

Code: Select all

bind pub o- .slap slap:target

proc slap:target {nick uhost hand chan arg} {
set target "[lindex [split $arg] 0]" ; set reason "[join [lrange [split $arg] 1 end]]"
putserv "PRIVMSG $chan :\001ACTION slaps $target around with a hord of bots!! $reason\001"
}
Is there anyway I could make it read from a file containing various stuff for the slap subject?
I mean if I type .slap nick around with <the stuf from the file>
it would then read from a file random.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Utilising the following should work; edit as required:

Code: Select all

set slap "./slap.txt"
set slapmsg [string range [randomline $slap] 0 end]

# Insert your own procedure.

proc randomline { filename } {

  set position [rand [expr [file size $filename] - 1024]]

  set fd [open $filename r]
  catch {
    seek $fd $position
    set text [read $fd 1024]
  }
  close $fd

  set lines [split $text \n]
  set lineno [randrange 1 [expr [llength $lines] - 1]]

  return [lindex $lines $lineno]
}
Of course you'd have already created "slap.txt" in the ~scripts folder and inserted your own custom messages.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Post Reply