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.

Need Help Adding A Line in bot config.

Old posts that have not been replied to for several years.
User avatar
CoMMy
Halfop
Posts: 99
Joined: Thu Jul 24, 2003 1:03 am
Location: Cyprus

Need Help Adding A Line in bot config.

Post by CoMMy »

Hi,

I need to add a line into the config of the bot.

First of all i need to make the bot find the name of the config file and second add a line i choose.
Can you make me an example.tcl PLEASE??

THANK YOU :lol:
(c) CoMMy (c)
Resistance is Futile!!
We Are The Borg!!
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

open conf-file
and use puts to add lines to it (use write mode when opening the file)
User avatar
CoMMy
Halfop
Posts: 99
Joined: Thu Jul 24, 2003 1:03 am
Location: Cyprus

Post by CoMMy »

I Do That But It Replaces Everything In The Config File And Puts That Line.
help pls.
(c) CoMMy (c)
Resistance is Futile!!
We Are The Borg!!
User avatar
z_one
Master
Posts: 269
Joined: Mon Jan 14, 2002 8:00 pm
Location: Canada

Post by z_one »

The problem seems to be in the way you use open to access your file.
It looks like you are using the w or w+ attributes. They truncate (empty) the file.
Use a or a+ to append the line at the end of the file.

For more details about the available attributes check out: http://www.cotse.com/dlf/man/TclCmd/open.htm#M8
User avatar
CoMMy
Halfop
Posts: 99
Joined: Thu Jul 24, 2003 1:03 am
Location: Cyprus

Post by CoMMy »

Thanks For That. I made it work. But i also want Something else please.
Is there a variable that gives out the main bots config file name?
And can you tell me how to remove a custom line once i added it?

Thanks again.
(c) CoMMy (c)
Resistance is Futile!!
We Are The Borg!!
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

CoMMy wrote: Is there a variable that gives out the main bots config file name?
The global variable "config" contains the config file name.
User avatar
CoMMy
Halfop
Posts: 99
Joined: Thu Jul 24, 2003 1:03 am
Location: Cyprus

Post by CoMMy »

Thanks egghead.

And can you tell me please how to remove a custom line once i added it?
(c) CoMMy (c)
Resistance is Futile!!
We Are The Borg!!
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

set line [read [open $conf r]]
split $line
close [open $conf r]
if {[lsearch -exact $line your-line] != -1} {
    set ls ""
    while {![eof [open $conf r]]} {
      set got [gets $a]
      if {[string tolower [lindex $got 0]] != [string tolower your-line]} { lappend ls $got }
    }
    close [open $conf r]
    foreach l $ls {
      if {$l != ""} { puts [open $conf w] $l }
    }
    close [open $conf w]
   ##line found and deleted
  } else {
   ##Line wasn't found in the conf file
 }
this should remove a line.
User avatar
CoMMy
Halfop
Posts: 99
Joined: Thu Jul 24, 2003 1:03 am
Location: Cyprus

Post by CoMMy »

Thanks for that but i still can get it to work. This is what i have.
Basically the purpose is of this tcl is a user sets the keepnick by a public cmd and this sets the keep-nick to the value got by the user and after that calls the proc below which gives the error:

Code: Select all

Tcl error [pub_keepnick]: can not find channel named "eggdrop.conf"

Code: Select all

proc keepnick { } {
global keepnick config
if {[info exists keepnick]} { 
set data "set keep-nick $keepnick" 
set line [read [open $config r]] 
split $line 
close [open $config r] 
if {[lsearch -exact $line $data] != -1} { 
    set ls "" 
    while {![eof [open $config r]]} { 
      set got [gets $a] 
      if {[string tolower [lindex $got 0]] != [string tolower $data]} { lappend ls $got } 
    } 
    close [open $config r] 
    foreach l $ls { 
      if {$l != ""} { puts [open $config w] $l } 
    } 
    close [open $config w] 
    rehash
  } else { 
    puts $config $data
    close $config }
    rehash 
 }
HELP PLS
(c) CoMMy (c)
Resistance is Futile!!
We Are The Borg!!
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

[snip]
} else {
puts $config $data
close $config }
rehash
}
replace this with:

Code: Select all

} else { 
  putlog "$line was not found in $conf"
    } 
 }
and put the data in the line before the else where it found the line and deleted it.
User avatar
CoMMy
Halfop
Posts: 99
Joined: Thu Jul 24, 2003 1:03 am
Location: Cyprus

Post by CoMMy »

Will This add the line if it doesn's exist?
(c) CoMMy (c)
Resistance is Futile!!
We Are The Borg!!
User avatar
]Kami[
Owner
Posts: 590
Joined: Thu Jul 24, 2003 2:59 pm
Location: Slovenia
Contact:

Post by ]Kami[ »

should do it
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

CoMMy wrote:Will This add the line if it doesn's exist?
No!, putlog "$line was not found in $conf" means that the line was not found in order to delete it.

Code: Select all

proc keepnick { olddata } { 
global keepnick config 
if {[info exists keepnick]} {
set data "set keep-nick $keepnick"
set line [read [open $config r]] 
split $line 
close [open $config r] 
if {[lsearch -exact $line $olddata] != -1} { 
    set ls "" 
    while {![eof [open $config r]]} { 
      set got [gets $a] 
      if {[string tolower [lindex $got 0]] != [string tolower $olddata]} { lappend ls $got } 
    } 
    close [open $config r] 
    foreach l $ls { 
      if {$l != ""} { puts [open $config w] $l } 
    }
    putlog "Deleted old data and added new one"
    puts [open $config w] $data
    utimer 1 [list close [open $config w]]
    utimer 2 "rehash" 
   }
  }
 }
this is what you want. use keepnick <old-data>
User avatar
CoMMy
Halfop
Posts: 99
Joined: Thu Jul 24, 2003 1:03 am
Location: Cyprus

Post by CoMMy »

Thanks. But you forgot to set a value for "a"

[15:42] Tcl error [pub_keepnick]: can't read "a": no such variable
(c) CoMMy (c)
Resistance is Futile!!
We Are The Borg!!
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Sir_Fz, in your script you often used [open $config ...]. You know that reopens the file each time, right? So in your while loop, you reopen the file each time you read a line... and close it once. The first bit of code, before the while loop, does most of the work, all you had to do was search/replace within the data you read, not re-read the file again. Anyway, something like this should work:

Code: Select all

set newnick "dragon123"

set fp [open $config r]
set lines [split [read $fp] \n]
close $fp
set idx [lsearch -glob "set keep-nick *"]
set newline [list set keep-nick $newnick]
if {$idx != -1} {
  set lines [lreplace $lines $idx $idx $newline]
} else {
  lappend lines $newline
}
set fp [open $config w]
puts -nonewline $fp [join $lines \n]
close $fp
Locked