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.
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Help with a command code (!day):

Post by Riddler »

Hello guys... I need some help again ...
I`m trying to make a little code that will work with a pub command...something like this:
-----
For Channel Managers:

<@Manager1> !day
-|Eggdrop- SYNTAX: !day <??> <nick|*!*@host> [reason]

-----
For :

<@Admin1> !day
-|Eggdrop- SYNTAX: !day <1-100> <nick|*!*@host> [reason]

-----
For Channel Senior OPs:

<@SOp1> !day
-|Eggdrop- SYNTAX: !day <1-60> <nick|*!*@host> [reason]

-----

......and so on

-----
For Channel OPs:

<@Op1> !day
-|Eggdrop- SYNTAX: !day <1-7> <nick|*!*@host> [reason]

-----
and here is the code :

Code: Select all

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

bind pub n|MASDTO !day s:ban

setudef flag djtools

proc s:ban {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!"
        } elseif {[matchattr $hand n|- $chan]} {
        if {$target == ""} {
        puthelp "NOTICE $nick :SYNTAX:\002 !day <??> <nick|*!*@host> \[reason\] \002"
        return 0
        }
        set options $target
          foreach item $options {
          if {![regexp "\[^0-99999\]" $item]} {
          set days $item
          }
          s:day:ban
          return 0
         }
       } elseif {![matchattr $hand -|O $chan]} {
        if {$target == ""} {
        puthelp "NOTICE $nick :SYNTAX:\002 !day <1-7> <nick|*!*@host> \[reason\] \002"
        return 0
        } else {
        foreach not $target {
          if {![regexp "\[^8-99999\]" $target} {
          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
        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" [expr $days * 1440]
      return 0
      }
   }
}

Well the errors are :

1.) Manager1
<Manager1> !day
-|Eggdrop- SYNTAX: !day <??> <nick|*!*@host> [reason]
<Manager1> !day 9999 *!*@test.ro lol
NO reaction :x ..... and I`m getting this error in dcc-chat
<|Eggdrop> [06:06] Tcl error [s:ban]: syntax error in expression "![matchattr $dtype n|MASDTOVU $chan] && ![isop $type $chan] ...": extra tokens at end of expression
...and so on for every user who has specific flags and trys to use this command...

any suggestions in how to make this script work ?1 :shock: :?
Last edited by Riddler on Mon Jun 18, 2007 6:45 am, edited 1 time in total.
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 »

nobody has any suggestion/ideas in how to make this script work... :shock: :?: :!:
I only need to make it work for 2 diferent flag users...the rest of the script I`ll do it myself. :roll:
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 »

... :?: :!:
I am a man of few words, but many riddles
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You can follow a patter like

Code: Select all

if {<is senior op>} {
 # give senior op privileges
} elseif {<is bla op>} {
 # give bla op privileges
} ...etc
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

Sir_Fz wrote:You can follow a patter like

Code: Select all

if {<is senior op>} {
 # give senior op privileges
} elseif {<is bla op>} {
 # give bla op privileges
} ...etc
never heard of this type of command :shock: :roll: :arrow: ...let`s see :)
I am a man of few words, but many riddles
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

It's not a command, that was just an example (duh). In your case it's a [matchattr] check. For example

Code: Select all

if {[matchattr $hand |+S $chan]} {
This checks if $hand has +S (senior ops?) on $chan... and so on.
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

ok, done the modifications, and here is the script..

Code: Select all

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

bind pub n|MASDTO !day s:ban

setudef flag djtools

proc s:ban {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!"
        } elseif {[matchattr $hand n|-]} {
        if {$target == ""} {
        puthelp "NOTICE $nick :SYNTAX:\002 .d <??> <nick|*!*@host> \[reason\] \002"
        return 0
        }
        set options $target
          foreach item $options {
          if {![regexp "\[^0-99999\]" $item]} {
          set days $item
          }
          s:day:ban $nick $uhost $hand $chan $text
          return 0
         }
       } elseif {[matchattr $hand -|+M $chan]} {
         if {$target == ""} {
        puthelp "NOTICE $nick :SYNTAX:\002 .d <??> <nick|*!*@host> \[reason\] \002"
        return 0
        }
        set options $target
          foreach item $options {
          if {![regexp "\[^0-99999\]" $item]} {
          set days $item
          }
          s:day:ban $nick $uhost $hand $chan $text
          return 0
         }
       } elseif {[matchattr $hand -|+A $chan]} {
         if {$target == ""} {
         puthelp "NOTICE $nick :SYNTAX:\002 .d <1-100> <nick|*!*@host> \[reason\] \002"
         return 0
         } else {
         foreach not $target {
           if {![regexp "\[^101-99999\]" $target} {
           puthelp "NOTICE $nick :Error max allowed 1-100 days for Administrator Access Users"
           return 0
           }
         set options $target
           foreach item $options {
           if {![regexp "\[^0-100\]" $item]} {
           set days $item
           }
         s:day:ban $nick $uhost $hand $chan $text
         return 0
         }
       } elseif {[matchattr $hand -|+S $chan]} {
         if {$target == ""} {
         puthelp "NOTICE $nick :SYNTAX:\002 .d <1-60> <nick|*!*@host> \[reason\] \002"
         return 0
         } else {
         foreach not $target {
           if {![regexp "\[^61-99999\]" $target} {
           puthelp "NOTICE $nick :Error max allowed 1-60 days for Senior OP Access Users"
           return 0
           }
         set options $target
           foreach item $options {
           if {![regexp "\[^0-60\]" $item]} {
           set days $item
           }
         s:day:ban $nick $uhost $hand $chan $text
         return 0
         }
       } elseif {[matchattr $hand -|+D $chan]} {
         if {$target == ""} {
         puthelp "NOTICE $nick :SYNTAX:\002 .d <1-30> <nick|*!*@host> \[reason\] \002"
         return 0
         } else {
         foreach not $target {
           if {![regexp "\[^31-99999\]" $target} {
           puthelp "NOTICE $nick :Error max allowed 1-30 days for DJ Access Users"
           return 0
           }
         set options $target
           foreach item $options {
           if {![regexp "\[^0-30\]" $item]} {
           set days $item
           }
         s:day:ban $nick $uhost $hand $chan $text
         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 {![regexp "\[^15-99999\]" $target} {
           puthelp "NOTICE $nick :Error max allowed 1-14 days for Test DJ 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 {![regexp "\[^8-99999\]" $target} {
          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" [expr $days * 1440]
      return 0
      }
   }
}
..and I still get errors like this :
(03:48:13) <me> .load test.tcl
(03:48:13) <|EGG> [02:30] script: test.tcl -- loaded without error.
(03:48:17) <|EGG> [02:31] Tcl error [s:ban]: wrong # args: should be "foreach varList list ?varList list ...? command"
I can`t understand why it`s giving me the error for the "foreach" command...because till now, that wasen`t the problem... :shock:
I am a man of few words, but many riddles
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

.set errorInfo?
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

Sir_Fz wrote:.set errorInfo?
:?: :!:

do you mean if I use this script ?!

Code: Select all

# .load scriptname.tcl
bind dcc n|- load script:load
proc script:load { handle idx text } {
   if { [catch { uplevel #0 [list source scripts/$text] } error] } {
      putlog "0,4Error while loading $text -- Errormsg: $error"
      putlog "script: $text -- ::errorInfo: $::errorInfo"
      return
   }
   putlog "script: $text -- loaded without errors."
   return
}
?
I am a man of few words, but many riddles
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Try reading eggdrop.conf. Sir_Fz said to use '.set errorInfo' not run another script.
# Comment these two lines if you wish to enable the .tcl and .set commands.
# If you select your owners wisely, you should be okay enabling these.
unbind dcc n tcl *dcc:tcl
unbind dcc n set *dcc:set
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

ok, removed the "unbind`s".. now I`m getting this error..

Code: Select all

(01:57:38) <me> .set errorInfo
(01:57:38) <|EGG> [00:39] #me# set errorInfo
(01:57:38) <|EGG> Currently: wrong # args: should be "foreach varList list ?varList list ...? command"
(01:57:38) <|EGG> Currently:     while compiling
(01:57:38) <|EGG> Currently: "foreach not $target {
(01:57:38) <|EGG> Currently:            if {![regexp "\[^101-99999\]" $target} {
(01:57:38) <|EGG> Currently:            puthelp "NOTICE $nick :Error max allowed 1-100 days for Administr..."
(01:57:38) <|EGG> Currently:     ("if" else script line 2)
(01:57:38) <|EGG> Currently:     while compiling
(01:57:38) <|EGG> Currently: "if {$target == ""} {
(01:57:38) <|EGG> Currently:          puthelp "NOTICE $nick :SYNTAX:\002 .d <1-100> <nick|*!*@host> \[reason\] \002"
(01:57:38) <|EGG> Currently:          return 0
(01:57:38) <|EGG> Currently:          } else {
(01:57:38) <|EGG> Currently:      ..."
(01:57:38) <|EGG> Currently:     ("if" then script line 2)
(01:57:38) <|EGG> Currently:     while compiling
(01:57:38) <|EGG> Currently: "if {![botisop $chan]} {
(01:57:38) <|EGG> Currently:         puthelp "NOTICE $nick :Error I don't have OP!"
(01:57:38) <|EGG> Currently:         } elseif {[matchattr $hand n|-]} {
(01:57:38) <|EGG> Currently:         if {$target == ""} {..."
(01:57:38) <|EGG> Currently:     ("if" then script line 3)
(01:57:38) <|EGG> Currently:     while compiling
(01:57:38) <|EGG> Currently: "if {[matchattr $hand n|MASDTO $chan] || [string tolower $chan]} {
(01:57:38) <|EGG> Currently:      set target [lindex [split $text] 0]
(01:57:38) <|EGG> Currently:         if {![botisop $chan]} {
(01:57:38) <|EGG> Currently:         put..."
(01:57:38) <|EGG> Currently:     ("if" then script line 2)
(01:57:38) <|EGG> Currently:     while compiling
(01:57:38) <|EGG> Currently: "if {[channel get $chan djtools] && ![isbotnick $nick]} {
(01:57:38) <|EGG> Currently:    if {[matchattr $hand n|MASDTO $chan] || [string tolower $chan]} {
(01:57:38) <|EGG> Currently:      set target [lindex ..."
(01:57:38) <|EGG> Currently:     (compiling body of proc "s:ban", line 3)
(01:57:38) <|EGG> Currently:     invoked from within
(01:57:38) <|EGG> Currently: "s:ban $_pub1 $_pub2 $_pub3 $_pub4 $_pub5"
(01:58:25) <|EGG> [00:40] @#¹¾ (+stn) : [m/8 o/8 h/0 v/0 n/0 b/0 e/- I/-]
Suggestions ?! :roll:
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 »

You've got a missing } after that foreach-loop, you only closed the if-conditional inside and not the foreach-loop itself.

It would also seem this is the case on several other locations.
NML_375
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

UPDATE:

I`ve closed the missing " } " form the foreach-loop and simplifyed the script for only 1 access flags... to make it a little easy for the script to work...

so here is the code ( simplifyed ):

Code: Select all

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

bind pub n|MASDTO !day s:ban

setudef flag djtools

proc s:ban {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 {![regexp "\[^15-99999\]" $target} {
              puthelp "NOTICE $nick :Error max allowed 1-14 days for Test DJ Access Users"
              return 0
              }
            }
          }
          set options $target
             foreach item $options {
             if {![regexp "\[^0-14\]" $item]} {
             set days $item
             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
            }
        }
      }
    }
  }
}
and I`m still getting this error on dcc ..
<|EGG> [01:35] Tcl error [s:ban]: missing close-bracket
and on the .set errorInfo I get this
<me> .set errorInfo
<|EGG> [01:35] #me# set errorInfo
<|EGG> Currently: missing close-bracket
<|EGG> Currently: ("if" test expression)
<|EGG> Currently: while compiling
<|EGG> Currently: "if {![regexp "\[^15-99999\]" $target} {
<|EGG> Currently: puthelp "NOTICE $nick :Error max allowed 1-14 days for Test DJ Access Users"
<|EGG> Currently: retur..."
<|EGG> Currently: ("foreach" body line 2)
<|EGG> Currently: while compiling
<|EGG> Currently: "foreach not $target {
<|EGG> Currently: if {![regexp "\[^15-99999\]" $target} {
<|EGG> Currently: puthelp "NOTICE $nick :Error max allowed 1-14 days for Test ..."
<|EGG> Currently: ("if" else script line 2)
<|EGG> Currently: while compiling
<|EGG> Currently: "if {![botisop $chan]} {
<|EGG> Currently: puthelp "NOTICE $nick :Error I don't have OP!"
<|EGG> Currently: return 0
<|EGG> Currently: } elseif {[matchattr $hand -|T $chan]} {
<|EGG> Currently: ..."
<|EGG> Currently: ("if" then script line 3)
<|EGG> Currently: while compiling
<|EGG> Currently: "if {[matchattr $hand n|MASDTO $chan] || [string tolower $chan]} {
<|EGG> Currently: set target [lindex [split $text] 0]
<|EGG> Currently: if {![botisop $chan]} {
<|EGG> Currently: put..."
<|EGG> Currently: ("if" then script line 2)
<|EGG> Currently: while compiling
<|EGG> Currently: "if {[channel get $chan djtools] && ![isbotnick $nick]} {
<|EGG> Currently: if {[matchattr $hand n|MASDTO $chan] || [string tolower $chan]} {
<|EGG> Currently: set target [lindex ..."
<|EGG> Currently: (compiling body of proc "s:ban", line 3)
<|EGG> Currently: invoked from within
<|EGG> Currently: "s:ban $_pub1 $_pub2 $_pub3 $_pub4 $_pub5"
I`m suppose that my code is a little more complicated and has a lot of if-elseif-else commands in it and maybe that`s why it makes it hard to solve, and I`ll really appreciate is someone helps me to make this script a little more simple than... and also to make it work...

I`ve pointed that I want this script to do something like this:
For OP access user ( +O flag )

<OP> !day 7 *!*@*.test.ro
* |EGG sets mode: +b *!*@*.test.ro

How it works:
- sets a chan ban for 1 or 7 days on the banmask with a default ban reason;
- if the OP will type a number higher than 7, like 8 or 9 or 100, the BOT will NOT do the chan ban and will give the specific notice (puthelp "NOTICE $nick :Error max allowed 1-7 days for OP Access Users");

For Test OPs access user ( +T flag )

<TestOP> !day 14 *!*@*.test.ro
* |EGG sets mode: +b *!*@*.test.ro
How it works:
- sets a chan ban for 1 or 14 days on the banmask with a default ban reason;
- if the OP will type a number higher than 14, like 15 or 16 or 100, the BOT will NOT do the chan ban and will give the specific notice (puthelp "NOTICE $nick :Error max allowed 1-14 days for Test OP Access Users");

(...)
and so on for the other flags... the higher the access flag, the more day's you can add to the banmask 8)

It`s a complicated code I`m trying to make... at least I`m trying :? ( my tcl knowledge are at the beginning :cry: ) ...so any help will be appreciated. Thanks
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 »

This time you're lacking some brackets ([]), check this line again:

Code: Select all

     if {![regexp "\[^15-99999\]" $target} {
NML_375
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Here's a huge bit of help: Properly TABINATE your scripts... Then you'd be able to see where missing junk is:

Code: Select all

if {this is my first test} {
        #tab
} else {
        if {this is my 2nd test} {
                 # tab tab
        } else {
                  if {this makes it much easier to figure things out} {
                             # tab tab tab
                 }
        }
}
Yes I know tabs are a matter of style, but if you're having that much difficulty as a beginner, then learn good coding habits, which begin with TABS (and using small fonts/wider screens so you can read 300+ char length lines because of deeply nested if's/tabs :) And if your editor allows you to configure tab stops, set it to 4 spaces, not 2, which also makes it easier to read..
Post Reply