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.

Channel locker (prob with string match/lsearch)

Old posts that have not been replied to for several years.
Locked
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Channel locker (prob with string match/lsearch)

Post by awyeah »

Hi,

I made this following script, it works in coherance with another script kicking clones and locking the channel, this is the channel locking procedure.

Code: Select all

set clone_mlock "mR"
set clone_mlockswitch "1"
set clone_noticeswitch "1"
set clone_notice "Testing channel locking script"
set clone_mlocktime "3"

bind pub m !checklock check:lock

proc check:lock {nick uhost hand chan text} {
 global botnick clone_mlock clone_mlockswitch clone_noticeswitch clone_notice clone_mlocktime clone_mlocked
  set checkmode [split [string trim [lindex [split [getchanmode $chan]] 0] "+"] ""]; set allmodes [split $clone_mlock ""]; putlog "Allmodes = $allmodes"
  if {($clone_mlocktime == "") || ($clone_mlocktime == 0) || ($clone_mlocktime < 1)} { set $clone_mlocktime 10 }
  if {(![info exists clone_mlocked($chan)]) && ($clone_mlockswitch == 1) && ($allmodes != "")} {; set newmodes [list]
   foreach modelock $allmodes { if {(![string match *$modelock* $checkmode])} { lappend modelock $newmodes } }; putlog "New modes = $newmodes"
   putquick "MODE $chan +[string trim $newmodes]" -next; set clone_mlocked([join [split $chan]]) 1; putlog "Locked channel to +[string trim $newmodes]"
   if {([info exists clone_mlocked($chan)]) && ($clone_noticeswitch == 1) && ($clone_notice != "")} {
   putquick "NOTICE $chan :$clone_notice" -next; putlog "Notice = $clone_notice" } }
   utimer $clone_mlocktime [list remove:flood:mlock $chan]
   putlog "Removing lock in $clone_mlocktime secs"
}

proc remove:flood:mlock {chan} {
 global botnick clone_mlock clone_mlockswitch clone_mlocked
  set checknewmode [split [string trim [lindex [split [getchanmode $chan]] 0] "+"] ""]; set newmodes [list]; set allmodes [split $clone_mlock ""]; putlog "New allmodes = $allmodes"
  foreach modelock $allmodes {; if {([string match *$modelock* $checknewmode])} { lappend modelock $newmodes } }; putlog "New unlock modes = $newmodes"
   if {([info exists clone_mlocked($chan)]) && ($clone_mlockswitch == 1) && ($allmodes != "")} {
   putquick "MODE $chan -[string trim $newmodes]" -next
   utimer [expr $clone_mlocktime + 5] "unset clone_mlocked($chan)"
   putlog "Removed mlock -[string trim $newmodes]"
   }
}
Here is the output of the putlogs I have put in
<bot> Allmodes = m R
<bot> New modes =
<bot> Locked channel to +
<bot> Notice = Testing channel locking script
<bot> Removing lock in 3 secs
<bot> New modes = m R
<bot> New unlock modes =
<bot> Removed mlock -
I get the value "", null for $newmodes when I try to string match, foreach modelock from the list $allmodes. Don't know what is wrong. I have tried lsearch too.

Can anyone please help me? I have made this script a little complicated so that, the bot doesn't do a mode flood and also it doesn't lock the modes which are already placed in the channel if they are given in its defined settings!

I get a null value for $newmodes, if I can get it with a value from the check:mlock procedure, then everything would be okay and would work! :mrgreen:
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

set lock_modes "mr"

set tmp [split [string trim [lindex [split [getchanmode $chan]] 0] "+"] ""]
  if {[regexp -all [join [split $lock_modes ""] "|"] $tmp] == [string length $lock_modes]} {
    return
  }
# continue locking the channel
taken from njf.tcl version 0.5 ..

edit.. actualy, on this one the thanks goes to teemu from #eggdrop @ undernet for this solution. :mrgreen: sorry.. :roll:
Last edited by caesar on Mon Sep 20, 2004 4:31 pm, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

caesar wrote:

Code: Select all

set lock_modes "mr"

set tmp [split [string trim [lindex [split [getchanmode $chan]] 0] "+"] ""]
  if {[regexp -all [join [split $lock_modes ""] "|"] $tmp] == [string length $lock_modes]} {
    return
  }
# continue locking the channel
taken from njf.tcl bla bla bla..
Why are you counting the length of the mode locks here? string length?
and why splitting and joining them with an "|"? which would be 'm|r' hmmm, then comparing lengths with a compartor. Weird code, I don't really understand why regexp is being used here. :-?

Something like this
if {([regexp -all "m|r" "t n"] == 2)} { ???? :-? :-?
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

awyeah wrote:

Code: Select all

set newmodes [list]
Do you expect this to yield anything but an empty list?
awyeah wrote:Why are you counting the length of the mode locks here? string length?
The purpose of string length is to see if the number of modes matched by the regexp is == the number of lock modes (if they're all set). Why he chose to split/join instead of enclosing the modes in \[\] in the regexp, I don't know :P
Have you ever read "The Manual"?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Good point user. Noted it. Thanks.

The \[$lock_modes\] is a lot more faster. 113 microseconds per iteration compared with 466 microseconds per iteration. :mrgreen:

@ awyeah
In order to perform an regexp on multiple things like check of a match of foo, moo and bla in a line you should have them foo|moo|bla so that [join [split $lock_modes ""] "|"] was doing it. Got to admit that I think I was sleeping or something cos I haven't noticed it.. pff. :roll: :mrgreen:
Once the game is over, the king and the pawn go back in the same box.
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

user wrote:
awyeah wrote:

Code: Select all

set newmodes [list]
Do you expect this to yield anything but an empty list?
Actually I set this to declare the variable $newmodes as a list, to generate a new list of modes. When the foreach loop runs it would automatically lappend the modes which aren't placed in the channel and are mentioned in the script in as $newmodes, which would then be locked and used for other stuff.

Code: Select all

foreach modelock $allmodes { 
 if {(![string match *$modelock* $checkmode])} { 
 #if {([lsearch -exact $checkmode $modelock] == -1)} { 
  lappend modelock $newmodes
  } 
 }
If we want to declare a variable as a list do we really need the
  • ?
    set allmodes [split $clone_mlock ""] or
    set allmodes [list [split $clone_mlock ""]]

    Secondly, [rand] generates a random number.
    Would [rand 2] generate: 0 or 1 or 2 or just 1.

    Limits for rand 2 are (0 < rand 2 < 2).
    Meaning does it generate the random number with the limits or does it generate the number between the limits?
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Locked