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.

Again doubts a braces in nick

Help for those learning Tcl or writing their own scripts.
Post Reply
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Again doubts a braces in nick

Post by juanamores »

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. :oops:

example:
!notiadd {juan}
Returns first line of file (prohibidos.txt) {juan}
!notiadd pedro
Returns second line of file (prohibidos.txt) pedro

Code: Select all

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 :)
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: Again doubts a braces in nick

Post by willyw »

juanamores wrote:I wish the nick containing braces in file storage.
...
example:
!notiadd {juan}
Returns first line of file (prohibidos.txt) {juan}
!notiadd pedro
Returns second line of file (prohibidos.txt) pedro

Code: Select all

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/200702051134 ... cters.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 !
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Re: Again doubts a braces in nick

Post by juanamores »

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.
<oper> !notiadd {test}
<bot> test has been added to the list of banned nicks.
The code continues regardless nick braces. :?

EDIT: I fixed!

Code: Select all

set nickpro [lindex [split $arg { }] 0]
Thanks willyw :D
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 :)
Post Reply