| View previous topic :: View next topic |
| Author |
Message |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Wed May 13, 2015 12:48 am Post subject: Again doubts a braces in nick |
|
|
I wish the nick containing braces in file storage.
Something explained me SpiKe^^ in another post, but it was referred to a list, which added nicks.
Now is another case, I store every nick on a separate line of a file.
I don't know fix it for this particular case a file.
example:
| Quote: | !notiadd {juan}
Returns first line of file (prohibidos.txt) {juan}
!notiadd pedro
Returns second line of file (prohibidos.txt) pedro
|
| Code: | bind pub at|n !notiadd notiadd
proc notiadd {nick uhost handle chan text} {
set nickpro [lindex $text 0]
if {![file exist prohibidos.txt]} {
set fs [open prohibidos.txt "w"]
puts $fs ""
close $fs
} else {
set fname "prohibidos.txt"
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
set first [lindex $lines 0]
if {$first == ""} {
set lines [lreplace $lines 0 0]
set fp [open $fname "w"]
puts $fp [join $lines "\n"]
close $fp
}
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines1 [split $data "\n"]
if {([lsearch -exact [string tolower $lines1] [string tolower $nickpro]] == -1)} {
set fp [open $fname "a"]
puts $fp $nickpro
close $fp
putmsg $canal_admin [encoding convertfrom utf-8 "\002$nickpro\002 has been added to the list of banned nicks."]
} else {
putmsg $canal_admin [encoding convertfrom utf-8 "$nickpro was already added!"]
return
}
}} |
_________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Wed May 13, 2015 8:28 am Post subject: Re: Again doubts a braces in nick |
|
|
| juanamores wrote: | I wish the nick containing braces in file storage.
...
example:
| Quote: | !notiadd {juan}
Returns first line of file (prohibidos.txt) {juan}
!notiadd pedro
Returns second line of file (prohibidos.txt) pedro
|
| Code: | bind pub at|n !notiadd notiadd
proc notiadd {nick uhost handle chan text} {
set nickpro [lindex $text 0]
...
|
|
1.) It would help a LOT if when you post code here, it was indented.
Indents and line spaces make code easier to read.
2.) Go here:
http://web.archive.org/web/20070205113405/http://www.peterre.info/characters.html
and read. Especially this section, "The first golden rule of Tcl for eggdrop".
Bookmark that page, and refer back to it, until you master it.
3.) Here is the problem: set nickpro [lindex $text 0]
lindex works on lists, not on strings. $text is a string.
You can "get away with it" sometimes. Then you acquire a bad habit, and one day it comes back to bite you.
Here we are.
Try this: set nickpro [lindex [split $text] 0]
p.s
The code you posted is missing :
set canal_admin $chan
too. _________________ For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia ! |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Wed May 13, 2015 4:09 pm Post subject: Re: Again doubts a braces in nick |
|
|
| willyw wrote: |
Try this: set nickpro [lindex [split $text] 0]
p.s
The code you posted is missing :
set canal_admin $chan
too. |
I tried what you advised me, but it NOT worked.
| Quote: | <oper> !notiadd {test}
<bot> test has been added to the list of banned nicks. |
The code continues regardless nick braces.
EDIT: I fixed!
| Code: | | set nickpro [lindex [split $arg { }] 0] |
Thanks willyw  _________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
|