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.

Delete Proc for database file

Old posts that have not been replied to for several years.
Locked
B
BiLL
Halfop
Posts: 78
Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany

Delete Proc for database file

Post by BiLL »

Greetings,

I have a problem - big one :o). I tried every ways but I don't get it working.

I have a $db file. (easy .txt file).

$db looks like:

User1|Pass1
User2|Pass2
User3|Pass3
User4|Pass4

Now I want to make a function !deluser.
The problem is that it should delete using the username. I already got a proc which does this by linenumber, for example !deluser num 3 (line 3 - User3) - thats no problem, but the problem is getting the line by just the username and the number. I dont want to use !deluser num - I want to use !deluser User2. Can anyone help me coding that proc ? I really don't get it working. It should work like this:

!deluser User3

-> Searches User3 in $db and deletes the WHOLE LINE out of $db.
After that command $db looks like:

User1|Pass1
User3|Pass3
User4|Pass4

Can anyone help me with that?

Big thanks.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

set datafile "bla.txt"

bind pub o !del pub:del

proc pub:del {nick host handle channel text} {
  set found 0
  set index ""
  set info "[lindex [split $text] 0]" 
  set file [open $::datafile r] 
  while {![eof $file]} {
    gets $file line
    if {$line == ""} { continue }
    if {[string match $info [lindex $line 0]]} {
      set found 1
      } else {
      lappend index $line
    }
  }
  if {$found == 0} {
    putserv "PRIVMSG $channel :$info was not found."
    return
  }
  catch {close $file}
  set file [open $::datafile w] 
  foreach line $index {
    puts $file $line
  }
  catch {close $file}
  putserv "PRIVMSG $channel :User '$info' removed."
}
This should do fine.
Once the game is over, the king and the pawn go back in the same box.
B
BiLL
Halfop
Posts: 78
Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany

Post by BiLL »

big thanks.

there seems to be a little bug in it thought.

i used some putserv msgs to check where the error is:

putserv "PRIVMSG $nick :info = $info"
putserv "PRIVMSG $nick :line = $line"
putserv "PRIVMSG $nick :found = $found"

into the while.

now i see :

[18:37] : !deluser user10
[18:37] (test-): info = user10
[18:37] (test-): line = user10|pass10
[18:37] (test-): found = 0
...
[18:37] (test-): User user10 not found.

but info (arg/rest) is correct and the line too.
but it didnt set found = 1.

if {[string match $info [lindex $line 0]]} {
there must be something wrong. maybe that lindex $line 0 ?

please help thanks
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Try changing that line to

if {[string match -nocase $info [lindex [split $line |] 0]]} {
B
BiLL
Halfop
Posts: 78
Joined: Wed Sep 26, 2001 8:00 pm
Location: Germany

Post by BiLL »

awesome - works perfect - big thanks.
Locked