egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

fileorganizer.tcl

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
delinquent
Voice


Joined: 08 Feb 2013
Posts: 11
Location: Undernet #ACAB

PostPosted: Mon Apr 22, 2013 9:32 am    Post subject: fileorganizer.tcl Reply with quote

Hello Smile

I am looking for a tcl that dows this
Code:

<+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:

<+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
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Mon Apr 22, 2013 6:21 pm    Post subject: Reply with quote

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
.
Back to top
View user's profile Send private message Visit poster's website
delinquent
Voice


Joined: 08 Feb 2013
Posts: 11
Location: Undernet #ACAB

PostPosted: Tue Apr 23, 2013 6:56 am    Post subject: Reply with quote

Code:
# 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:
<+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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber