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 

lsearch and list
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Craig
Voice


Joined: 22 Feb 2006
Posts: 18

PostPosted: Sat Mar 17, 2007 5:13 pm    Post subject: lsearch and list Reply with quote

How to do lsearch for two or more words? like:

[lsearch -all -inline {1 11 111 22 2 222} 2* 1*]

i want to if find me words with 2* 1* .. so 1 11 111 2 22 222

[lsearch -all -inline {147 158 169 175 121 540} *0 *9]

return => 540 169


------

how to do list?

like i got set $word "word1 2 3"

i want to it be :

word1
2
3
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Mar 17, 2007 5:30 pm    Post subject: Reply with quote

Checking the manpage for lsearch, you'd see it only supports one pattern.
However, it does support various matching-algorithms, including regular expressions ("regexps"). Regular expressions do allow you to make quite complicated patterns, including matching multiple keywords.

Ex:
Code:
lsearch -regexp -all -inline {1 11 111 22 2 222} {^(1|2).*}


As for your second inquery, if you're using a string, I guess you could do something like this:
Code:
join [split $word] "\n"

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Craig
Voice


Joined: 22 Feb 2006
Posts: 18

PostPosted: Sun Mar 18, 2007 2:25 pm    Post subject: Reply with quote

could u "repair" my part of script ?

Code:
   set readbw [open [string trimleft $chan #]_badwords.txt r]
   while { ![eof $readbw] } { 
   putlog "i do something"
   gets $readbw line
   set helpwanted [string range $line 0 [expr [string first # $line]-1]]
   set message [string range $line [expr [string first # $line]+1] [expr [string first ź $line]-1]]
   set typeof  [string range $line [expr [string first ź $line]+1] end]
if { ([string match -nocase "* $helpwanted *" $input] == 1 && $helpwanted != "") || ([string match -nocase "$helpwanted" $input] == 1 && $helpwanted != "") } {
      if { $typeof == 3 } {
         putquick "PRivmsg $chan : cos znalazlem! :D"
         set Excepts(File) [open excepts_[string trimleft $chan #]_badwords.txt r]
         while { ![eof $Excepts(File)] } { 
            gets $Excepts(File) line
            set Excepts(list) [string range $line 0 [expr [string first # $line]-1]]
            close $Excepts(File)
            ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            set count 0
            ## At Least one Badword  to chek
            set bw "http:// www. ftp:/"
            set bw *[join [split $bw] "*\n*"]*
            set bwfound [lsearch -regexp -all -inline $arg {(http://|www.|ftp://)}]
            putquick "privmsg $chan : $bwfound"
            foreach bwb $bw {
            while {$count < [llength $bwfound]} {
               if { [string match -nocase "$bwb" [lindex $bwfound $count]] == 1 } {
                  putquick "PRIVMSG $chan : Wypierdalam cie bo podałeś badword."
                  #putquick "PRIVMSG $chan : $Excepts(list)"
                  if { [string match -nocase "$Excepts(list)" [lindex $bwfound $count]] == 1 } {
                     putquick "PRIVMSG $chan : Ale jest wyjatek to mash spokój bo spokoje. :p"
                  } else {
                     putquick "PRIVMSG $chan : Wyjątku tez brak to wypad."
                     return 0
                  }
               }
               incr count 1
            }
            }         
      }
         }


The problem is:
script work only when i type http:// ( it is added in badword list file ), after wchich is all ok.

When i typed "www." (it is added to badword list too and it is typeof 3 too) it doesn't do anything.

When i typed lolz www. it doesnt do anything only error -> 10.:141910·142210·141210:. 03«dghnws03» [19:22] Tcl error [badword:pubm:check]: can not find channel named "file33"

I want to it work for www. and ftp:/ and maybe others too not only for http://

this part is for check for except in a badword typed it working when i tested it with http:// but when i typed http://lol (lol is except added to except file) it has error : 10.:141910·142410·141210:. 03«dghnws03» [19:24] Tcl error [badword:pubm:check]: can not find channel named "file37"
The part is :
Code:

               if { [string match -nocase "$bwb" [lindex $bwfound $count]] == 1 } {
                  putquick "PRIVMSG $chan : Wypierdalam cie bo podałeś badword."
                  #putquick "PRIVMSG $chan : $Excepts(list)"
                  if { [string match -nocase "$Excepts(list)" [lindex $bwfound $count]] == 1 } {
                     putquick "PRIVMSG $chan : Ale jest wyjatek to mash spokój bo spokoje. :p"
                  } else {
                     putquick "PRIVMSG $chan : Wyjątku tez brak to wypad."
                     return 0
                  }
               }

but it was working.

10.:141910·142410·145310:. 03«~Igor03» http://
10.:141910·142410·145410:. 03«@dghnws03»  cos znalazlem! Very Happy
10.:141910·142410·145410:. 03«@dghnws03»  http://
10.:141910·142410·145410:. 03«@dghnws03»  Wypierdalam cie bo podałeś badword.
10.:141910·142410·145410:. 03«@dghnws03»  Wyjątku tez brak to wypad.
10.:141910·142510·140010:. 03«~Igor03» http://lol
10.:141910·142510·140110:. 03«@dghnws03»  cos znalazlem! Very Happy
10.:141910·142510·140110:. 03«@dghnws03»  http://lol
10.:141910·142510·140110:. 03«@dghnws03»  Wypierdalam cie bo podałeś badword.
10.:141910·142510·140110:. 03«@dghnws03»  Ale jest wyjatek to mash spokój bo spokoje. :p
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Mar 18, 2007 6:32 pm    Post subject: Reply with quote

First off, why on earth do you use $bw as the list for foreach? You've joined back into a string!
As for your regular expression, "." is a special atom matching any single character.
Next, your "no such channel" error...
It's from your exceptions-file, or rather your incorrect reading of it:
Code:
         while { ![eof $Excepts(File)] } {
            gets $Excepts(File) line
            set Excepts(list) [string range $line 0 [expr [string first # $line]-1]]
            close $Excepts(File)

Looking at this piece of the code makes it obvious that you open the file, starts a while-loop checking for an eof-conditon on the opened file. You then read it once, and directly afterwards, you close it... so when the body fo the while-loop reaches the end and the conditional of the while-loop is tested, $Excepts(File) has already been closed, and thus the file-descriptor (or channel) is no longer valid...

Finally, I'm curious as to the source for $arg, which you use in your lsearch.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Craig
Voice


Joined: 22 Feb 2006
Posts: 18

PostPosted: Mon Mar 19, 2007 8:57 am    Post subject: Reply with quote

Code:
            while {$count < [llength $bwfound]} {
               if { [string match -nocase "$bw" [lindex $bwfound $count]] == 1 } {
                  putquick "PRIVMSG $chan : Wypierdalam cie bo podałeś badword."
                  #putquick "PRIVMSG $chan : $Excepts(list)"
                  if { [string match -nocase "$Excepts(list)" [lindex $bwfound $count]] == 1 } {
                     putquick "PRIVMSG $chan : Ale jest wyjatek to mash spokój bo spokoje. :p"
                  } else {
                     putquick "PRIVMSG $chan : Wyjątku tez brak to wypad."
                     return 0
                  }
               }
               incr count 1
            }


now it dont want work anyhow ..

it is possible to change that . to ? ?
coz i really need chars like . to be normal -,-

--
lsearch is working with $ARG :p
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Mar 19, 2007 10:33 am    Post subject: Reply with quote

I fail to see whatever you've changed in the posted piece of code from the original post.

In order to use . with regular expressions you'll have to escape them properly. I'd strongly suggest you study the basics on regular expressions, as these can quite quickly become very complex and not behave as intended.

Yes, I know you use lsearch to scan through $arg. That was not my question. The question was where the value of arg is defined/set.

Oh, btw, just saying "it does'nt work" and not providing any more details really does'nt help...
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Craig
Voice


Joined: 22 Feb 2006
Posts: 18

PostPosted: Mon Mar 19, 2007 11:54 am    Post subject: Reply with quote

Only this part does not work which i paste you higher . And as i think, script dont even read this part. If i use bwb $bw and then when i change $bw on $bwb in a place "if string match -nocase" this $bwb works. Problem with this comunicate - ubm:check]: can not find channel named "file" - gone after i delete - close excepts-file -.

However i still dont know what i have to do with this "." as u wrote to me. I think it should be recognize as a simple sign, and i cant use / before "." because i have to write !badword add *www* before. then in my file it should to be wrote as www. I dont have any problems with this command but as u told me ..laters eggdrop will read this as any sign, it should to exist something like "simple full stop" (".")
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Mar 19, 2007 12:41 pm    Post subject: Reply with quote

You'll have to escape the . if you want it to match period (.) only... There's no other way of doing it with regular expressions.
As for bw and bwb, in the last code example including that part that you've posted, bw is a string, and as such is unsuitable to be used with foreach (as I stated in a previous post aswell).

If you believe the part of the code you pasted isn't even executed, why do you think the error is there in the first place?
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Craig
Voice


Joined: 22 Feb 2006
Posts: 18

PostPosted: Mon Mar 19, 2007 1:41 pm    Post subject: Reply with quote

There is no any errors,

i said http:// wchich is added to $bw and it didnt do anything,

it should say at least putquick "PRIVMSG $chan : Wypierdalam cie bo podałeś badword."
Back to top
View user's profile Send private message
Craig
Voice


Joined: 22 Feb 2006
Posts: 18

PostPosted: Tue Mar 20, 2007 2:07 pm    Post subject: Reply with quote

$bw dont want work as list in "if string match - nocase" always returnining 0 -.-
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Mar 20, 2007 2:13 pm    Post subject: Reply with quote

So you've removed the foreach loop then?
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Craig
Voice


Joined: 22 Feb 2006
Posts: 18

PostPosted: Wed Mar 21, 2007 7:33 am    Post subject: Reply with quote

i said you i did - if not sorry then

but it also dont working with foreach .. just maybe with first badword "http://" it dont see "www." and others when foreach
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed Mar 21, 2007 12:50 pm    Post subject: Reply with quote

So, if you don't use foreach anymore, why should bw match "http://", assuming it's still set according to this:
Code:
set bw "http:// www. ftp:/"
set bw *[join [split $bw] "*\n*"]*

Effectively setting bw to this:
Quote:
*http://*
*www.*
*ftp:/*

I doubt any of the list-items within $bwfound would match that pattern, however I would need further information on $arg to effectively say wether it would actually have a chance of matching anything...
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Craig
Voice


Joined: 22 Feb 2006
Posts: 18

PostPosted: Thu Mar 22, 2007 12:51 pm    Post subject: Reply with quote

Code:
bind pubm - "* *" badword:pubm:check
proc badword:pubm:check {nick uhost handle chan arg} {
   global triggerchar
   ## if { [isop $nick $chan] || [ishalfop $nick $chan] || [isvoice $nick $chan] } {
   ##   putlog "used isop/hop/vop"
   ##   return 0
   ## }
   if {[string match "*@..." $uhost]} {
       putlog "is hosted"
       return 0
   }
   if { ![file exists [string trimleft $chan #]_badwords.txt] } {
      return 0
   }
   set input [swear:filter2 $arg]
   set readbw [open [string trimleft $chan #]_badwords.txt r]
   while { ![eof $readbw] } { 
   putlog "i do something"
   gets $readbw line
   set helpwanted [string range $line 0 [expr [string first # $line]-1]]
   set message [string range $line [expr [string first # $line]+1] [expr [string first ź $line]-1]]
   set typeof  [string range $line [expr [string first ź $line]+1] end]
if { ([string match -nocase "* $helpwanted *" $input] == 1 && $helpwanted != "") || ([string match -nocase "$helpwanted" $input] == 1 && $helpwanted != "") } {
                if { $typeof == 4 } {
                        BadWordKick $nick $uhost $chan $arg $helpwanted $message $typeof $input
                        return 0
                }
      if { $typeof == 3 } {
         putquick "PRivmsg $chan : cos znalazlem! :D"
         set Excepts(File) [open excepts_[string trimleft $chan #]_badwords.txt r]
         while { ![eof $Excepts(File)] } { 
            gets $Excepts(File) line
            set Excepts(list) [string range $line 0 [expr [string first # $line]-1]]
            ## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            set count 0
            ## At Least one Badword  to chek
            set bw "http:// www. ftp:/"
            set bw *[join [split $bw] "*\n*"]*
            set bwfound [lsearch -regexp -all -inline $arg {(http://|www.|ftp://)}]
            putquick "privmsg $chan : $bwfound"
            putquick "privmsg $chan : $bw"
            putquick "privmsg $chan : $Excepts(list)"
            

            while {$count < [llength $bwfound]} {
               if { [string match -nocase "$bw" [lindex $bwfound $count]] == 1 } {
                  putquick "PRIVMSG $chan : Wypierdalam cie bo podałeś badword."
                  #putquick "PRIVMSG $chan : $Excepts(list)"
                  if { [string match -nocase "$Excepts(list)" [lindex $bwfound $count]] == 1 } {
                     putquick "PRIVMSG $chan : Ale jest wyjatek to mash spokój bo spokoje. :p"
                  } else {
                     putquick "PRIVMSG $chan : Wyjątku tez brak to wypad."
                     return 0
                  }
               }
               incr count 1
            }
      
      }
         }


etc., so $arg return what someone said ... ;p of course i tried to say http:// and ftp://
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Thu Mar 22, 2007 1:23 pm    Post subject: Reply with quote

First off then, you cannot use lsearch on $arg, as it is not a list...
Secondly, since arg is provided from the pubm-trigger, it cannot contain a newline; hence the pattern you store in bw cannot match any possible result from your lsearch (as should be obvious from my last post)
That is, since arg never could hold any newlines, and you type http://, at best, the lsearch would result in bwfound being set to:
Quote:
http://

Quite obviously, bw cannot match this pattern:
Quote:
*http://*
*www.*
*ftp:/*

_________________
NML_375, idling at #eggdrop@IrcNET
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
Goto page 1, 2  Next
Page 1 of 2

 
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