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.

fileorganizer.tcl

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
d
delinquent
Voice
Posts: 11
Joined: Fri Feb 08, 2013 10:58 am
Location: Undernet #ACAB

fileorganizer.tcl

Post by delinquent »

Hello :)

I am looking for a tcl that dows this

Code: Select all

<+delinquent> !filelist -list
<@Eggdrop> Listing file database :
<@Eggdrop> 1. AliciaKeys | 2. Nas 2 | 3. Drake 3 | 4. Rihanna
<@Eggdrop> 5. TwilightSucks | 6. MeganFox | 7. BreakingBad | 8. Supernatural
<@Eggdrop> 9. Barney | 10. Fabolous | 11. Eleven | 12. Kanyw
line 1 , line 2 , line 3 ... etc .. these are the lines in the file from /folder/database

Code: Select all

<+delinquent> !filelist -delete 5
<@Eggdrop> Deleted line number 5 in file database [ TwilightSucks ]
<+delinquent> !filelist -add Justin Bieber sucks
<@Eggdrop> Added line number 12 in file database [ Justin Bieber sucks ]
The tricky part will probably be when i erase lets say line nr 5 .. then the list changes becouse 6 becomes 5 , 7 becomes 6 and so on ..

I hope its doable ....

Thanks a lot in advance !
delinquent @ Undernet

BotLending Project @ www.BotLending.tk
Channels : #Y&X #E&A #LendEgg #mIRC-Bots #MyBot #botland #mythic #lmt #elmt #Eggdrops
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Try this forum string for a couple of scripts for working with text files...
http://forum.egghelp.org/viewtopic.php?p=101119#101119

If one of them is close, maybe it could be edited to your liking.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
d
delinquent
Voice
Posts: 11
Joined: Fri Feb 08, 2013 10:58 am
Location: Undernet #ACAB

Post by delinquent »

Code: Select all

# EditTextFile Version 0.3 #

# author:  SpiKe^^ #
# e-mail:  spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #

# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #

###########  Begin Settings ###########

# set the full route & file name of the file to edit #
set eTxFile(file) {/usr/home/spike/eggdrop/scripts/filename.txt}

# set the channel for this script to run in #
set eTxFile(chan) {#yourchannel}

# set the public trigger for the add line command #
set eTxFile(add) {!addline}

# set the public trigger for the read line command #
set eTxFile(read) {!readline}

# set the public trigger for the edit line command #
set eTxFile(edit) {!editline}

# set the access flags to use the above public commands #
set eTxFile(flags) {o|o}

############  End Settings ############


bind pub $eTxFile(flags) $eTxFile(add) etfProcAdd
bind pub $eTxFile(flags) $eTxFile(read) etfProcRead
bind pub $eTxFile(flags) $eTxFile(edit) etfProcEdit

proc etfProcAdd {nk uh hn ch tx} {
  if {[string tolower $ch] ne [string tolower $::eTxFile(chan)]} { return }
  set tf $::eTxFile(file)
  if {![file exists $tf]} {
    puthelp "PRIVMSG $ch :Text file does not exist: $tf"
    return
  }
  set tx [string trim $tx]
  if {$tx eq ""} {
    puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(add) text to add to the end of the file."
    return
  }
  puthelp "PRIVMSG $ch :Adding: $tx :to file: [file tail $tf]"
  set id [open $tf a]
  puts $id $tx
  close $id
  return
}

proc etfProcRead {nk uh hn ch tx} {
  if {[string tolower $ch] ne [string tolower $::eTxFile(chan)]} { return }
  set tf $::eTxFile(file)
  if {![file exists $tf]} {
    puthelp "PRIVMSG $ch :Text file does not exist: $tf"
    return
  }
  set tx [string trim $tx]
  if {![string is digit -strict $tx]} {
    puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(read) line#"
    return
  }
  set tid [open $tf]
  set lnum 0
  while {![eof $tid]} {
    set line [gets $tid]
    if {$line ne ""} {  incr lnum
      if {$lnum==$tx} {
        puthelp "PRIVMSG $ch :Existing line $lnum text: $line"
        break
      }
    }
  }
  close $tid
  if {$tx>$lnum} {
    puthelp "PRIVMSG $ch :File line $tx doesn't exist ($lnum lines in the file)"
  }
  return
}

proc etfProcEdit {nk uh hn ch tx} {
  if {[string tolower $ch] ne [string tolower $::eTxFile(chan)]} { return }
  set tf $::eTxFile(file)
  if {![file exists $tf]} {
    puthelp "PRIVMSG $ch :Text file does not exist: $tf"
    return
  }
  set tx [split [string trim $tx]]
  if {[llength $tx]<"2" || ![string is digit -strict [lindex $tx 0]]} {
    puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(edit) line# text to replace original line."
    return
  }
  set find [lindex $tx 0]
  set tx [string trim [join [lrange $tx 1 end]]]
  set new [file dirname $tf]/newfile.tmp
  set nid [open $new w]
  set tid [open $tf]
  set lnum 0
  while {![eof $tid]} {
    set line [gets $tid]
    if {$line ne ""} {  incr lnum
      if {$lnum==$find} {
        puthelp "PRIVMSG $ch :Replacing existing line $lnum text: $line"
        puthelp "PRIVMSG $ch :with the new text line: $tx"
        puts $nid $tx
      } else {  puts $nid $line  }
    }
  }
  close $nid  ;  close $tid
  if {$find>$lnum} {
    puthelp "PRIVMSG $ch :File line $find doesn't exist ($lnum lines in the file)"
    file delete $new
  } else {  file rename -force $new $tf  }
  return
} 
This one is good ... only some small changes .. like ..
instead of !addline !readline !editline there must be

Code: Select all

<+delinquent> !readfile
<@Eggdrop> Reading file filename :
<@Eggdrop> 1. AliciaKeys | 2. Nas 2 | 3. Drake 3 | 4. Rihanna
<@Eggdrop> 5. TwilightSucks | 6. MeganFox | 7. BreakingBad | 8. Supernatural
<@Eggdrop> 9. Barney | 10. Fabolous | 11. Eleven | 12. Kanyw 
<+delinquent> !delline 5
<@Eggdrop> Deleted line number 5 in file filename [ TwilightSucks ]
<+delinquent> !addline Justin Bieber sucks
<@Eggdrop> Added line number 12 in file dilename [ Justin Bieber sucks ] 
1. 2. 3. 4. 5. being the lines in the file .... the lines being small i figured that the eggdrop could put 3 or 4 lines in one sentence ... so if i type !readfile ... and there are 60 lines in the file ... the eggdrop would`t ping timeout ...

i suck at scripting .. that why i ask for so much help ...

Thanks !
delinquent @ Undernet

BotLending Project @ www.BotLending.tk
Channels : #Y&X #E&A #LendEgg #mIRC-Bots #MyBot #botland #mythic #lmt #elmt #Eggdrops
Post Reply