egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

List elements between braces how to search?

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Mon Apr 27, 2015 11:40 am    Post subject: List elements between braces how to search? Reply with quote

I've managed to save a list of nicks on line 0 in a text file.

The problem I have is when search and find nicks that list that begin and end with braces.

Example:
The nicknames variable is stored the full list of nicks.
$nicknames = pedro juan {FoSFaTiTo} maria susan
When I fetch the nick {FoSFaTiTo} on that list, the code takes the argument WITHOUT braces (the nick contains those braces), for that reason can not find it in the list.
Code:

## !list [nickname]
bind pub n !list list_out_of_fd
proc list_out_of_fd {nick uhost hand chan arg} {
  global nchan
  if {[string tolower $chan] != [string tolower $nchan]} {
   return
  }
  if {[llength $arg] == 0} {
##here nicknames variables take values of list##
   set nicknames [getinfo]
   if {$nicknames == ""} {
     puthelp "NOTICE $nick :No one is added in the database!"
   } else {
     puthelp "NOTICE $nick :Added in the database: $nicknames"
   }
  } elseif {[llength $arg] == 1} {
##here nicknames variables take values of list##
   set nicknames [getinfo]
#For debuggin purposes#
   putmsg $nchan "The list: $nicknames"
   set arg [lindex $arg 0]
#For debuggin purposes# 
 putmsg $nchan "Nick to search: $arg"
   if {[lsearch -exact [string tolower $nicknames] [string tolower $arg]] == -1} {
     puthelp "NOTICE $nick :$arg not found in the database!"
   } else {
     puthelp "NOTICE $nick :$arg  is in the database!"
   }
  } else {
   puthelp "NOTICE $nick :Usage: !list \[nickname\]"
  }
}


Result:
Quote:
<oper> !list {FoSFaTiTo}
<bot> The list: pedro juan {FoSFaTiTo} maria susan
<bot> Nick to search: FoSFaTiTo
<bot> FoSFaTiTo not found in the database!


Any idea how to solve this problem with nicks containing braces?

EDIT:
Another thing I've found if I show the contents of the variable that contains the list, the list looks good by the channel.
Example:
Code:
putmsg #canal "$nicknames"

result:
Quote:
pedro juan {FoSFaTiTo} maria susan

but if I do a foreach or use any other loop in the variable returns the nick me without the braces.
Code:
foreach n $nicknames {
putmsg #canal "$n"
}

result:
Quote:
pedro
juan
FoSFaTiTo
maria
susan


It's so hard to fix this in Tcl?
_________________
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 Smile
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Tue Apr 28, 2015 8:25 am    Post subject: Reply with quote

Quote:
result:

Quote:
pedro juan {FoSFaTiTo} maria susan
That's not a list! It's a space separated string.
You need to split it into a proper tcl list at the spaces before treating it as a list...
Code:
foreach n [split $nicknames] {
  putmsg #canal "$n"
}

_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Tue Apr 28, 2015 10:39 am    Post subject: Reply with quote

Quote:

...
set nicknames [getinfo]
...


It looks like you have some other scripts, or parts to this script, that create a proc named
getinfo

Please show us the whole script.

I'm curious to see how that
getinfo
makes the list, etc.
_________________
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
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Tue Apr 28, 2015 11:44 am    Post subject: Reply with quote

SpiKe^^ wrote:
Quote:
result:

Quote:
pedro juan {FoSFaTiTo} maria susan
That's not a list! It's a space separated string.
You need to split it into a proper tcl list at the spaces before treating it as a list...
Code:
foreach n [split $nicknames] {
  putmsg #canal "$n"
}

Thanks SpiKe^^, when I go home I try to change the code so advised.

willyw wrote:

It looks like you have some other scripts, or parts to this script, that create a proc named
getinfo

Please show us the whole script.

I'm curious to see how that
getinfo
makes the list, etc.


The full code I have already posted in other threads.
See here.

And the proc getinfo, part of the total code is:
Code:
proc getinfo {} {
  global filename
  set file [open $filename r]
  set nlist ""
  while {![eof $file]} {
   set chast [gets $file]
    if {$chast != ""} {
     append nlist $chast
   }
  }
  close $file
  return $nlist
}

_________________
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 Smile
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Tue Apr 28, 2015 3:11 pm    Post subject: Reply with quote

juanamores wrote:

...
And the proc getinfo, part of the total code is:
Code:
proc getinfo {} {
  global filename
  set file [open $filename r]
  set nlist ""
  while {![eof $file]} {
   set chast [gets $file]
    if {$chast != ""} {
     append nlist $chast
   }
  }
  close $file
  return $nlist
}



I created a text file that looks like this:
Code:

pedro
juan
{FoSFaTiTo}
maria
susan

with one nick on each line.
Each is on its own line.
Created with plain text editor - nano.

The proc quote above returns this:

.tcl getinfo
<rog> Tcl: pedrojuan{FoSFaTiTo}mariasusan

Are you sure that is the exact
getinfo
proc that you are using? Because... that's a mess. Smile
_________________
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
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Tue Apr 28, 2015 11:19 pm    Post subject: Reply with quote

willyw wrote:


I created a text file that looks like this:
Code:

pedro
juan
{FoSFaTiTo}
maria
susan

with one nick on each line.
Each is on its own line.
Created with plain text editor - nano.

The proc quote above returns this:

.tcl getinfo
<rog> Tcl: pedrojuan{FoSFaTiTo}mariasusan

Are you sure that is the exact
getinfo
proc that you are using? Because... that's a mess. Smile

The code does not work that way friend.
This code stores all nicks in line 1 of the text file, not one per line.
In addition, we have lacked copy another part of the total code where proc is used to remove the spaces.
Code:
 set nicknames [removespaces $nicknames]

Code:
proc removespaces {arg} {
  regsub {^\s+} $arg "" arg
  return $arg
}


SpiKe^^,there is a part that I could not solve.
See if you help me, the solution should be easy, but I could not fix the code.
Example:
Code:
$nicknames = mario pedro luis {susan} {[polo]}

Code:

proc del_in_fd {nick uhost hand chan text} {
##variable who added nick to delete##
set who [lindex $text 0]
##nicknames variable  stored values ​​I said above.##
nicknames [getinfo]
##Compare who (nick to delete) with the value of the variable nicknames above.##
  if {[lsearch -exact [string tolower $nicknames] [string tolower $who]] == -1} {
   putmsg $canal_admin "$who not found in the database!"
   return 0
  } else {
##variable i added index nick to delete##
 set i [lsearch -exact [string tolower $nicknames] [string tolower $who]]
##Delete index containing the nick in the string.###
set nicknames [lreplace $nicknames $i $i]
###for debuggin purpose###
putmsg $canal_admin "value nicknames: $nicknames"
#####HERE PROBLEM######

Quote:
<oper> !del pedro
<bot> value nicknames: mario luis susan {[polo]}

Eliminate pedro, but it takes away the brace to susan.
Where I have to put the split when you delete a nick not remove braces susan? Embarassed
Or
Is there another way to remove nicks the string without susan lose your braces?
_________________
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 Smile
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Apr 29, 2015 10:23 am    Post subject: Reply with quote

juanamores wrote:

...
The code does not work that way friend.
This code stores all nicks in line 1 of the text file, not one per line.


This is made much more difficult, because you are not giving us everything that you are working with.

Quote:

In addition, we have lacked copy another part of the total code ...


... sigh...


Quote:

where proc is used to remove the spaces.
Code:
 set nicknames [removespaces $nicknames]

Code:
proc removespaces {arg} {
  regsub {^\s+} $arg "" arg
  return $arg
}



And who knows why....

I believe that with a re-write of your method, not only would it be easier to get the correct result, it might even be easier to see it happen.

I think I will just bow out and wait. Smile
_________________
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
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Wed Apr 29, 2015 1:57 pm    Post subject: Reply with quote

willyw wrote:

This is made much more difficult, because you are not giving us everything that you are working with.


Dear friend, of course I have given the full code on several occasions, TCL is the same we have been studying in other threads.. Very Happy

I did not put full at this time, since the code is very complex, and do not want to confuse them when applying concrete help with a small part of it.

What I will share them, my doubts are small pieces of code that achievement not fix.
Anyway I have adapted the original TCL to my needs, so it is not identical.

I've shared part of getinfo proc, you were curious as to how it worked the same, but that part and have dominated the list to add or nicks.

If you want to use only the getinfo for the purpose of achieving the same results that I managed process, you have to create a text file and put the first line of the same, all nicks separated by a space.
eg:
LINE 1 of your txt file look like this:
Code:

pedro juan {FoSFaTiTo} maria susan

As SpiKe^^ said earlier, the result stored in a variable is a string separated by spaces.

Anyway when I get finished all the code I'll share with you completely. Very Happy

I've solved the processes when added as the nicks are listed, so that they are stored in text format without losing any characters (eg containing braces).
That I succeeded, with the help of SpiKe^^ who advised me to use the split command.

The only part I have left unfixed is the procedure where a nick from the list is deleted, prompting my new consulting SpiKe^^.
[quote="juanamores"]
SpiKe^^,there is a part that I could not solve.
See if you help me, the solution should be easy, but I could not fix the code.
Example:
Code:

$nicknames = mario pedro luis {susan} {[polo]}   


Code:

proc del_in_fd {nick uhost hand chan text} {
##variable who added nick to delete##
set who [lindex $text 0]
##nicknames variable  stored values ​​I said above.##
nicknames [getinfo]
##Compare who (nick to delete) with the value of the variable nicknames above.##
  if {[lsearch -exact [string tolower $nicknames] [string tolower $who]] == -1} {
   putmsg $canal_admin "$who not found in the database!"
   return 0
  } else {
##variable i added index nick to delete##
 set i [lsearch -exact [string tolower $nicknames] [string tolower $who]]
##Delete index containing the nick in the string.###
set nicknames [lreplace $nicknames $i $i]
###for debuggin purpose###
putmsg $canal_admin "value nicknames: $nicknames"
#####HERE PROBLEM######

Quote:

<oper> !del pedro
<bot> value nicknames: mario luis susan {[polo]}

Eliminate pedro, but it takes away the brace to susan.
Where I have to put the split when you delete a nick not remove braces susan? Embarassed
Or
Is there another way to remove nicks the string without susan lose your braces?

_________________
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 Smile
Back to top
View user's profile Send private message
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Wed Apr 29, 2015 4:38 pm    Post subject: Reply with quote

[quote="juanamores"]
willyw wrote:

This is made much more difficult, because you are not giving us everything that you are working with.


Dear friend, of course I have given the full code on several occasions, TCL is the same we have been studying in other threads.. Very Happy

I did not put full at this time, since the code is very complex, and do not want to confuse them when applying concrete help with a small part of it.

What I will share them, my doubts are small pieces of code that achievement not fix.
Anyway I have adapted the original TCL to my needs, so it is not identical.

I've shared part of getinfo proc, you were curious as to how it worked the same, but that part and have dominated the list to add or nicks.

If you want to use only the getinfo for the purpose of achieving the same results that I managed process, you have to create a text file and put the first line of the same, all nicks separated by a space.
eg:
LINE 1 of your txt file look like this:
Code:

pedro juan {FoSFaTiTo} maria susan

As SpiKe^^ said earlier, the result stored in a variable is a string separated by spaces.

Anyway when I get finished all the code I'll share with you completely. Very Happy

I've solved the processes when added as the nicks are listed, so that they are stored in text format without losing any characters (eg containing braces).
That I succeeded, with the help of SpiKe^^ who advised me to use the split command.

The only part I have left unfixed is the procedure where a nick from the list is deleted, prompting my new consulting SpiKe^^.
juanamores wrote:

SpiKe^^,there is a part that I could not solve.
See if you help me, the solution should be easy, but I could not fix the code.
Example:
Code:

$nicknames = mario pedro luis {susan} {[polo]}   


Code:

proc del_in_fd {nick uhost hand chan text} {
##variable who added nick to delete##
set who [lindex $text 0]
##nicknames variable  stored values ​​I said above.##
nicknames [getinfo]
##Compare who (nick to delete) with the value of the variable nicknames above.##
  if {[lsearch -exact [string tolower $nicknames] [string tolower $who]] == -1} {
   putmsg $canal_admin "$who not found in the database!"
   return 0
  } else {
##variable i added index nick to delete##
 set i [lsearch -exact [string tolower $nicknames] [string tolower $who]]
##Delete index containing the nick in the string.###
set nicknames [lreplace $nicknames $i $i]
###for debuggin purpose###
putmsg $canal_admin "value nicknames: $nicknames"
#####HERE PROBLEM######

Quote:

<oper> !del pedro
<bot> value nicknames: mario luis susan {[polo]}

Eliminate pedro, but it takes away the brace to susan.
Where I have to put the split when you delete a nick not remove braces susan? Embarassed
Or
Is there another way to remove nicks the string without susan lose your braces?


So we will wait the kind assistance of SpiKe^^ for the purpose of completing the code. Smile
_________________
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 Smile
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Wed Apr 29, 2015 7:18 pm    Post subject: Reply with quote

Maybe....
Code:

proc del_in_fd {nick uhost hand chan text} {

  ##variable who added nick to delete (dont use list commands on strings!)##
  set who [lindex [split $text] 0]
  ##nicknames variable  stored values ​​I said above & split to a list.##
  set nicknames [split [getinfo]]

  ##Compare who (nick to delete) with the value of the variable nicknames above.##
  set i [lsearch -exact -nocase $nicknames $who]

  if {$i == -1} {

    putmsg $canal_admin "$who not found in the database!"
    return 0
  } else {

    ##Delete index containing the nick in the list & join list to string.###
    set nicknames [join [lreplace $nicknames $i $i]]

   

    ###for debuggin purpose###
    putmsg $canal_admin "value nicknames: $nicknames"
    #####HERE PROBLEM######

  }
}


_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
juanamores
Master


Joined: 15 Mar 2015
Posts: 317

PostPosted: Wed Apr 29, 2015 7:53 pm    Post subject: Reply with quote

Thanks SpiKe^^ worked perfectly. Very Happy

If you want to share the full code with my modifications notified me that I'll post here (is in Spanish). Very Happy
_________________
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 Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber