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.

Simple !add !delete !edit Script

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
j
janii
Halfop
Posts: 41
Joined: Wed Aug 03, 2011 8:08 am

Simple !add !delete !edit Script

Post by janii »

hello i want a tcl which does the following
This is the out put text file

17|how old are you?
7th nov|what is date today?
egghelp.org|what is ur fav website ?

Now i want to add delete and edit in above text file

!add guides|what is ur nick ? {and it shld add a new line i.e line#4}

17|how old are you?
7th nov|what is date today?
egghelp.org|what is ur fav website ?
guides|what is ur nick ?

!delete 4 {it shld delete line #4

!edit 4 janii| wat ur nick ? {it shld replace line#4 guides with janii}


17|how old are you?
7th nov|what is date today?
egghelp.org|what is ur fav website ?
janii|what is ur nick ?

the below code is similar to what i want but not exactly wht i want if some one can modify it to my needs
and ya only few nicks can do !add !edit !delete commands
thanx

Code: Select all

# *************************************************************************************************************************************** #
# ********** INSTALLATION *************************************************************************************************************** #

# 1 configure database.tcl in a suitable text editor
# 2 create the subdirectory scripts/database if it doesn't already exist
# 3 put the configured database.tcl into the bot's scripts/database subdirectory
# 4 add a line to the end of the bot's .conf file 'source scripts/database/database.tcl'
# 5 restart the bot (not rehash)
# 6 requires '.chanset #channelname +database' in the partyline to function in #channelname

# *************************************************************************************************************************************** #
# ********** CONFIGURATION ************************************************************************************************************** #

# ***** configuration is not essential as some thought has been given to the optimal default settings below ***** #

# set here the single character command trigger
# ensure that it is set such that it does not interfere with similar commands on this or other bots in the same channel(s)
# allowed values are as follows
# , = comma
# . = period
# ! = exclamation mark
# $ = dollar sign
# & = ampersand
# - = hyphen
# ? = question mark
# ~ = tilde
# ; = semi-colon
# : = colon
# ' = apostrophe
# % = percent
# ^ = caret
# * = asterisk
set vDatabaseTrigger !

# set here the text colours used in the bot's responses
# settings are only valid where channel mode permits colour, otherwise all text is default colour
# allowed values are as follows
# 00  = white
# 01  = black
# 02  = blue
# 03  = green
# 04  = light red
# 05  = brown
# 06  = purple
# 07  = orange
# 08  = yellow
# 09  = light green
# 10 = cyan
# 11 = light cyan
# 12 = light blue
# 13 = pink
# 14 = grey
# 15 = light grey
set vDatabaseColor(arrow) 03
set vDatabaseColor(compliance) 10
set vDatabaseColor(dimmed) 14
set vDatabaseColor(emphasis) 12
set vDatabaseColor(errors) 04
set vDatabaseColor(output) 05
set vDatabaseColor(typo) 06

# set here the bot user flag required to add, modify or delete database records
# allowed values are as follows
# o = global operator
# m = global master
# n = global owner
set vDatabaseFlag m

# *************************************************************************************************************************************** #
# ********** CODE *********************************************************************************************************************** #

# *********************************** #
# *** DO NOT EDIT BELOW THIS LINE *** #
# *********************************** #

# ---------- INITIALISE ------------------------------------------- #

set vDatabaseVersion 10.04.29.15.48

setudef flag database

set vDatabaseCommands {add copy delete help keywords modify replace search show}

proc pDatabaseTrigger {} {
    global vDatabaseTrigger
    return $vDatabaseTrigger
}

# ---------- BINDS ------------------------------------------------ #

bind EVNT - init-server pDatabaseRead
bind EVNT - rehash pDatabaseRead

bind PUB - [pDatabaseTrigger]help pDatabaseHelp
bind PUB - [pDatabaseTrigger]keywords pDatabaseKeywords
bind PUB - [pDatabaseTrigger]search pDatabaseSearch
bind PUB - [pDatabaseTrigger]show pDatabaseShow

bind PUB - [pDatabaseTrigger]add pDatabaseAdd
bind PUB - [pDatabaseTrigger]copy pDatabaseCopy
bind PUB - [pDatabaseTrigger]delete pDatabaseDelete
bind PUB - [pDatabaseTrigger]modify pDatabaseModify
bind PUB - [pDatabaseTrigger]replace pDatabaseReplace

bind PUBM - "#% [pDatabaseTrigger]*" pDatabaseCheck

# ---------- PROCS ------------------------------------------------ #

proc pDatabaseAdd {nick uhost hand chan text} {
    global vDatabaseData vDatabaseFlag
    if {[channel get $chan database]} {
        if {[matchattr $hand $vDatabaseFlag]} {
            set txt [string trim $text]
            set cmd add
            if {[llength [split $txt]] > 1} {
                set keyword [stripcodes bcruag [string tolower [lindex [split $txt] 0]]]
                set body [join [lrange [split $txt] 1 end]]
                switch -- [array size vDatabaseData] {
                    0 {
                        set vDatabaseData($keyword) $body
                        pDatabaseWrite
                        pDatabaseCompliance 001 0 $nick $chan $keyword 0
                    }
                    default {
                        if {![info exists vDatabaseData($keyword)]} {
                            set vDatabaseData($keyword) $body
                            pDatabaseWrite
                            pDatabaseCompliance 001 0 $nick $chan $keyword 0
                        } else {pDatabaseError 003 0 $nick $chan $keyword 0}
                    }
                }
            } else {pDatabaseError 001 $cmd $nick $chan 0 0}
        } else {pDatabaseError 010 $cmd $nick $chan 0 0}
    }
    return 0
}

proc pDatabaseCheck {nick uhost hand chan text} {
    global vDatabaseCommands
    if {![isbotnick $nick]} {
        set command [string trimleft [lindex [split $text] 0] [pDatabaseTrigger]]
        if {[lsearch -exact $vDatabaseCommands $command] == -1} {
            foreach item $vDatabaseCommands {
                switch -- [expr {[string length $command] - [string length $item]}] {
                    -1 {
                        for {set loop 0} {$loop < [string length $item]} {incr loop} {
                            set pattern [string replace $item $loop $loop]
                            if {[string equal $pattern $command]} {
                                pDatabaseTypo 001 0 $nick $chan $item 0
                                return 0
                            }
                        }
                    }
                    0 {
                        for {set loop 0} {$loop < [string length $item]} {incr loop} {
                            set pattern [string replace $command $loop $loop \?]
                            if {[string match $pattern $item]} {
                                pDatabaseTypo 001 0 $nick $chan $item 0
                                return 0
                            }
                        }
                    }
                    1 {
                        for {set loop 0} {$loop <= [string length $item]} {incr loop} {
                            switch -- $loop {
                                0 {set pattern \?$item}
                                [string length $item] {set pattern $item\?}
                                default {set pattern [string range $item 0 [expr {$loop - 1}]]\?[string range $item $loop end]}
                            }
                            if {[string match $pattern $command]} {
                                pDatabaseTypo 001 0 $nick $chan $item 0
                                return 0
                            }
                        }
                    }
                    default {continue}
                }
            }
        }
    }
    return 0
}

proc pDatabaseColor {chan type number} {
    global vDatabaseColor
    if {[regexp -- {^\+[^\-]*c} [getchanmode $chan]]} {
        return ""
    } else {
        switch -- $number {
            1 {
                switch -- $type {
                    0 {return "\003$vDatabaseColor(errors)"}
                    1 {return "\003$vDatabaseColor(compliance)"}
                    2 {return "\003$vDatabaseColor(output)"}
                    3 {return "\003$vDatabaseColor(typo)"}
                    default {}
                }
            }
            3 {return "\003$vDatabaseColor(dimmed)"}
            5 {return "\003$vDatabaseColor(arrow)"}
            7 {return "\003$vDatabaseColor(emphasis)"}
            2 - 4 - 6 - 8 {return "\003"}
            default {}
        }
    }
}

proc pDatabaseCompliance {number cmd nick chan t1 t2} {
    for {set loop 1} {$loop <= 8} {incr loop} {
        set col($loop) [pDatabaseColor $chan 1 $loop]
    }
    set output1 "$col(1)Compliance$col(2) ($col(3)$nick$col(4)) $col(5)-->$col(6)"
    switch -- $number {
        001 {set output2 "$col(7)$t1$col(8) and associated text has been added"}
        002 {set output2 "$col(7)$t1$col(8) has been deleted"}
        003 {set output2 "text associated with $col(7)$t1$col(8) has been modified"}
        004 {set output2 "found matching keywords $col(7)$t1$col(8)"}
        005 {set output2 "keyword $col(7)$t1$col(8) replaced by $col(7)$t2$col(8) but retaining same text"}
        006 {set output2 "keyword $col(7)$t1$col(8) copied to $col(7)$t2$col(8) with same text"}
        default {}
    }
    putserv "PRIVMSG $chan :$output1 $output2"
    return 0
}

proc pDatabaseCopy {nick uhost hand chan text} {
    global vDatabaseData vDatabaseFlag
    if {[channel get $chan database]} {
        if {[matchattr $hand $vDatabaseFlag]} {
            set txt [string trim $text]
            set cmd copy
            if {[llength [split $txt]] == 2} {
                set old [stripcodes bcruag [string tolower [lindex [split $txt] 0]]]
                set new [stripcodes bcruag [string tolower [lindex [split $txt] 1]]]
                switch -- [array size vDatabaseData] {
                    0 {pDatabaseError 002 0 $nick $chan 0 0}
                    default {
                        if {[info exists vDatabaseData($old)]} {
                            if {![info exists vDatabaseData($new)]} {
                                set vDatabaseData($new) $vDatabaseData($old)
                                pDatabaseWrite
                                pDatabaseCompliance 006 0 $nick $chan $old $new
                            } else {pDatabaseError 003 0 $nick $chan $new 0}
                        } else {pDatabaseError 004 0 $nick $chan $old 0}
                    }
                }
            } else {pDatabaseError 001 $cmd $nick $chan 0 0}
        } else {pDatabaseError 010 $cmd $nick $chan 0 0}
    }
    return 0
}

proc pDatabaseDelete {nick uhost hand chan text} {
    global vDatabaseData vDatabaseFlag
    if {[channel get $chan database]} {
        if {[matchattr $hand $vDatabaseFlag]} {
            set keyword [stripcodes bcruag [string tolower [string trim $text]]]
            set cmd delete
            if {[llength [split $keyword]] == 1} {
                switch -- [array size vDatabaseData] {
                    0 {pDatabaseError 002 0 $nick $chan 0 0}
                    default {
                        if {[info exists vDatabaseData($keyword)]} {
                            unset vDatabaseData($keyword)
                            pDatabaseWrite
                            pDatabaseCompliance 002 0 $nick $chan $keyword 0
                        } else {pDatabaseError 004 0 $nick $chan $keyword 0}
                    }
                }
            } else {pDatabaseError 001 $cmd $nick $chan 0 0}
        } else {pDatabaseError 010 $cmd $nick $chan 0 0}
    }
    return 0
}

proc pDatabaseError {number cmd nick chan t1 t2} {
    for {set loop 1} {$loop <= 8} {incr loop} {
        set col($loop) [pDatabaseColor $chan 0 $loop]
    }
    set output1 "$col(1)Error$col(2) ($col(3)$nick$col(4)) $col(5)-->$col(6)"
    switch -- $number {
        001 {
            switch -- [pDatabaseSyntax $cmd] {
                "" {set output2 "correct syntax is $col(7)[pDatabaseTrigger]$cmd$col(8) without additional arguments"}
                default {set output2 "correct syntax is $col(7)[pDatabaseTrigger]$cmd [pDatabaseSyntax $cmd]$col(8)"}
            }
        }
        002 {set output2 "keyword database is empty"}
        003 {set output2 "keyword $col(7)$t1$col(8) already exists"}
        004 {set output2 "keyword $col(7)$t1$col(8) does not exist"}
        005 {set output2 "the text you entered for keyword $col(7)$t1$col(8) is the same as already exists"}
        006 {set output2 "the <part-keyword> search text must be at least 3 characters in length"}
        007 {set output2 "nothing found for <part-keyword> $col(7)$t1$col(8)"}
        008 {set output2 "the character $col(7)\xA5$col(8) cannot be used anywhere in the keyword or associated text"}
        009 {set output2 "unrecognised command $col(7)$t1$col(8)"}
        010 {set output2 "you do not have access to the command $col(7)$cmd$col(8)"}
        011 {set output2 "$col(7)[pDatabaseTrigger]$cmd$col(8) optional argument(s) must be a single letter"}
        012 {set output2 "no keywords found matching $col(7)$t1$col(8)"}
        013 {set output2 "no keywords found matching $col(7)$t1$col(8) through $col(7)$t2$col(8)"}
        014 {set output2 "second $col(7)[pDatabaseTrigger]$cmd$col(8) optional argument must be lexicographically greater than the first"}
        default {}
    }
    putserv "PRIVMSG $chan :$output1 $output2"
    return 0
}

proc pDatabaseHelp {nick uhost hand chan text} {
    global vDatabaseCommands
    if {[channel get $chan database]} {
        set txt [string tolower [string trim $text]]
        set cmd help
        switch -- [llength [split $txt]] {
            0 {
                foreach item $vDatabaseCommands {
                    pDatabaseOutput 003 0 0 $chan $item 0
                }
            }
            1 {
                if {[lsearch -exact $vDatabaseCommands $txt] != -1} {
                    pDatabaseOutput 003 0 0 $chan $txt 0
                } else {pDatabaseError 009 0 $nick $chan $txt 0}
            }
            default {pDatabaseError 001 $cmd $nick $chan 0 0}
        }
    }
    return 0
}

proc pDatabaseKeywords {nick uhost hand chan text} {
    global vDatabaseData
    if {[channel get $chan database]} {
        set txt [string tolower [string trim $text]]
        set cmd keywords
        if {([llength [split $txt]] >= 0) && ([llength [split $txt]] <= 2)} {
            switch -- [array size vDatabaseData] {
                0 {pDatabaseError 002 0 $nick $chan 0 0}
                default {
                    switch -- [llength [split $txt]] {
                        0 {set data [lsort -dictionary [array names vDatabaseData]]}
                        1 {
                            if {[regexp -- {^[a-z]$} $txt]} {
                                set data [lsort -dictionary [array names vDatabaseData ${txt}*]]
                                if {[llength $data] == 0} {
                                    pDatabaseError 012 0 $nick $chan ${txt}* 0
                                    return 0
                                }
                            } else {
                                pDatabaseError 011 $cmd $nick $chan 0 0
                                return 0
                            }
                        }
                        2 {
                            set arg1 [lindex [split $txt] 0]
                            set arg2 [lindex [split $txt] 1]
                            if {[regexp -- {^[a-z]$} $arg1] && [regexp -- {^[a-z]$} $arg2]} {
                                if {$arg2 > $arg1} {
                                    set data [lsort -dictionary [array names vDatabaseData -regexp [subst -nocommands {^[$arg1-$arg2]}]]]
                                    if {[llength $data] == 0} {
                                        pDatabaseError 013 0 $nick $chan ${arg1}* ${arg2}*
                                        return 0
                                    }
                                } else {
                                    pDatabaseError 014 $cmd $nick $chan 0 0
                                    return 0
                                }
                            } else {
                                pDatabaseError 011 $cmd $nick $chan 0 0
                                return 0
                            }
                        }
                        default {}
                    }
                    while {[llength $data] > 0} {
                        pDatabaseOutput 002 0 0 $chan [lrange $data 0 24] 0
                        set data [lrange $data 25 end]
                    }
                }
            }
        } else {pDatabaseError 001 $cmd $nick $chan 0 0}
    }
    return 0
}

proc pDatabaseModify {nick uhost hand chan text} {
    global vDatabaseData vDatabaseFlag
    if {[channel get $chan database]} {
        if {[matchattr $hand $vDatabaseFlag]} {
            set txt [string trim $text]
            set cmd modify
            if {[llength [split $txt]] > 1} {
                switch -- [array size vDatabaseData] {
                    0 {pDatabaseError 002 0 $nick $chan 0 0}
                    default {
                        set keyword [stripcodes bcruag [string tolower [lindex [split $txt] 0]]]
                        set body [join [lrange [split $txt] 1 end]]
                        if {[info exists vDatabaseData($keyword)]} {
                            if {![string equal $body $vDatabaseData($keyword)]} {
                                set vDatabaseData($keyword) $body
                                pDatabaseWrite
                                pDatabaseCompliance 003 0 $nick $chan $keyword 0
                            } else {pDatabaseError 005 0 $nick $chan $keyword 0}
                        } else {pDatabaseError 004 0 $nick $chan $keyword 0}
                    }
                }
            } else {pDatabaseError 001 $cmd $nick $chan 0 0}
        } else {pDatabaseError 010 $cmd $nick $chan 0 0}
    }
    return 0
}

proc pDatabaseOutput {number cmd nick chan t1 t2} {
    for {set loop 1} {$loop <= 8} {incr loop} {
        set col($loop) [pDatabaseColor $chan 2 $loop]
    }
    switch -- $number {
        001 {set output "$col(1)$t1$col(2) $col(5)-->$col(6) $t2"}
        002 {set output "$col(1)$t1$col(2)"}
        003 {
            switch -- [pDatabaseSyntax $t1] {
                "" {set output "$col(1)[pDatabaseTrigger]$t1$col(2) $col(5)-->$col(6) [pDatabaseText $t1]"}
                default {set output "$col(1)[pDatabaseTrigger]$t1 [pDatabaseSyntax $t1]$col(2) $col(5)-->$col(6) [pDatabaseText $t1]"}
            }
        }
        default {}
    }
    putserv "PRIVMSG $chan :$output"
}

proc pDatabaseRead {type} {
    global vDatabaseData
    if {[file exists database.txt]} {
        set id [open database.txt r]
        set data [split [read -nonewline $id] \n]
        foreach line $data {
            set keyword [lindex [split $line \xA5] 0]
            set body [lindex [split $line \xA5] 1]
            set vDatabaseData($keyword) $body
        }
        close $id
    }
    return 0
}

proc pDatabaseReplace {nick uhost hand chan text} {
    global vDatabaseData vDatabaseFlag
    if {[channel get $chan database]} {
        if {[matchattr $hand $vDatabaseFlag]} {
            set txt [string trim $text]
            set cmd replace
            if {[llength [split $txt]] == 2} {
                set old [stripcodes bcruag [string tolower [lindex [split $txt] 0]]]
                set new [stripcodes bcruag [string tolower [lindex [split $txt] 1]]]
                switch -- [array size vDatabaseData] {
                    0 {pDatabaseError 002 0 $nick $chan 0 0}
                    default {
                        if {[info exists vDatabaseData($old)]} {
                            if {![info exists vDatabaseData($new)]} {
                                set vDatabaseData($new) $vDatabaseData($old)
                                unset vDatabaseData($old)
                                pDatabaseWrite
                                pDatabaseCompliance 005 0 $nick $chan $old $new
                            } else {pDatabaseError 003 0 $nick $chan $new 0}
                        } else {pDatabaseError 004 0 $nick $chan $old 0}
                    }
                }
            } else {pDatabaseError 001 $cmd $nick $chan 0 0}
        } else {pDatabaseError 010 $cmd $nick $chan 0 0}
    }
    return 0
}

proc pDatabaseSearch {nick uhost hand chan text} {
    global vDatabaseData
    if {[channel get $chan database]} {
        set keyword [stripcodes bcruag [string tolower [string trim $text]]]
        set cmd search
        if {[llength [split $keyword]] == 1} {
            if {[string length $keyword] >= 3} {
                foreach name [array names vDatabaseData] {
                    if {[string match *${keyword}* $name]} {
                        lappend result $name
                    }
                }
                if {[info exists result]} {
                    pDatabaseCompliance 004 0 $nick $chan [join $result] 0
                } else {pDatabaseError 007 0 $nick $chan $keyword 0}
            } else {pDatabaseError 006 0 $nick $chan 0 0}
        } else {pDatabaseError 001 $cmd $nick $chan 0 0}
    }
    return 0
}

proc pDatabaseShow {nick uhost hand chan text} {
    global vDatabaseData
    if {[channel get $chan database]} {
        set keyword [stripcodes bcruag [string tolower [string trim $text]]]
        set cmd show
        if {[llength [split $keyword]] == 1} {
            switch -- [array size vDatabaseData] {
                0 {pDatabaseError 002 0 $nick $chan 0 0}
                default {
                    if {[info exists vDatabaseData($keyword)]} {
                        set output [join [lindex [array get vDatabaseData $keyword] 1]]
                        pDatabaseOutput 001 0 0 $chan $keyword $output
                    } else {pDatabaseError 004 0 $nick $chan $keyword 0}
                }
            }
        } else {pDatabaseError 001 $cmd $nick $chan 0 0}
    }
    return 0
}

proc pDatabaseSyntax {command} {
    switch -- $command {
        add {set txt "<keyword> <text>"}
        copy {set txt "<old-keyword> <new-keyword>"}
        delete {set txt "<keyword>"}
        help {set txt "?command?"}
        keywords {set txt "?letter? ?letter?"}
        modify {set txt "<keyword> <text>"}
        replace {set txt "<old-keyword> <new-keyword>"}
        search {set txt "<part-keyword>"}
        show {set txt "<keyword>"}
        default {}
    }
    return $txt
}

proc pDatabaseText {command} {
    switch -- $command {
        add {set txt "add a keyword and associated text"}
        copy {set txt "copy old-keyword to new-keyword with same text"}
        delete {set txt "delete a keyword and associated text"}
        help {set txt "output help for all commands or specified command"}
        keywords {set txt "show existing keywords, using optional argument(s) to restrict output"}
        modify {set txt "modify the text associated with a keyword"}
        replace {set txt "replace old-keyword with new-keyword but retain text"}
        search {set txt "search keywords for incidences of part-keyword"}
        show {set txt "show keyword and associated text"}
        default {}
    }
    return $txt
}

proc pDatabaseTypo {number cmd nick chan t1 t2} {
    for {set loop 1} {$loop <= 8} {incr loop} {
        set col($loop) [pDatabaseColor $chan 3 $loop]
    }
    set output1 "$col(1)Typo$col(2) ($col(3)$nick$col(4)) $col(5)-->$col(6)"
    switch -- $number {
        001 {set output2 "perhaps you meant to type the command $col(7)[pDatabaseTrigger]$t1$col(8)"}
        default {}
    }
    putserv "PRIVMSG $chan :$output1 $output2"
    return 0
}

proc pDatabaseWrite {} {
    global vDatabaseData
    set id [open database.txt w]
    if {[array size vDatabaseData] != 0} {
        foreach {keyword body} [array get vDatabaseData] {
            puts $id "$keyword\xA5$body"
        }
    }
    close $id
    return 0
}

# ---------- ACKNOWLEDGEMENT -------------------------------------- #

putlog "database.tcl version $vDatabaseVersion loaded"
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

So, what's wrong with the script you posted??

It already does add, delete, and edit of a text database file.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
j
janii
Halfop
Posts: 41
Joined: Wed Aug 03, 2011 8:08 am

Post by janii »

thanx 4 the quick reply spike
actually the script i posted ws just to give an idea what i want bcoz it does add delete edit but therez a problem tht its just for database and one i want is for trivia file
like i mentioned tht i want to add a question in txt file
and it shld add a new line whn i do
and thn if i want to !delete a question number it does delete tht particular question number
and thn to edit it shld modify the said question number

but the script i posted for an example doesnt do such things ur a famous trivia tcl maker so u shld ve known now wht exactly i want
thanx
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

That's far from a simple script....

The delete function causes some real issues. Let's say you have a 5 line file:
line1
line2
line3
line4
line5
You want to delete line2 and fix line4. So you delete line2 & that renumbers all lines 3-5 down one number. Then your next command, edit line 4, would try to edit the wrong question line, and the bad question would remain as it was. In actual usage, with let's say 20,000+ lines in the file, and a list of 10 or 12 deletes & edits, the numbering system becomes way crazy.

Also, all the commands would have to make sure the game was stopped before doing anything to the database. Then I believe the eggdrop would have to be rehashed, or maybe even restarted, and the game restarted.

I'm sure there are other problems with the concept that I haven't thought of yet:)
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
j
janii
Halfop
Posts: 41
Joined: Wed Aug 03, 2011 8:08 am

Post by janii »

yes you are right abt it spike but what if we forget abt deleting a question and stick to adding it which is easy part
and editing the question number so if we ve errors in our question file it can be modify frm irc ???
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

That makes the concept more possible, but still not a simple few line script. I will think some on the subject and maybe try some on it tomorrow.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
j
janii
Halfop
Posts: 41
Joined: Wed Aug 03, 2011 8:08 am

Post by janii »

ok No Worries spike i ll be waiting .. and thank u very much for replyin on the topic
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Let's try this first.
Put the code below in a text file, and name it EditTextFile.tcl

Code: Select all

# EditTextFile Version 0.1 #

# author:  SpiKe^^ #
# e-mail:  spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #

# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #

###########  Begin Settings ###########

# set the full route & file name of the file to edit #
set eTxFile(file) {/usr/home/spike/eggdrop/scripts/filename.txt}

# set the channel for this scrip to run in #
set eTxFile(chan) {#yourchannel}

# change the flags and/or public trigger for the add command here #
bind pub o|o !addline etfProcAdd

############  End Settings ############


proc etfProcAdd {nk uh hn ch tx} {
  if {[string tolower $ch] ne [string tolower $::eTxFile(chan)]} { return }
  set tf $::eTxFile(file)

  if {![file exists $tf]} {
    puthelp "PRIVMSG $ch :Text file does not exist: $tf"
    return
  }

  puthelp "PRIVMSG $ch :Adding: $tx :to file: [file tail $tf]"
  set id [open $tf a]
  puts $id $tx
  close $id
  return
}

Edit the file and channel settings.
Upload the new file to your shell's scripts directory.
Add a load line to the bottom of your egg conf file:

Code: Select all

source scripts/EditTextFile.tcl
Upload the edited conf file and .rehash the bot.

My guess is that the trivia game needs to be stopped before you do any file editing with this script.
Try to use the !addline command in the channel you set:
!addline egghelp.org|what is ur fav website ?
You may have to rehash or restart the bot to get it to see the new file line, hard for me to say either way:)
None of this has been tested, so let me know how the script is coming along.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Try this script with all the above instructions. This one has both the commands...
EDIT: and a read command to check if it's the line you are looking for before editing:)

Code: Select all

# EditTextFile Version 0.3 #

# author:  SpiKe^^ #
# e-mail:  spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #

# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #

###########  Begin Settings ###########

# set the full route & file name of the file to edit #
set eTxFile(file) {/usr/home/spike/eggdrop/scripts/filename.txt}

# set the channel for this script to run in #
set eTxFile(chan) {#yourchannel}

# set the public trigger for the add line command #
set eTxFile(add) {!addline}

# set the public trigger for the read line command #
set eTxFile(read) {!readline}

# set the public trigger for the edit line command #
set eTxFile(edit) {!editline}

# set the access flags to use the above public commands #
set eTxFile(flags) {o|o}

############  End Settings ############


bind pub $eTxFile(flags) $eTxFile(add) etfProcAdd
bind pub $eTxFile(flags) $eTxFile(read) etfProcRead
bind pub $eTxFile(flags) $eTxFile(edit) etfProcEdit

proc etfProcAdd {nk uh hn ch tx} {
  if {[string tolower $ch] ne [string tolower $::eTxFile(chan)]} { return }
  set tf $::eTxFile(file)
  if {![file exists $tf]} {
    puthelp "PRIVMSG $ch :Text file does not exist: $tf"
    return
  }
  set tx [string trim $tx]
  if {$tx eq ""} {
    puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(add) text to add to the end of the file."
    return
  }
  puthelp "PRIVMSG $ch :Adding: $tx :to file: [file tail $tf]"
  set id [open $tf a]
  puts $id $tx
  close $id
  return
}

proc etfProcRead {nk uh hn ch tx} {
  if {[string tolower $ch] ne [string tolower $::eTxFile(chan)]} { return }
  set tf $::eTxFile(file)
  if {![file exists $tf]} {
    puthelp "PRIVMSG $ch :Text file does not exist: $tf"
    return
  }
  set tx [string trim $tx]
  if {![string is digit -strict $tx]} {
    puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(read) line#"
    return
  }
  set tid [open $tf]
  set lnum 0
  while {![eof $tid]} {
    set line [gets $tid]
    if {$line ne ""} {  incr lnum
      if {$lnum==$tx} {
        puthelp "PRIVMSG $ch :Existing line $lnum text: $line"
        break
      }
    }
  }
  close $tid
  if {$tx>$lnum} {
    puthelp "PRIVMSG $ch :File line $tx doesn't exist ($lnum lines in the file)"
  }
  return
}

proc etfProcEdit {nk uh hn ch tx} {
  if {[string tolower $ch] ne [string tolower $::eTxFile(chan)]} { return }
  set tf $::eTxFile(file)
  if {![file exists $tf]} {
    puthelp "PRIVMSG $ch :Text file does not exist: $tf"
    return
  }
  set tx [split [string trim $tx]]
  if {[llength $tx]<"2" || ![string is digit -strict [lindex $tx 0]]} {
    puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(edit) line# text to replace original line."
    return
  }
  set find [lindex $tx 0]
  set tx [string trim [join [lrange $tx 1 end]]]
  set new [file dirname $tf]/newfile.tmp
  set nid [open $new w]
  set tid [open $tf]
  set lnum 0
  while {![eof $tid]} {
    set line [gets $tid]
    if {$line ne ""} {  incr lnum
      if {$lnum==$find} {
        puthelp "PRIVMSG $ch :Replacing existing line $lnum text: $line"
        puthelp "PRIVMSG $ch :with the new text line: $tx"
        puts $nid $tx
      } else {  puts $nid $line  }
    }
  }
  close $nid  ;  close $tid
  if {$find>$lnum} {
    puthelp "PRIVMSG $ch :File line $find doesn't exist ($lnum lines in the file)"
    file delete $new
  } else {  file rename -force $new $tf  }
  return
}

Last edited by SpiKe^^ on Wed Nov 28, 2012 5:59 pm, edited 1 time in total.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
j
janii
Halfop
Posts: 41
Joined: Wed Aug 03, 2011 8:08 am

Post by janii »

Now that is sumthing :)
THank You very very much Spike
ur code is working perfectly i dun ve words to thank you thts 2nd problem in a row which u solved :) Luv yaaaa
f
fyre
Voice
Posts: 9
Joined: Thu Jun 08, 2006 9:04 am

Post by fyre »

that's nice, could you add more 2 commands to it.. example

!delline (to delete a specific line)
&
!list (to see the entire list via notice)

thanks in advance :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

See if this variation of the above script will do the job for you...
http://forum.egghelp.org/viewtopic.php?p=100363#100363

You can turn off the timed part of that script with...

Code: Select all

# Set number of minutes between each timed public read line # 
# Set this to "0" to disable all timed public read lines 
# Note: file errors will be sent to the first channel in eTxFile(tchan) 
set eTxFile(timed) "0"
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
j
juggle
Voice
Posts: 15
Joined: Sat Sep 01, 2018 1:04 am

Post by juggle »

I have been looking this kinda script!! i googled so many times an i couldn't fine one.. thanks spike
Post Reply