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.

Help with a command code (!day):

Help for those learning Tcl or writing their own scripts.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

In my opinion, the number of spaces/tabs per level is'nt that important, what is however, is using the same fashion all through the script, ie. add one space/tab for each level you descend, as illustrated by rosc.

Also, I'm not sure those regular expressions you're using actually does what you intended, ie:

Code: Select all

if {![regexp "\[^15-99999\]" $target} {
This will match anything starting with the number 1, 5, 6, 7, 8, 9 (such as 1, 10, 19, 91, but not 20). Probably not what you intended.
NML_375
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

nml375 wrote:In my opinion, the number of spaces/tabs per level is'nt that important, what is however, is using the same fashion all through the script, ie. add one space/tab for each level you descend, as illustrated by rosc.

Also, I'm not sure those regular expressions you're using actually does what you intended, ie:

Code: Select all

if {![regexp "\[^15-99999\]" $target} {
This will match anything starting with the number 1, 5, 6, 7, 8, 9 (such as 1, 10, 19, 91, but not 20). Probably not what you intended.
Ok, thanks for the ie, but if this code

Code: Select all

if {![regexp "\[^15-99999\]" $target]} {
doesn`t except the numbers between 1 to 14 ( that ar the numbers that a specifyed user level will use with the !day command ), what should I use to except numbers form 1 to 14 and for the rest of the numbers to give that notice to the user ( in hope that the user will type the correct number based on his access level )
Last edited by Riddler on Thu Jun 28, 2007 2:07 pm, edited 1 time in total.
I am a man of few words, but many riddles
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I would probably use something like this:

Code: Select all

if {![string is -strict integer $target] || $target >= 15 || $target <= 0} {
NML_375
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

nml375 wrote:I would probably use something like this:

Code: Select all

if {![string is -strict integer $target] || $target >= 15 || $target <= 0} {
good idea, but... it didn`t work :?
I`ve used that code, and there is no reaction if the number is higher than 7 ( for user with OP Access) and 14 ( for user with Test OP Access) .... the user didn`t get the warning notice.
I`ve also tested the script with this ( the first pieces of codes):

Code: Select all

if {![regexp "\[^8-99999\]" $target} {

and

Code: Select all

if {![regexp "\[^15-99999\]" $target} {


...still no reaction from the bot ( no notice )
<@OP> !d
-|EGG- SYNTAX: !d <1-7> <nick|*!*@host> [reason]
<@OP> !d 8 *!*@*.test.ro
<@OP> !d 7 *!*@*.test.ro
* |EGG sets mode: +b *!*@*.test.ro
<me> .tcl killchanban #chan *!*@*.test.ro
<@|EGG> OK: 1 - 0.246 ms
* |EGG sets mode: -b *!*@*.test.ro
and the same thing happends for a nother user with a higher access flag to the bot
<@TestOP> !d
-|EGG- SYNTAX: !d <1-14> <nick|*!*@host> [reason]
<@TestOP> !d 15 *!*@*.test.ro
<@TestOP> !d 100 *!*@*.test.ro
<@TestOP> !d 14 *!*@*.test.ro
* |EGG sets mode: +b *!*@*.test.ro
<me> .tcl killchanban #chan *!*@*.test.ro
<@|EGG> OK: 1 - 0.246 ms
* |EGG sets mode: -b *!*@*.test.ro
btw nm375, this piece of code:

Code: Select all

if {![string is -strict integer $target] || $target >= 15 || $target <= 0} {
doesn`t than mean number form 0 to 15 ? :?: :!:
I am a man of few words, but many riddles
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

Later UPDATE:

Code: Select all

set dj(br) "Banned!"
set dj(xb) 1

bind pub n|MASDTO !d s:day

setudef flag djtools

proc s:day {nick uhost hand chan text} {
 global botnick dj
   if {[channel get $chan djtools] && ![isbotnick $nick]} {
   if {[matchattr $hand n|MASDTO $chan] || [string tolower $chan]} {
     set target [lindex [split $text] 0]
        if {![botisop $chan]} {
        puthelp "NOTICE $nick :Error I don't have OP!"
        return 0
        } elseif {[matchattr $hand -|T $chan]} {
          if {$target == ""} {
          puthelp "NOTICE $nick :SYNTAX:\002 !d <1-14> <nick|*!*@host> \[reason\] \002"
          return 0
          }
          } else {
          foreach not $target {
              if {![string is -strict integer $target] || $target >= 15 || $target <= 0} {
              puthelp "NOTICE $nick :Error max allowed 1-14 days for Test OP Access Users"
              return 0
              }
            }
          }
          set options $target
          foreach item $options {
          if {![regexp "\[^0-14\]" $item]} {
            set days $item
            s:day:ban $nick $uhost $hand $chan $text
          return 0
          }
        }
        } elseif {[matchattr $hand -|O $chan]} {
          if {$target == ""} {
          puthelp "NOTICE $nick :SYNTAX:\002 !d <1-7> <nick|*!*@host> \[reason\] \002"
          return 0
          }
          } else {
          foreach not $target {
              if {![string is -strict integer $target] || $target >= 8 || $target <= 0} {
              puthelp "NOTICE $nick :Error max allowed 1-7 days for OP Access Users"
              return 0
              }
            }
          }
          set options $target
          foreach item $options {
          if {![regexp "\[^0-7\]" $item]} {
            set days $item
            s:day:ban $nick $uhost $hand $chan $text
          return 0
          }
        }
    }
}

proc s:day:ban {nick uhost hand chan text} {
 global botnick dj
   if {[channel get $chan djtools] && ![isbotnick $nick]} {
        set type [lindex [split $text] 1]
        set dtype [nick2hand $type]
        set reason [join [lrange [split $text] 3 end]]
          if {$reason == ""} {
          set reason $dj(br)
          }
          if {[string match *!*@* $type]} {
          set dhost $type
          } else {
          set dhost "*!*@[lindex [split [getchanhost $type] @] 2]"
          }
          if {![matchattr $dtype n|MASDTOVU $chan] && ![isop $type $chan] && ![isvoice $type $chan] && ![matchattr $dtype b]} {
            newchanban $chan $dhost days "($hand) $reason" [expr $days * 1440]
            putquick "MODE $chan +b $dhost"
            putquick "KICK $chan $type :($hand) $reason"
            if {$dj(xb) == 1} {
            putquick "PRIVMSG X :ban $chan $dhost 1 100 ($hand) $reason" -next
            }
            newignore $dhost days "($hand) $reason"
          return 0
        }
    }
}
I`ve made some changes and reorder the script and I`m getting this error on dcc-chat:
<|EGG> [01:01] Tcl error [s:day]: can't read "days": no such variable
<me> .set errorInfo
<|EGG> [01:02] #me# set errorInfo
<|EGG> Currently: can't read "days": no such variable
<|EGG> Currently: while executing
<|EGG> Currently: "expr $days * 1440"
<|EGG> Currently: (procedure "s:day:ban" line 16)
<|EGG> Currently: invoked from within
<|EGG> Currently: "s:day:ban $nick $uhost $hand $chan $text"
<|EGG> Currently: (procedure "s:day" line 26)
<|EGG> Currently: invoked from within
<|EGG> Currently: "s:day $_pub1 $_pub2 $_pub3 $_pub4 $_pub5"
How to I make the second proc to recognize a variable form the first proc ?!
In this case, this one :

Code: Select all

proc s:day {nick uhost hand chan text} {
(...)
          set days $item
          s:day:ban $nick $uhost $hand $chan $text
          return 0
(...)
I am a man of few words, but many riddles
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

It's so obviously simple how to do this. Your missing minor logic first and need to look back..
nml375 wrote:if {![string is -strict integer $target] || $target >= 15 || $target <= 0} {
You said, "doesn`t than mean number form 0 to 15 ?" Quite the opposite, it means string not an integer -or- the value is less than or equal to 0 -or- the value is larger than or equal to 15. This is where you would write your standard error message checks to explain to that user what they did wrong, too long, too short, not a number, etc.. it's simple input sanitizing, and in this situation simple is best.

...and about your error, since the bind isn't calling your s:day:ban proc directly and your invoking it within an already bound proc, you can pass it added parameters easily, meaning.. you can just shove them into passing calls.. like below.. just modify your s:day proc like so:

Code: Select all

             # the line below should replace the regexp line presently used
             # if {[string is -strict integer $item] || $item <= 14 || $item >= 1} {
             # if you insist on using that dirty regexp, remove the line above or you will get unbalanced brace error
             if {![regexp "\[^0-14\]" $item]} {
              # the set line below can be removed, and change $days to $item in the s:day:ban call
              set days $item
              s:day:ban $nick $uhost $hand $chan $days $text
              .. rest is here..
then, your s:day:ban proc needs to be changed like this:

Code: Select all

proc s:day:ban {nick uhost hand chan days text} {
.. rest continues the same ... 
It's easier to understand code if your able to understand it's logic as well. You should follow nml375's advice, as your regexp's are not having their intended purpose in your script and are highly exploitable by lower level ops.

and finally, just as a ps.. heh, type .echo off on your partyline so you don't get those #echo# messages after everything.. :wink:
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

ok, sorry for that I was just asking, didn`t know what that string will do.
so, I`ve made the changes like you suggested and now I`m getting this error wen I`m trying to load the script:
<me> .tcl source scripts/lol.tcl
<@|EGG> Error: missing close-brace: possible unbalanced brace in comment - 41.84 ms
and on the dcc-chat:
<me> .set errorInfo
<|EGG> Currently: missing close-brace: possible unbalanced brace in comment
<|EGG> Currently: while executing
<|EGG> Currently: "proc s:day {nick uhost hand chan text} {
<|EGG> Currently: global botnick dj
<|EGG> Currently: if {[channel get $chan djtools] && ![isbotnick $nick]} {
<|EGG> Currently: if {[matchattr $hand n|MASD..."
<|EGG> Currently: (file "scripts/lol.tcl" line 8)
<|EGG> Currently: invoked from within
<|EGG> Currently: "source scripts/lol.tcl"
<|EGG> Currently: ("eval" body line 1)
<|EGG> Currently: invoked from within
<|EGG> Currently: "eval $args"
I am a man of few words, but many riddles
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Riddler wrote:<|EGG> Currently: if {[channel get $chan djtools] && ![isbotnick $nick]} {
The eggdrop is telling you the offending line here, you haven't closed this conditional before closing the procedure. Just change the last part of the s:day proc like this:

Code: Select all

          return 0
          }
        }
    }
    }
}
Indentation done to match position of your double stacked if statements that start the procedure.
Riddler wrote:ok, sorry for that I was just asking, didn`t know what that string will do.
Sorry for what? That the advice I gave you was in a tone that led you to believe your question upset me?...hahah.. It's just that remedial questions (questions easily solved just by reading tcl commands docs) usually get sterner answers than something truly complex. So figured I would chime in to explain that you were incorrect in your interpretation of the logic behind that code nml375 gave you, before I explained your other issues.
Post Reply