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.

Problems with Brackets & Pipes...

Old posts that have not been replied to for several years.
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Problems with Brackets & Pipes...

Post by ProXy »

Hi there,

I have a little Script that should kick and ban a user via bublic command. I just start the proc using !lamer NICKNAME. I also entered this line to check if the user is in the channel before kicking:

Code: Select all

} elseif {[lsearch -exact [string tolower [chanlist $channel]] [string tolower [lindex [split $arg] 0]]]==-1} { putserv "PRIVMSG $channel :Error: \"[lindex [split $arg] 0]\" ist nicht in diesem Channel! $lamerusage" }
I have to split the $arg because $arg can have those 2 values:

1. nickname
2. nickname & Bantime

Whenever I try to kick a user that uses Brackets and Pipes in his nick, i get the error, that the user is not in the channel. Does anyone know how to solve that?
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Re: Problems with Brackets & Pipes...

Post by egghead »

ProXy wrote:Hi there,

I have a little Script that should kick and ban a user via bublic command. I just start the proc using !lamer NICKNAME. I also entered this line to check if the user is in the channel before kicking:

Code: Select all

} elseif {[lsearch -exact [string tolower [chanlist $channel]] [string tolower [lindex [split $arg] 0]]]==-1} { putserv "PRIVMSG $channel :Error: "[lindex [split $arg] 0]" ist nicht in diesem Channel! $lamerusage" }
I have to split the $arg because $arg can have those 2 values:

1. nickname
2. nickname & Bantime

Whenever I try to kick a user that uses Brackets and Pipes in his nick, i get the error, that the user is not in the channel. Does anyone know how to solve that?
The use of the [onchan nick channel] command is a tad better then using [string tolower], [split], [lindex], [chanlist] and [lsearch]. read more in tcl-commands.doc :)
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

Additionally, I've tried the following:

Code: Select all

bind PUB - !search searchnick

proc searchnick { nick uhost hand channel arg } {

   set chanlist [string tolower [chanlist $channel]]

   set searchnick [string tolower [lindex [split $arg] 0]]

   if {[lsearch -exact $chanlist $searchnick] == -1 } { 

      putserv "PRIVMSG $channel :$searchnick is NOT on $channel!"

   } else {

      putserv "PRIVMSG $channel :$searchnick is on $channel!"

   }

}
with the following result:
<egg{{||[[head> !search egg{{||[[head
<Eggheadsbot> egg{{||[[head is on #egghead!
Likely, the problem is in a different part of your script.
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

*lol* Thx a lot - I ever thought about this way - all problems fixed now :)
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

Oh but it is still not possible to Kick User that have ` in their nick. Any ideas?

I also found another bug. In some cases the eggdrop cannot ban the user because he bans the wrong hostmask!

Code: Select all

set lamerhost [getchanhost [lindex [split $arg] 0] $channel]
		putserv "MODE $channel +b [lindex [split $arg] 0]!$lamerhost"
Isn`t this source right?
Last edited by ProXy on Thu Oct 03, 2002 11:35 am, edited 1 time in total.
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

ProXy wrote:Oh but it is still not possible to Kick User that have ` in their nick. Any ideas?
Lot of ideas :) But need to see the full script.
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

Code: Select all

#### Flag for global users ####
set lamerglobalflag "*"

#### Flag for local users #####
set lamerlocalflag "*"

####### Public command ########
set lamercommand "!lamer"

## default ban-time in mins ###
set lamerdefaulttime "10"

#### END OF CONFIGURATION #####

set lamerusage "Usage: $lamercommand <nick> \[time\]"
bind pub $lamerglobalflag|$lamerlocalflag $lamercommand pub:lamer
proc pub:lamer { nick uhost handle channel arg } {
	global botnick lamerdefaulttime lamerusage
	if {([llength $arg]==0) || (![string is digit [lindex [split $arg] 1]]) || ([llength [lindex [split $arg] 2]])} {
		putserv "PRIVMSG $channel :$lamerusage"
	} elseif {[onchan [lindex [split $arg] 0] $channel]!=1} {
		putserv "PRIVMSG $channel :Error: \"[lindex [split $arg] 0]\" ist nicht in diesem Channel! $lamerusage"
	} elseif {![botisop $channel]} {
		putserv "PRIVMSG $channel :$nick: Ja, du Scherzkeks, dann gib mir OP!"
	} elseif {[string tolower [lindex [split $arg] 0]]==[string tolower $botnick]} {
		putserv "PRIVMSG $channel :$nick: So blöd bin ich nun wirklich nicht..."
	} else {
		if {[llength [lindex [split $arg] 1]]!=0} {
			set lamerbantime [lindex [split $arg] 1]
		} else {
			set lamerbantime $lamerdefaulttime
		}
		set lamerhost [getchanhost [lindex [split $arg] 0] $channel]
		putserv "MODE $channel +b [lindex [split $arg] 0]!$lamerhost"
		if {$lamerbantime==1} {
			set lamermins "minute"
		} else {
			set lamermins "minutes"
		}
		utimer 2 [list putkick $channel [lindex [split $arg] 0] "banned for $lamerbantime $lamermins"] 
		timer $lamerbantime [list putserv "MODE $channel -b [lindex [split $arg] 0]!$lamerhost"]
	}
}
Perhaps you could also check why he sometimes bans a wrong host :)

I just tested the script again: It is possible to use !lamer eS`rien, the bot bans the host (but the wrong host) and kicks the user. But it is NOT possible to kick or bann the user frz`bot...

The value of onchan frz`bot #HTP is 0, even when the user is in the channel!
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

That is some interesting code :evil:

Just some general suggestions:

1. The if-the-else-elseif constructions are too complicated. A simple approach:

Code: Select all

if {conditional statement } {
   do something
   return 1
}

if {conditional statement } {
   do something
   return 1
}
etc. etc.
2. In most of the if-then statements you must include return statements. The return statements will stop further processing of the procedure.

3. A lot of times statements like "[lindex [split $arg] 0]" are used. For easier reading it is better to reuse variables. Example:
set arglist [split $arg]
set listlen [llength $arglist]
set lamer [lindex $arglist 0]
set bantime [lindex $arglist 1]

reuse these variable in the code.
4. What is the idea of ([llength [lindex [split $arg] 2]])?

5. Instead of sending out a +b, a kick and an unban, it can be easier to simply set a "newchanban" (tcl-commands.doc) and with the correct settings let the bot enforce this ban.

6. Why use a timed kick which send a kick only 2 seconds after the command is issued?

7. running a test with a nick with ``` in it, just worked fine.
Last edited by egghead on Thu Oct 03, 2002 12:37 pm, edited 1 time in total.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

First off, unrealted.

You have some un-needed code.

Code: Select all

if {[llength [lindex [split $arg] 1]]!=0} {
split turns a string into a list.

lindex returns an item from the list, as a string.

llength measures how many items are in a list.

As such, you are using a string with the "llength" list command. When you should be using [string length].

Second, you have allready checked at the top of the script to see if the second argument is a number. thus, the default ban time, nor this code is of much use.

As for your problem, the only other thing this can be, is network related. What IRC network are you on, and what IRCD software does it use?
Last edited by ppslim on Thu Oct 03, 2002 12:36 pm, edited 1 time in total.
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

I just tested the script again: It is possible to use !lamer eS`rien, the bot bans the host (but the wrong host) and kicks the user. But it is NOT possible to kick or bann the user frz`bot...

The value of onchan frz`bot #HTP is 0, even when the user is in the channel!
The fact that it bans the wrong host etc. is likely due to the fact that you don't have return values included. Review the above comments, and test the script again with putlogs added at critical points.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

After testing for non-closed brackets, I was unable to locate any (allthough, my test suite is not the best thing int he world).

As such, there is no need to use any return statements.

Code: Select all

if {1==1} {
  code1
} elseif {2==2} {
  code2
} else {
  code3
}
Neither the command code2, nor code3 will execute. This is due to the fact, the code is considered exactly like the following.

Code: Select all

if {1==1} {
  code1
} else {
  if {2==2} {
    code2
  } else {
    code3
  }
}
If an IF statment, has allready made a match (thus executing the corisponding body), no more processing of the same IF is done.

In plain elglish, if-elseif-else work like this

Code: Select all

if {A is equal to B} {
  then do this
} if-nothing-aboved-matched-try-this {C is equal to D} {
  then do this
} otherwise-the-only-alternative-is-this {
  do this
}
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

ppslim wrote:After testing for non-closed brackets, I was unable to locate any (allthough, my test suite is not the best thing int he world).

As such, there is no need to use any return statements.
Of course you are right and subsequently my comments on the return statements can be ignored. I was guided too much by disliking the construction made :wink:
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

Okay I fixed the bug with the ban, and the script works fine now, but i still have some questions:

Code: Select all

	if {([llength $arg]==0) || (![string is digit [lindex [split $arg] 1]]) || ([llength [lindex [split $arg] 2]])} {
This line should check if: The user entered a parameter , the user entered a number, the user typed a third (wrong) argument.
A right input would be: !lamer NICK 10, but not !lamer NICK 10 BLA.
I hope you understand my thinking. Now, what should be fxied in this short source to make it work better?
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

if {($arg == "") || (![string is digit [lindex [split $arg] 1]]) || ([llength [split $arg]] == "3")} {
Elen sila lúmenn' omentielvo
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

THX :)
Locked