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.

lsort help

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

lsort help

Post by COBRa »

Hi guys i have a script that writes and reads a .txt file and im trying to list the file alphabetically

here is the code

Code: Select all

# set the location of the banned.txt file
set banned_(txt) "/home/eggbots/eggdrop/scripts/banned.txt"

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

#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"]
   set line_sort [lsort -dictionary $lines]
   set lines1 [split $line_sort "\n"] 
   
   putserv "privmsg $chan :\00314$site_(name)\003 - \0034(BaNNeD LiST)\003 - $lines1"

}

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_

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

	set lines [split $data "\n"]

	set el_num [lsearch $lines $text]

	if {$el_num != -1} {

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

    putquick "PRIVMSG $chan : \0034Ban Removed Sucessfully\003"

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

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


}
but it outputs with these braces

Code: Select all

FtN - (BaNNeD LiST) - {aBD AlternativePorn ANiURL CoWRY D3Si EiNFACHNORMAL GAYGAY JustDifferent Ltu MANLOVE N3WS NAMi ONEPiECE PMCG PR0N0Z ZHONGGUO}
is it possible to output without the {} plz

many thx in advance
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

A quick read-through of the code suggests there are some flaws in the get:banned proc, mainly related to how lists are handled...

Depending on how you'd like the output, you might try replacing the following line:

Code: Select all

set lines1 [split $line_sort "\n"]
into

Code: Select all

set lines1 [join $line_sort ", "]
NML_375
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

Post by COBRa »

Many thx it works a treat
Post Reply