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.

shitlist

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

shitlist

Post by r0t3n »

Ok. Just made this shitlist script.

Code: Select all

bind pub - %shitlist [censored]:list

proc [censored]:list {nick host hand chan text} {
  set cmd [lindex [split $text] 0]
  set rest [lindex [split $text] 1]
  set reason [lindex [range [split $text] 2 end]] 
  switch -exact -- [string tolower $cmd] {
    "add" {
      if {![matchattr $hand ahnmM]} {
        putserv "PRIVMSG $nick :Shitlist: You do not have access to add a channel to the shitlist."
        } elseif {[matchattr $hand ahnmM]} {
        if {($rest == "")} {
          putserv "PRIVMSG $nick :Shitlist: Please enter a channel name to add to the shitlist."
          } elseif {($rest != "") && ![string match "#*" $rest]} {
          putserv "PRIVMSG $nick :Shitlist: Please enter a channel begining with #.
          } elseif {($rest != "") && [string match "#*" $rest]} {
          if {($reason == "")} {
            set $reason No reason added...
            putserv "PRIVMSG $nick :Shitlist: Adding $rest to Shitlist with the reason: $reason."
            } else {
            putserv "PRIVMSG $nick :Shitlist: Adding $rest to Shitlist with the reason: $reason."
          }
          set fp [open shitlist.db a]
          put $fp $rest $reason added by $nick
          close $fp
          putserv "PRIVMSG $nick :Shitlist: $text now added to Shitlist."
          putlog "$nick added $text to the shitlist with the reason: $reason." 
        }
      }
      "del" {
        if {![matchattr $hand ahnmM]} {
          putserv "PRIVMSG $nick :Shitlist: You do not have access to delete a channel from the shitlist."
          } elseif {[matchattr $hand ahnmM]} {
          if {($rest == "")} {
            putserv "PRIVMSG $nick :Shitlist: Please enter a channel name to delete from the shitlist."
            } elseif {($rest != "") && ![string match "#*" $rest]} {
            putserv "PRIVMSG $nick :Shitlist: Please enter a channel begining with #.
            } elseif {($rest != "") && [string match "#*" $rest]} {
            set fp [open shitlist.db r]
            set data [read -nonewline $fp]
            close $fp
            set lines [split $data "\n"]
            if {![string match "$rest" $lines]} {
              putserv "PRIVMSG $nick :Shitlist: $rest is not in the shitlist."
              } elseif {[string match "$rest" $lines]} {
              putserv "PRIVMSG $nick :Shitlist: Deleting $rest from the shitlist."
            }
            set fp [open shitlist.db r]
            set data [read -nonewline $fp]
            close $fp
            set lines [split $date "\n"]
            if {[string match "$rest" $lines]} {
              set delline line number
              set lines [lreplace $lines $delline $delline] 
              set fp [open shitlist.db "w"] 
              puts $fp [join $lines "\n"] 
              close $fp 
              putserv "PRIVMSG $nick :Shitlist: $text is now deleted from the shitlist."
              putlog "$nick deleted $text from the shitlist."
            }
          }
        }
      }
      "list" {
        if {![matchattr $hand ahnmM]} {
          putserv "PRIVMSG $nick :Shitlist: You do not have access to dump the shitlist."
          } elseif {[matchattr $hand ahnmM]} {
          set fp [open shitlist.db r]
          set data [read -nonewline $fp]
          close $fp
          putserv "PRIVMSG $nick :Shitlist: Channel   Reason."
          foreach shitchan [split $data "\n"] {
            putserv "PRIVMSG $nick : [lindex [split $text] 0]   [lindex [lrange [split $text] 1 end]]
          }
          putserv "PRIVMSG $nick :Shitlist: End of shitlist channel list."
        }
      }
      "default" {
        if {![matchattr $hand ahnmM]} {
          putserv "PRIVMSG $nick :Shitlist: You do not have access to any of the shitlist commands."
          } else {
          putserv "PRIVMSG $nick :Shitlist: Shitlist Commands:-."
          putserv "PRIVMSG $nick :Shitlist: \[\] = optional
          putserv "PRIVMSG $nick :Shitlist: %shitlist add #channel [reason]."
          putserv "PRIVMSG $nick :Shitlist: %shitlist del #channel."
          putserv "PRIVMSG $nick :Shitlist: %shitlist list - lists all channels added to the shitlist."
        }
      }
    }
  }
I need to find out the line number for the del part of the script.

Code: Select all

 "del" {
        if {![matchattr $hand ahnmM]} {
          putserv "PRIVMSG $nick :Shitlist: You do not have access to delete a channel from the shitlist."
          } elseif {[matchattr $hand ahnmM]} {
          if {($rest == "")} {
            putserv "PRIVMSG $nick :Shitlist: Please enter a channel name to delete from the shitlist."
            } elseif {($rest != "") && ![string match "#*" $rest]} {
            putserv "PRIVMSG $nick :Shitlist: Please enter a channel begining with #.
            } elseif {($rest != "") && [string match "#*" $rest]} {
            set fp [open shitlist.db r]
            set data [read -nonewline $fp]
            close $fp
            set lines [split $data "\n"]
            if {![string match "$rest" $lines]} {
              putserv "PRIVMSG $nick :Shitlist: $rest is not in the shitlist."
              } elseif {[string match "$rest" $lines]} {
              putserv "PRIVMSG $nick :Shitlist: Deleting $rest from the shitlist."
            }
            set fp [open shitlist.db r]
            set data [read -nonewline $fp]
            close $fp
            set lines [split $date "\n"]
            if {[string match "$rest" $lines]} {
              set delline line number
              set lines [lreplace $lines $delline $delline] 
              set fp [open shitlist.db "w"] 
              puts $fp [join $lines "\n"] 
              close $fp 
              putserv "PRIVMSG $nick :Shitlist: $text is now deleted from the shitlist."
              putlog "$nick deleted $text from the shitlist."
            }
          }
        }
      }

Code: Select all

set delline line number
What do i need to set delline to find out the line number.

Thanks in advance!!
r0t3n @ #r0t3n @ Quakenet
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

you didn't take an iota of a hint from my comments regarding your scripting style, did you?

*sigh*

again, unless you have to manipulate lots of data - and that's not your case - you better slurp all data from file at startup, manipulate all data in memory, and only periodically save to file
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Hmm, no idea how to do that...
r0t3n @ #r0t3n @ Quakenet
k
kanibus
Halfop
Posts: 44
Joined: Tue May 03, 2005 7:22 am

Post by kanibus »

he means to 'open' the file and 'set' all data to say a list, or something easy for you to manipulate it, than when you done save it to the text or periodically save it so its not every time opening and saving, opening and saving, etc.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

slurping (getting all) data from file and populating your structures in memory (normally done only once, on script's startup):

Code: Select all

set thelist {}
if ![catch {set fd [open datafile.txt]}] {
   eval lappend thelist [split [read $fd] \n]
   close $fd
}
manipulating data structures in memory:

Code: Select all

if {...} { ;# add
   lappend thelist $data
} elseif {...} { ;# search
   if {[set idx [lsearch $thelist $data]] != -1} {
      # found
   } else {
      # not found
   }
} elseif {...} { ;# update
   if {[set idx [lsearch $thelist $data]] != -1} {
      lset thelist $idx $newdata ;# ot use [lreplace] for older Tcl installs
   }   
} elseif {...} { ;# delete
   if {[set idx [lsearch $thelist $data]] != -1} {
      set thelist [lreplace $thelist $idx $idx]
   }
}
periodically save data to file:

Code: Select all

bind time - ?0* save
proc save {m h d mo y} {
   set fd [open datafile.txt w]
   foreach elem $thelist {puts $fd $elem}
   close $fd
}
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

In my blacklist script I only open the file when I want to store a new mask or when I want to delete a mask, and whenever one of those is done the new contents are set to the list that's being mainly used in the script.
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

ok. Thanks. Ill add this to the script now. Thanks again.
r0t3n @ #r0t3n @ Quakenet
Locked