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"