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.

Need a script line

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
m
mabus
Voice
Posts: 27
Joined: Fri Jun 17, 2005 6:19 pm

Need a script line

Post by mabus »

When a user types;

!folder file 1:1

I need a line of script that returns the line 1:1 inside the requested file, inside the requested folder.

What would be the simplest way to do this?

I also need if possible for the $file variable to only look at the first 3 letters of the word and ignore the rest of the word.

Any help?
t
theice
Voice
Posts: 36
Joined: Thu Mar 13, 2008 4:20 pm

Post by theice »

start with a public proc / bind

Code: Select all

set pubtrig "!"

#public format !displayfile folder file line

bind pub - ${pubtrig}displayfile display:pub
proc display:pub {nick uname hand chan text} {
	set folder [lindex [split $text] 0]
                set file [lindex [split $text] 1]
                set line [lindex [split $text] 2]

}
you can easily have it return the first 3 letters of the word, once you grab the information.
Image
m
mabus
Voice
Posts: 27
Joined: Fri Jun 17, 2005 6:19 pm

Post by mabus »

Thanks for the reply theice, I realise i was a bit unclear in my question though, sorry about that.

Here's perhaps a better description of what I need to do, Let me give you a step by step example so you can see what I meant;

The structure includes numerous FOLDERS, each folder has many (txt) FILES of 3 letter names. Each file has a lot of numerbed lines, each numbered line contains written text.

So, if a user types !recipies george 1
I would want the script to go into folder recipies
Seek out file geo [ignoring everything after the 3rd letter]
read line 1 (including all text on line 1)
and then read line 1 back to the user on the main channel

So for example;

<Bob> !recipies george 1
<Bot> george 1 - this is the text that appears on line 1
<Bob> !stories larry 4
<Bot> larry 4 - this is the text that appears on line 4
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

EDIT: Changed some stuff, Fixed folder variable error

Code: Select all

set folder(dir) "[pwd]/folders"
set folder(trigger) "!"

bind pubm - "$folder(trigger)*" displayfile

proc displayfile {nick host hand chan text} {
    global lastbind folder
    set folder_ [lindex [split $lastbind !] 1]
    set file [string range [lindex [split $text] 0] 0 2]
    set line [lindex [split $text] 1]
    if {$file == "" || $line == ""} {
       putserv "NOTICE $nickname :SYNTAX: !<folder> <file> <line(s)> (without the <>'s)."
    } elseif {![file exists [file join $folder(dir) $folder_ $file]]} {
       putserv "NOTICE $nick :File '$file' does not exist."
    } elseif {![string is integer $line]} {
       putserv "NOTICE $nick :Line(s) must be a digit."
    } else {
       set f [open [file join $folder(dir) $folder_ $file] r]
       set d [read -nonewline $f]
       close $f
       if {[llength $d] < 1} {
           putserv "NOTICE $nick :File '$file' is empty."
       } elseif {[llength $d] < $line]} {
           putserv "NOTICE $nick :Line number '#$line' does not exist."
       } else {
           set count 0
           puthelp "NOTICE $nick :Contents of file '$file':"
           foreach i [split $d \n] {
               if {$i == ""} { continue }
               incr count
               if {$count == $line} {
                   puthelp "NOTICE $nick :$i"
                   break
               }
           }
           puthelp "NOTICE $nick :Dumped contents of file '$file'."
       }
    }
}
NOT TESTED!
Last edited by r0t3n on Fri Apr 18, 2008 12:10 pm, edited 2 times in total.
r0t3n @ #r0t3n @ Quakenet
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

mabus, you need to provide better information on the files.
Where are the files? Are they in a directory within the eggdrop directory?
What format is the numbering? Is it "1 blahblahblah", or is it "1. blahblahblah", or is it different then those?
m
mabus
Voice
Posts: 27
Joined: Fri Jun 17, 2005 6:19 pm

Post by mabus »

Thanks for all the replies guys, I appreciate the help.

I'll be as detailed as I possibly can be;

The path is: #! /usr1/home/server/mabus/bot

The text files will be in: /bot/scripts/txt/

Inside /txt/ will be a series of folders all like /bot/scripts/txt/help/ or /bot/scripts/txt/rules/ or /bot/scripts/txt/dirs/ and so on

Inside each subfolder will be a bunch of text files. Each of the text files will be only 3 letters long. For example:

/bot/scripts/txt/help/cha
/bot/scripts/txt/help/bot
/bot/scripts/txt/help/web
/bot/scripts/txt/rules/cha
/bot/scripts/txt/rules/ftp
/bot/scripts/txt/dirs/bbs

now.... what i want is for when a user types something like !help channel 1-1

the bot returns the help 1-1 to the channel (from the file cha)

if the user types !rules ftp 20-7
the bot returns the line 20-7 in the rules folder (from the file ftp)
m
mabus
Voice
Posts: 27
Joined: Fri Jun 17, 2005 6:19 pm

Post by mabus »

Tosser, thanks for the code, unfortunately it does not seem to work. I get an error message;

"Tcl error [displayfile]: can't set
"folder": variable is array"
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

I edited my post with a fix, it should work.
r0t3n @ #r0t3n @ Quakenet
m
mabus
Voice
Posts: 27
Joined: Fri Jun 17, 2005 6:19 pm

Post by mabus »

Hey tosser... interesting script, It gives me an error message now that file "fil does not exist". on the command !folder file test.txt 1

Thing is... that format is a good bit different than what i need. I really need the trigger to be !folder file # Example;

!help channel 17

should return line 17 from file cha from folder help
m
mabus
Voice
Posts: 27
Joined: Fri Jun 17, 2005 6:19 pm

Post by mabus »

No one knows how to do this?
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

mabus wrote:No one knows how to do this?
No one Image wants to do this?
corrected your quote above, no thanks neccessary...your tone sounds sarcastic, and your bump isn't going to magically make people do your bidding...
m
mabus
Voice
Posts: 27
Joined: Fri Jun 17, 2005 6:19 pm

Post by mabus »

there was no sarcasm.... and it wasn't a bump .... and it wasn't an attempt to make people "do my bidding" ... it's a script request forum is it not? It's a script I really need, and this is more of a plea for help. I thought that's what this forum was for after all.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

mabus wrote:there was no sarcasm.... and it wasn't a bump .... and it wasn't an attempt to make people "do my bidding" ... it's a script request forum is it not? It's a script I really need, and this is more of a plea for help. I thought that's what this forum was for after all.
There was indeed a bump you silly silly person. You posted this No one knows how to do this? as a new post, when you could've just edited your prior post. Instead of doing that, now you have two replies of your own in a row. This constitutes a bump. You did this so your request would move to the top. In doing this, you ARE NOT going to get any more help. In fact, quite the opposite, people will stop helping you.

Btw, noob, all you need to do is change this line, and instantly Tosser^^'s code works according to your layout.
set folder(dir) "[pwd]/folders" -> set folder(dir) "[pwd]/scripts/txt"
m
mabus
Voice
Posts: 27
Joined: Fri Jun 17, 2005 6:19 pm

Post by mabus »

Speechless, I came to the forum for help... Tosser offered a suggestion for a script that didn't work for me, and after no one replied after a couple of days I repeated my request to see if anyone else had any ideas (lest anyone think the problem was solved).

I assumed this was the best way to go about it, rather than double posting. Obviously I was mistaken and offended you, and I apologise, it was not my intention to do so.

As for your suggestion on the change to Tosser's script. It did not work. The bot does not reply to the command at all now.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

mabus wrote:Speechless, I came to the forum for help... Tosser offered a suggestion for a script that didn't work for me, and after no one replied after a couple of days I repeated my request to see if anyone else had any ideas (lest anyone think the problem was solved).

I assumed this was the best way to go about it, rather than double posting. Obviously I was mistaken and offended you, and I apologise, it was not my intention to do so.

As for your suggestion on the change to Tosser's script. It did not work. The bot does not reply to the command at all now.
Haw.. there is no need to apologize, as it doesn't change anything. The problem is people are assuming this forum section is a 'magic lamp'. Then posting here to them basically is the act of 'rubbing the lamp'. Now the part everybody waits on forever is the genie. Sometimes if you request is meger and not some intense 40hr project, you will get a genie faster... Your request was somewhere in the middle, and your genie was one with much expertise, so to assume after his initial attempts to help you that 'no one knows how to do this' insults your genie. Hopefully you understand, with the clues you gave as to the structure and what not of your files. You've confused many genies initially. Hopefully Tosser can help you further, and your persistant 'rubbing' doesn't upset him as well...
Post Reply