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.

.add .del .list

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
e
edu
Voice
Posts: 31
Joined: Sun Oct 29, 2006 2:10 pm

.add .del .list

Post by edu »

Hello

I need some help from you guys ... I need to make three simple public commands

Something like:

Code: Select all

.add <handle> <hostname> <access>
.del <handle>
.whois <handle>
So .. here's what I need ..

When I type:

Code: Select all

.add edu *!*@edu.users.undernet.org 100
I want that the eggdrop adds me into a file like scripts/userlist.txt like:

Code: Select all

$handle:$hostname:$channel:$access
This should be the .add command

Then ..
The .del command will delete the $handle's dates from "userlist.txt"

The .whois command I want to return it some like:

Code: Select all

putquick "NOTICE $nickname :handle: $handle -- hostname: $hostname -- channel: $channel -- access: $access"
Please help me, is very important. Thanks

edu
Seek the truth
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Plenty of examples for doing this kind of stuff around the forum. Take a look at the tcl faq section about basic file operations.
e
edu
Voice
Posts: 31
Joined: Sun Oct 29, 2006 2:10 pm

Post by edu »

I know how to make this simple script, but I don't know how to "create" a file directer where with the public commands to add/del/change it.

:-/

edu
Seek the truth
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Code: Select all

set datafile "/tmp/data.txt"

bind pub - add procadd
bind pub - del procdel
bind pub - list proclist

proc procadd {nick uhost hand chan text} {
        global datafile
        set text [split $text]
        set ahand [lindex $text 0]
        set amask [lindex $text 1]
        set alvl [lindex $text 2]

        # check for valid input
        if {$ahand == "" || $amask == "" || $alvl == ""} {
                puthelp "PRIVMSG $nick :Usage: add <handle> <mask> <level>"
                return
        }

        # check for duplicate handles
        if {[file exists $datafile]} {
                set input [open $datafile r]
                while {![eof $input]} {
                        set curline [gets $input];set curline [split $curline]
                        if {[lindex $curline 0] == $ahand} {
                                puthelp "PRIVMSG $nick :handle $ahand already exists..Delete it first if you want to change it! :P"
                                # or you could overwrite it, but I'm too lazy to do that here :P
                                catch {close $input}
                                return
                        }
                }
                catch {close $input}
        }
        # no dupes found, so add the new line
        # btw, reading/writing tcl-special chars is a real pain in the arse..You'll prolly find that out :^)
        set output [open $datafile a]
        puts $output "[join $ahand] [join $amask] [join $alvl]"
        flush $output
        catch {close $output}
        puthelp "PRIVMSG $nick :Wrote [join $ahand] [join $amask] [join $alvl] to file.."
}               
        
proc procdel {nick uhost hand chan text} {
        global datafile
        set text [split $text]
        set ahand [lindex $text 0]

        # check for valid input
        if {$ahand == ""} {
                puthelp "PRIVMSG $nick :Usage: del handle"
                return
        }

        # check for data file
        if {![file exists $datafile]} {
                puthelp "PRIVMSG $nick :No data file, nothing to delete!"
                return
        }

        # check for requested handle
        set data ""
        set input [open $datafile r]
        while {![eof $input]} {
                set curline [gets $input];set curline [split $curline]
                if {$curline != ""} {
                        set data [linsert $data end $curline]
                }
        }
        catch {close $input}

        set mark -1;set match ""
        foreach line $data {
                incr mark
                if {[lindex $line 0] == $ahand} {
                        set match $mark
                        break
                }
        }
        if {$match == ""} {
                puthelp "PRIVMSG $nick :No handle matching $ahand found.."
                return
        }
        set newdata [lreplace $data $mark $mark]
        set output [open $datafile w]
        foreach newline $newdata {
                if {$newline != ""} {
                        puts $output $newline
                }
        }
        flush $output
        catch {close $output}
        puthelp "PRIVMSG $nick :Deleted $ahand.."
        return                  
}

proc proclist {nick uhost hand chan text} {
        global datafile
        if {![file exists $datafile]} {
                puthelp "PRIVMSG $nick :No data file.."
                return
        }
        set input [open $datafile r]
        set lines [split [read $input] \n]
        catch {close $input}
        set cnt 0
        foreach line $lines {
                if {$line != ""} {
                        puthelp "PRIVMSG $nick :$line"
                        incr cnt
                }
        }
        if {$cnt == 0} {
                puthelp "PRIVMSG $nick :No saved data";return
        } else {
                puthelp "PRIVMSG $nick :End of list.."
        }
}
#####################################################################################################################################
putlog "add/del script loaded.."
What's the point of having a whois command in the bot? Can't you just type /whois directly?
Post Reply