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.

[SOLVED] Ban code error

Help for those learning Tcl or writing their own scripts.
Post Reply
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

[SOLVED] Ban code error

Post by Riddler »

Hello all, I need some help form you guys...if posibile .
I have a tried to code a ban script and also I`m working one a blacklist script and I`m geting some errors:

The code:

Code: Select all

# ban.tcl

# Set here reason and bantime in minutes for bans
set dj(br) "Banned!"
set dj(bt) 1440

# Activate ban times? [1/0]
set dj(bact) 1

###END CFG ###

bind pub n|MASDTO .b s:b
bind pub n|MAS .bl s:black
bind pub n|MAS .black s:black

setudef flag djtools

proc s:b {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 bnick [lindex $text 0]
     if {![botisop $chan]} {
     puthelp "NOTICE $nick :Error I don't have OP!"
     } elseif {$bnick == ""} {
     puthelp "NOTICE $nick :SYNTAX\002 .b <nick|*!*@host> \[reason\] \002"
     } elseif {![onchan $bnick]} {
     puthelp "NOTICE $nick :Error\002 $bnick \002is not on\002 $chan \002Check\002 .b \002"
     } else {
     set bhost "*!*@[lindex [split $uhost @] 1]"
     set bres [lindex $text 1 end]
     } else { set bres $dj(br)
        newchanban $chan $bhost ban ($hand) $bres $dj(bt)
        putquick "KICK $chan $bnick :($hand) $bres"
        if {$dj(xb) == 1} {
        putserv "PRIVMSG X :ban $chan $bhost 1 100 ($hand) $bres" -next
        }
       return 1
      }
    }
  }
}
And the errors:
<me> .b
-|EGG- SYNTAX .b <nick|*!*@host> [reason]
<me> .b lol
-|EGG- Error lol is not on #channel Check .b
<me> .b test1
* |EGG sets mode: -o+b me *!*@me.users.undernet.org
* test1 was kicked by |EGG ((me) )
* Joins: test1 (identd@127.0.0.0)
* You were kicked by X ((egguser) (me))
* Attempting to rejoin channel #channel
* Unable to join channel (address is banned)
-> *x* unban #channel *!*@me.users.undernet.org
-X- Removed 2 pitchforks that matched *!*@me.users.undernet.org
* Rejoined channel #channel
.... it only kick the nickname I`ve typed, and the chanban and Xban is placed on me.... why ?! :? :(

This is the way it should have to work:
<me> .b
-|EGG- SYNTAX .b <nick|*!*@host> [reason]
<me> .b lol
-|EGG- Error lol is not on #channel Check .b
<me> .b test1 test-reason
* |EGG sets mode: +b *!*@127.0.0.0
* test1 was kicked by |EGG ((me) test-reason)
and if there is no reason added, the bot will use the defaul reason (in this case $dj(br) )

something like this
<me> .b test2
* |EGG sets mode: +b *!*@127.0.0.1
* test2 was kicked by |EGG ((me) Banned!)
Last edited by Riddler on Sat Nov 28, 2009 8:10 pm, edited 4 times in total.
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 »

The problem is here:

Code: Select all

set bhost "*!*@[lindex [split $uhost @] 1]"
$uhost is the user@host of the command issuer (i.e. you), instead use

Code: Select all

set bhost "*!*@[lindex [split [getchanhost $bnick] @] 1]"
and, as we've repeated ourselves on and on, you must NOT apply
  • commands on strings.

    Code: Select all

    set bnick [lindex $text 0]
    should be

    Code: Select all

    set bnick [lindex [split $text] 0]
    and

    Code: Select all

    set bres [lindex $text 1 end]
    should be

    Code: Select all

    set bres [join [lindex [split $text] 1 end]]
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

Thank Sir_Fz...
Ok the code with the changes:

Code: Select all

proc s:b {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 bnick [lindex [split $text] 0]
     set bhost "*!*@[lindex [split [getchanhost $bnick] @] 1]"
        if {![botisop $chan]} {
        puthelp "NOTICE $nick :Error I don't have OP!"
        } elseif {$bnick == ""} {
        puthelp "NOTICE $nick :SYNTAX\002 .b <nick|*!*@host> \[reason\] \002"
        } elseif {[join [lindex [split $text] 1 end]] == ""} {
        newchanban $chan $bhost ban ($hand) $dj(br) $dj(bt)
        putquick "KICK $chan $bnick :($hand) $dj(br)"
        if {$dj(xb) == 1} {
        putserv "PRIVMSG X :ban $chan $bhost 1 100 ($hand) $dj(br)" -next
        }
        return 1
        } else {
        set bres [join [lrange [split $text] 1 end]]
        newchanban $chan $bhost ban ($hand) $bres $dj(bt)
        putquick "KICK $chan $bnick :($hand) $bres"
        if {$dj(xb) == 1} {
        putserv "PRIVMSG X :ban $chan $bhost 1 100 ($hand) $bres" -next
        }
       return 1
      }
    }
  }
}
and I have this error in dcc-chat with the bot:
<|EGG> [16:48] Tcl error [s:b]: invalid option 1440 (must be one of: sticky, none)
...the bot dosen`t do nothing... :(


also a nother error...

Code: Select all

<me> .b *test*!*@* lol 
and also here the bot will NOT reply..
:?
:idea: :?: :!:

P.S.1: When i place a nickname , like .b Test-nick1 lol , the bot reacts and bans the Test-nick1...but on a hostmask... no react...
P.S.2: Also it bans users who have access to the bot and they are op/voice on the specific channel.... :cry: ...and it dosen`t have to do that.
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 »

Riddler wrote:
<|EGG> [16:48] Tcl error [s:b]: invalid option 1440 (must be one of: sticky, none)
...the bot dosen`t do nothing... :(
That means you're using an invalid switch with the newchanban command.
Riddler wrote: also a nother error...

Code: Select all

<me> .b *test*!*@* lol 
and also here the bot will NOT reply..
:?
:idea: :?: :!:

P.S.1: When i place a nickname , like .b Test-nick1 lol , the bot reacts and bans the Test-nick1...but on a hostmask... no react...
P.S.2: Also it bans users who have access to the bot and they are op/voice on the specific channel.... :cry: ...and it dosen`t have to do that.
The bot doesn't figure things out by itself, you have to script it. In your code, you do not check whether bnick is a hostmask or a nick, you always assume it's a nick. So you might want to check if it's a hostmask (something like if {[string match *!*@* $bnick]} {) And to exempt +of users you also need to add a check (i.e. use the [matchattr] command).
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

Sir_Fz wrote:
Riddler wrote:
<|EGG> [16:48] Tcl error [s:b]: invalid option 1440 (must be one of: sticky, none)
...the bot dosen`t do nothing... :(
That means you're using an invalid switch with the newchanban command.
Ok, I understand this, but if I change the newchanban command to this

Code: Select all

newchanban $chan $bhost ban $dj(br) $dj(bt)
it works, the person gets ban on the channel like this
<me> .b TestNick1
* |EGG sets mode: +b *!*@127.0.0.1
* TestNick1 was kicked by |EGG ((test) Banned!)
all is ok, but if I remove the chan ban manualy when the person rejoins the channel ...he gets ban again ( using the internal banlist of the bot ) but the reason has change...
* me sets mode: -b *!*@127.0.0.1
* Joins: TestNick1 (identd@127.0.0.1)
* |EGG sets mode: +b *!*@127.0.0.1
* TestNick1 was kicked by |EGG (Banned: Banned!)
.... in the internal banlist of the bot for this specific ban ... the ($hand) is not recorded ( in this case (test) )...

How can I fit the ($hand) code in the reason and make the newchanban command work also ?
To look something like this:
* me sets mode: -b *!*@127.0.0.1
* Joins: TestNick1 (identd@127.0.0.1)
* |EGG sets mode: +b *!*@127.0.0.1
* TestNick1 was kicked by |EGG (Banned: (test) Banned!)
....
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 »

Change the reason to something like "($hand) $dj(br)" instead of just $dj(br) in the newchanban reason.
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

Ok, done, fixed the bug, it works...thanks Sir_Fz 8) (again :D )

A little problem remains... and that is were/how do you I put the excepts code for ops,voiced and users that have access to the bot ( by the level n|MASDTOV ) so that they don`t get ban by the bot ...
On other scripts ( protection type of scripts ) I use this code for excepting ops, voices and users in the access list of the bot:

Code: Select all

if {[matchattr $hand of|of $chan] || [isop $nick $chan] || [isvoice $nick $chan]}  { return 0 }
if {(([lsearch -exact [string tolower $webadvchan] [string tolower $chan]] != -1) || ($webadvchan == "*")) && (![matchattr $hand b]) && ($nick != $botnick)} {
it works great on those scripts.. but were do I set it in this case ... ?! :?: :!: :shock:

suggestions ?!
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 »

Use [nick2hand $bnick] to get the handle of $bnick (read about it in tcl-commands.doc).
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

Sir_Fz wrote:Use [nick2hand $bnick] to get the handle of $bnick (read about it in tcl-commands.doc).
Ok ...let`s see if this idea will work...

Code: Select all

set drhost [nick2hand $drnick]
if {![matchattr $drhost n|MASDTOVU $chan] || [isop $drnick $chan] || [isvoice $drnick $chan] || ![matchattr $drhost b]} {
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 »

Code: Select all

if {[matchattr $drhost n|MASDTOVU $chan] || [isop $drnick $chan] || [isvoice $drnick $chan] || [matchattr $drhost b]} {
 # do nothing
 return 0
}
or

Code: Select all

if {![matchattr $drhost n|MASDTOVU $chan] && ![isop $drnick $chan] && ![isvoice $drnick $chan] && ![matchattr $drhost b]} {
 # do everything here
}
R
Riddler
Halfop
Posts: 60
Joined: Sun May 20, 2007 10:20 pm
Location: Brasov, Romania
Contact:

Post by Riddler »

Thanks Sir_Fz :D 8) The script works great now :P
I am a man of few words, but many riddles
Post Reply