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.

random line from txt file

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
w
whittinghamj
Op
Posts: 103
Joined: Sun May 21, 2006 4:50 pm

random line from txt file

Post by whittinghamj »

Hey guys. I have a script request. I just looked over the forums but could not put my hands on a post that covers this already.

Anyways. I have a text file which is formatted like this.

Code: Select all

Name: info URL: www.url.com
[quote]

What i need is someone to type say !sites and the script goes off and picks randomy a line from the txt file and pastes it to the channel.

No security needed and I am adding the sites already by trigger.

Any help would be great.

Thanks[/quote]
User avatar
SaPrOuZy
Halfop
Posts: 75
Joined: Wed Mar 24, 2004 7:38 am
Location: Lebanon

Post by SaPrOuZy »

Code: Select all

bind pub - !foo bar
proc bar {nick uhost hand chan rest} {
    set file [open "txt_file_path" r] 
    set data [split [read $file] "\n"]
    set line [lindex $data [rand [llength $data]]]
    putserv "privmsg $chan : $line"
    close $file
}
EDIT: Code fixed, thx Sir_Fz
Last edited by SaPrOuZy on Thu Jun 22, 2006 1:50 am, edited 1 time in total.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

And don't forget to close the file.
Post Reply