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.

badword script

Old posts that have not been replied to for several years.
Locked
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

badword script

Post by r0t3n »

Code: Select all

"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!!

Thanks in advance!!
r0t3n @ #r0t3n @ Quakenet
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

i suggest using something like:

Code: Select all

    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 :D.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

ok, thanks De Kus!
r0t3n @ #r0t3n @ Quakenet
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

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

Code: Select all

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!!"
Please help!!

Thanks in advance!!
r0t3n @ #r0t3n @ Quakenet
Locked