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 

.add .del .list

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


Joined: 29 Oct 2006
Posts: 31

PostPosted: Wed Feb 21, 2007 2:10 pm    Post subject: .add .del .list Reply with quote

Hello

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

Something like:
Code:

.add <handle> <hostname> <access>
.del <handle>
.whois <handle>


So .. here's what I need ..

When I type:
Code:

.add edu *!*@edu.users.undernet.org 100

I want that the eggdrop adds me into a file like scripts/userlist.txt like:
Code:

$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:

putquick "NOTICE $nickname :handle: $handle -- hostname: $hostname -- channel: $channel -- access: $access"


Please help me, is very important. Thanks

edu
_________________
Seek the truth
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Wed Feb 21, 2007 2:13 pm    Post subject: Reply with quote

Plenty of examples for doing this kind of stuff around the forum. Take a look at the tcl faq section about basic file operations.
Back to top
View user's profile Send private message
edu
Voice


Joined: 29 Oct 2006
Posts: 31

PostPosted: Wed Feb 21, 2007 2:16 pm    Post subject: Reply with quote

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


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Wed Feb 21, 2007 6:33 pm    Post subject: Reply with quote

Code:

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?
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