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.

cant clean file

Old posts that have not been replied to for several years.
Locked
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

cant clean file

Post by the_crow »

Code: Select all

bind pub - !duvida idle_getnick
bind pub o !listar listar:pub

proc idle_getnick {nick mask hand chan text} {
global botnick
set ficheiro "scripts/duvidas.txt"
putserv "PRIVMSG $chan : A sua duvida foi enviada com sucesso. Será respondido o mais depressa possível."
set fp [open $ficheiro a+]
puts $fp "$nick : $text"
catch {close $fp}
}


proc listar:pub {nick mask hand chan text} {
global botnick
set ficheiro "scripts/duvidas.txt"
set fs [open $ficheiro r]
while {![eof $fs]} {
gets $fs line
putserv "PRIVMSG $nick : $line"
}
close $fs
}

how can i make procedure that clean my file when i trig !clean ? thanks :)
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

Code: Select all

set fs [open $ficheiro w]
close $fs
Que?
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

Post by the_crow »

thanks by the help... by the way... how can i make a onjoin that sendme a msg if the file is not empty?can you help me?
n
netux
Voice
Posts: 19
Joined: Fri Jul 30, 2004 8:42 pm

Post by netux »

Code: Select all

bind join - * file_check

proc file_check {n u h c} {
  if {$n != "|The_Crow|"} {return 0} ; set ficheiro [open "scripts/duvidas.txt"] ; set linhas 0
  while {![eof $ficheiro]} {gets $ficheiro line ; if {$line != ""} {incr linhas 1}} ; close $ficheiro
  if {$linhas != 0} {puthelp "PRIVMSG $n : ficheiro não está vazio!"}}
tinhas ajuda ai ao lado ;]
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

Code: Select all

bind join - * file_check
proc file_check {n u h c} {
  set ficheiro "scripts/duvidas.txt" 
  if {[file size $ficheiro] > 0} then {
    putserv "PRIVMSG $n :File $ficheiro is not empty"
  }
} ;# file_check
Que?
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

Post by the_crow »

thanks :)

Netux pois agora começo a reparar... vai aparecendo la mais vezes :) ja agora obrigado pelo codigo... mas prefiro o do outro bacano nao keria tar a fazer incrementacoes :S
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

Post by the_crow »

Code: Select all

bind pub - !duvida idle_getnick
bind pub o !listar listar:pub
bind pub o !apagar apagar:pub
bind join - * file_check

set id 0

proc file_check {n u h c} {
  set ficheiro "scripts/duvidas.txt"
  if {[file size $ficheiro] > 0} then {
    putserv "PRIVMSG $n :Existem duvidas para tirar,faz !listar para veres e depois de resolvidas faz !apagar"
  }
}

proc idle_getnick {nick mask hand chan text} {
global botnick id
set ficheiro "scripts/duvidas.txt"
putserv "PRIVMSG $chan : A sua duvida foi enviada com sucesso. Será respondido o mais depressa possível."
set fp [open $ficheiro a+]
puts $fp "$id -> $nick : $text"
catch {close $fp}
incr id 1
}


proc listar:pub {nick mask hand chan text} {
global botnick
set ficheiro "scripts/duvidas.txt"
putserv "PRIVMSG $nick : Lista de Duvidas por user"
set fs [open $ficheiro r]
while {![eof $fs]} {
gets $fs line
putserv "PRIVMSG $nick : $line"
}
close $fs
}
proc apagar:pub {nick mask hand chan text} {
set id [string tolower [lindex $text 0]]
set ficheiro "scripts/duvidas.txt"
if {$id == ""} { putserv "privmsg $nick : insert the id to clean." }
set fs [open $ficheiro a]
while {![eof $fs]} {
   set linha "[gets $fs]"
   if {$linha != ""} {
     set ident [lindex $linha 0]
     if {$id == $ident} {
      puts $fs2 ""
      close $fs2
      putserv "privmsg $nick : THe id that you wanted was clean."
     }
    }
   }
}
Like you saw i made same alterations, but know when i try to clean one ID like !apagar 1, it doesn´t work...

its a exemple:
!duvita hellp

!listar
(it will appear) 0 - $nick - Hello

!apagar 0

it doesn't work :(
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

Use this to replace or remove line from file:

Code: Select all

 # Replace line(s) in file
  # Usage:
  #  replaceLines <file> <first line> <last line> [replacement data]
  proc replaceLines { args } {
    if {[llength $args] >= 3} then {
      foreach {file start end} $args break
      set cmd [list lreplace [split [read [set f [open $file r]]] \n] $start $end]
      close $f
      if {[llength $args] > 3} then {lappend cmd [lindex $args 3]}
      puts -nonewline [set f [open $file w]] [join [eval $cmd] \n]
      close $f
    } else {
      error "wrong # args: should be \"[lindex [info level 0] 0] file start end ?replacement?\""
    }
  } ;# replaceLines
To remove first line use:

Code: Select all

replaceLines "file.txt" 0 0
To replace first line use:

Code: Select all

replaceLines "file.txt" 0 0 "new data"
Que?
t
the_crow
Halfop
Posts: 42
Joined: Fri Feb 28, 2003 7:37 am
Location: Lisboa, Portugal

Post by the_crow »

thks by helping but i have solved the problem :)
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

KrzychuG wrote:Use this to replace or remove line from file:

Code: Select all

 # Replace line(s) in file
  # Usage:
  #  replaceLines <file> <first line> <last line> [replacement data]
  proc replaceLines { args } {
    if {[llength $args] >= 3} then {
      foreach {file start end} $args break
      set cmd [list lreplace [split [read [set f [open $file r]]] \n] $start $end]
      close $f
      if {[llength $args] > 3} then {lappend cmd [lindex $args 3]}
      puts -nonewline [set f [open $file w]] [join [eval $cmd] \n]
      close $f
    } else {
      error "wrong # args: should be "[lindex [info level 0] 0] file start end ?replacement?""
    }
  } ;# replaceLines
What's up with the screwed up indentation and added braces and keywords? :P
btw: here's a more recent version of that proc (the syntax is identical, but you can also add more lines passed as separate arguments and it's a bit faster)

Code: Select all

proc replaceLines {file args} {
	if {[llength $args]>=2} {
		set data [eval lreplace [list [split [read [set f [open $file]]] \n]] $args]
		close $f
		puts -nonewline [set f [open $file w]] [join $data \n]
		close $f
	} {
		error "wrong # args: should be "[lindex [info level 0] 0] file start end ?replacement?""
	}
}
Have you ever read "The Manual"?
User avatar
KrzychuG
Master
Posts: 306
Joined: Sat Aug 16, 2003 2:51 pm
Location: Torun, Poland
Contact:

Post by KrzychuG »

Nice, i can update it in my scripts :)
Que?
Locked