"del" {
if {![matchattr $hand nm|]} {
putserv "NOTICE $nick :Error: you do not have access to this command, global +n or +m needed."
} elseif {($info == "")} {
putserv "NOTICE $nick :Error: please enter a badword to remove from the database, use !badword del word."
} elseif {($info != "") && [matchattr $hand nm|]} {
set $fs [open "/scripts/inc/badwords.db" "a"]
set data [read -nonewline $fs]
close $fs
set lines [split $data "\n"]
if [string match "$info" $lines] {
set line_to_delete $lines
This is a part of a badwords script im making, i just wondered, how do i remove whats in the $info var, i have read the basic file operations in the tcl faq, but it doesnt help me. Its got to search for the line, and then find out the line number, and then remove. Please help!!
set fs [open "scripts/inc/badwords.db" r]
set data [read -nonewline $fs]
close $fs
if { [set i [lsearch -exact $lines $info]] == -1 } {
puthelp "NOTICE $nick :Error: badword '$info' wasn't found in the database."
} else {
set lines [lreplace $lines $i $i]
set data [join $lines \n]
set fs [open "scripts/inc/badwords.db" w]
puts -nonewline $fs $data
close $fs
puthelp "NOTICE $nick :'$info' is nolonger a badword."
}
btw. I fixed a lot of syntax errors, but I don't if I found all .
Hmm, theres a error somewhere in the script, whenever i type !badword add/del word or !badword list nothjing happens, the bot does not report a erro in dcc, and the bot does not reply. Please help!!
bind pub - * badwords:check
bind pub - !badword bad:words
proc badwords:check {nick host hand chan text} {
global badword botnick
if {[channel get $chan "badwords"]} {
if {![matchattr $hand o|o $chan] && ![matchattr $hand of|of $chan]} {
set $fp [open "/scripts/inc/badwords.db" "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
if [string match "$text" $lines] {
set badword(word,$chan) $lines
set userhost(badword,$chan) [getchanhost $nick $chan]
if {[string match "*users.quakenet.org" $userhost(badword,$chan)]} {
set userhost *!*@[lindex [split $userhost "@"] 1]
newchanban $chan $userhost $botnick "$lines is a badword, banned for 2 minutes." 2
putquick "MODE $chan -o+b $nick $userhost"
putquick "KICK $chan $nick :$lines is a badword, banned for 2 minutes."
timer 2 [list pushmode $chan -b $userhost]
timer 2 [list putserv "PRIVMSG $nick :Your are now unbanned in $chan for saying a badword: $lines."]
}
}
}
}
}
proc bad:words {nick host hand chan text} {
set cmd [lindex [split $text] 1]
set info [join [lrange [split $text] 2 end]]
switch -exact -- [string tolower $cmd] {
"add" {
if {![matchattr $hand nm|]} {
putserv "NOTICE $nick :Error: you do not have access to this command, global +n or +m needed."
} elseif {($info == "")} {
putserv "NOTICE $nick :Error: please enter a badword to add to the database, use !badword add word."
} elseif {($info != "") && [matchattr $hand nm|]} {
set fs [open "/scripts/inc/badwords.db" "a"]
put $fs $info
close $fs
putlog "The word: $info was add to the badwords database by $nick at [timestamp]"
}
}
"del" {
if {![matchattr $hand nm|]} {
putserv "NOTICE $nick :Error: you do not have access to this command, global +n or +m needed."
} elseif {($info == "")} {
putserv "NOTICE $nick :Error: please enter a badword to remove from the database, use !badword del word."
} elseif {($info != "") && [matchattr $hand nm|]} {
set fs [open "scripts/inc/badwords.db" r]
set data [read -nonewline $fs]
close $fs
if { [set i [lsearch -exact $lines $info]] == -1 } {
puthelp "NOTICE $nick :Error: badword '$info' wasn't found in the database."
} else {
set lines [lreplace $lines $i $i]
set data [join $lines \n]
set fs [open "scripts/inc/badwords.db" w]
puts -nonewline $fs $data
close $fs
puthelp "NOTICE $nick :'$info' is nolonger a badword."
putlog "The word: $info was removed from the badwords database by $nick at [timestamp]"
}
}
}
"list" {
if {![matchattr $hand nm|]} {
putserv "NOTICE $nick :Error: you do not have access to this command, global +n or +m needed."
} elseif {![file exist "/scripts/inc/badwords.db"] {
putserv" NOTICE $nick :Error: The badwords database was not found."
} else {
set $fp [open "/scripts/inc/badwords.db" "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
putserv "NOTICE $nick :Badwords List"
putserv "NOTICE $nick :$lines
putserv "NOTICE $nick :End of list"
}
}
}
}
putlog "BADWORDS.TCL LOADED!!"