| View previous topic :: View next topic |
| Author |
Message |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Sat Jan 09, 2016 8:59 am Post subject: lsort help |
|
|
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: | # 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: | | 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 |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Jan 09, 2016 9:16 am Post subject: |
|
|
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: | | set lines1 [split $line_sort "\n"] |
into
| Code: | | set lines1 [join $line_sort ", "] |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Mon Jan 11, 2016 8:02 am Post subject: |
|
|
| Many thx it works a treat |
|
| Back to top |
|
 |
|