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 some help plz

Help for those learning Tcl or writing their own scripts.
Post Reply
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

Need some help plz

Post by COBRa »

Im writing a script which adds bans to a text file tht part works fine its the output to channel i cant get right atm it outputs like this

CN - (BaNNeD LiST) - GROUP1GROUP2

but i'd like it to output like this

CN - (BaNNeD LiST) - GROUP1 GROUP2 (with the space in between)

here's what i have so far

Code: Select all

# set the location of the banned.txt file
set banned_(txt) "/*****/*****/***/scripts/banned.txt"

#set the sitename
set site_(name) "CN"

#set the trigger
bind pub - !banned get:banned
bind pub - !addban get:addban 

proc get:addban {nick uhost handle chan text} {
  global banned_
   if {$text == ""} {
   return 0
   }
   set line_to_add $text
   set fname $banned_(txt)
   set fp [open $fname "a"]
   puts $fp $line_to_add
   close $fp
   putquick "PRIVMSG $chan : \0034Ban Added Sucessfully\003"
} 

proc get:banned {nick uhost handle chan arg} {
  global banned_ site_
      foreach line [split [exec cat $banned_(txt)] " "] {
      putquick "PRIVMSG $chan :\00314$site_(name)\003 - \0034(BaNNeD LiST)\003 - $line"
   }
}

putlog "COBRa Banned Script V1.0 Sucsesfully loaded"
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

Code: Select all


### reference:
### http://forum.egghelp.org/viewtopic.php?t=6885

proc get:banned {nick uhost handle chan arg} {
  global banned_ site_

   set fp [open $banned_(txt) "r"]
   set data [read -nonewline $fp]
   close $fp

   set lines [split $data "\n"] 

   foreach ban $lines {
  	   putserv "privmsg $chan :$ban"
	 }
} 


Substitute that and try it.


Else:

Code: Select all


### reference:
### http://forum.egghelp.org/viewtopic.php?t=6885

proc get:banned {nick uhost handle chan arg} {
  global banned_ site_

   set fp [open $banned_(txt) "r"]
   set data [read -nonewline $fp]
   close $fp

   set lines [split $data "\n"] 

   putserv "privmsg $chan :$lines"

} 


Try that.
The second example may be what you are looking for.
(You'll have to edit in the other text and color codes that you desire later)


I have not tested the above, so I'm hoping for no typos.

I hope this helps.
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

Post by COBRa »

Works great ty very much

Just one more question if i wanted to del a single entry would tht be possible plz
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Try all or part of this forum string...

http://forum.egghelp.org/viewtopic.php?t=19168
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

Post by COBRa »

SpiKe^^ wrote:Try all or part of this forum string...

http://forum.egghelp.org/viewtopic.php?t=19168
Ty looked at tht earlier and couldnt understand the code :(
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Sorry, that actually wasn't the right string, doesn't even include the delete line function:) This string does...

http://forum.egghelp.org/viewtopic.php?t=19179

Basicly, you have to open a new file, and write all the lines except the line you wish to delete, to the new file.
then delete the original file, and rename the new file:)

See this help string for how to code this yourself... http://forum.egghelp.org/viewtopic.php?t=6885
Last edited by SpiKe^^ on Sat Jan 05, 2013 2:17 am, edited 1 time in total.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

Post by COBRa »

ive come up with this but it seems to del everything where am i going wrong plz

Code: Select all

proc get:delban {nick uhost handle chan text} {
  global banned_
    if {$text == ""} {
    return 0
    }
    set line_to_delete $text
    set fname $banned_(txt)
    set fp [open $fname "w"]
    puts $fp $line_to_delete
    close $fp
    putquick "PRIVMSG $chan : \0034Ban Removed Sucessfully\003"
  }
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

In that process, you are overwriting the entire file, with the line you wish to delete.

Basicly, you have to open a new file, and write all the lines EXCEPT the line you wish to delete, to the new file.
then delete the original file, and rename the new file.
http://forum.egghelp.org/viewtopic.php?t=6885
This help string has all the file functions layed out in their simplest forms, if you want to try writing this yourself.

Do you really want help, or do you want someone to write you a process? If you just want someone to write you a process,
this forum post string http://forum.egghelp.org/viewtopic.php?t=19179 has the delete/edit/add functions included.
Simply rem out the binds you don't wish to use. Or just cut out the parts you need... but that route seems a waste though,
because it also includes all the other file functions you will want next:)
Last edited by SpiKe^^ on Sat Jan 05, 2013 2:22 am, edited 2 times in total.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

Post by COBRa »

tbh i think im gonna need someone to write the code in its entirity it seems very involved can u help plz ?
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

EditTextFile+TimedReadLine Version 1.0

Post by SpiKe^^ »

I would, but I just wrote the same thing a few weeks ago... please just use the last script in this string -> http://forum.egghelp.org/viewtopic.php?t=19179

Disable the timed part -> set eTxFile(timed) "0"

All the included commands will come in handy when working with the information in your text file, you can change the triggers to suit your needs, and disable the commands you wont use...

Has help in the script file for all the included commands, and help available by public trigger for every command... you can read the whole file or any line in the file, edit any line in the file, delete any line in the file, even add a line to the beginning of the file or the end of the file or anywhere in between:)

Script even checks for if the file exists, and will make it when needed, if it does not exist.

If I thought this script wasn't what you needed, I would write another, but it is what you are needing, so I won't be rewriting it again any time soon:)
You can run this script, and yours too. Yours to do the things you have so far, and mine to do the other file work.

Please just try the script as it is now, I'm sure you will come to like it.
If after you have run it, there are things you would like it to do differently, we may be able to address those issues.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

Post by COBRa »

After much help from the guys in this thread here is the final draught

Code: Select all

# set the location of the banned.txt file
set banned_(txt) "**************"

#set the sitename
set site_(name) "*******"

#set the trigger
bind pub - !banned get:banned
bind pub - !addban get:addban
bind pub - !delban get:delban

proc get:banned {nick uhost handle chan arg} {
  global banned_ site_

   set fp [open $banned_(txt) "r"]
   set data [read -nonewline $fp]
   close $fp

   set lines [split $data "\n"] 
   
   putserv "privmsg $chan :\00314$site_(name)\003 - \0034(AFFiLs BaNNeD LiST)\003 - $lines"

}

proc get:addban {nick uhost handle chan text} {
  global banned_
   if {$text == ""} {
   putserv "PRIVMSG $chan :Usage: !addban <grpname>" 
   return 0
   }
   set line_to_add $text
   set fname $banned_(txt)
   set fp [open $fname "a"]
   puts $fp $line_to_add
   close $fp
      
   putquick "PRIVMSG $chan : \0034Ban Added Sucessfully\003"
}

proc get:delban {nick uhost handle chan text} {
	global banned_

##	putserv "privmsg $chan :text is: $text"



	set fp [open $banned_(txt) "r"]
	set data [read -nonewline $fp]
	close $fp

	set lines [split $data "\n"]


##	putserv "privmsg $chan :lines is: $lines"

	set el_num [lsearch -nocase $lines $text]

##	putserv "privmsg $chan :el_num is: $el_num"


	if {$el_num != -1} {

		set lines [lreplace $lines $el_num $el_num]
	}

##	putserv "privmsg $chan :lines is now: $lines"
    putquick "PRIVMSG $chan : \0034Ban Removed Sucessfully\003"

	set fp [open $banned_(txt) "w"]

	foreach element $lines {
		puts $fp $element
	}
	close $fp


}


 

putlog "COBRa Banned Script V1.2 Sucsesfully loaded" 
works for me once big thx to SpiKe^^/willyw for their help
Post Reply