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.

Two scripts, which is better?

Help for those learning Tcl or writing their own scripts.
Post Reply
L
Longbow
Voice
Posts: 29
Joined: Thu Jan 13, 2005 9:24 am

Two scripts, which is better?

Post by Longbow »

Code: Select all

bind pub - ${trigger}kick akick

proc akick {nick host hand chan text} {
global botnick protect
if {([matchattr $hand n] || [isop $nick $chan]) && [isop $botnick $chan]} {
	if {[lindex $text 0] == ""} {
	putserv "NOTICE $nick :You need to enter a user."
	} else {
	if {[onchan [lindex $text 0] $chan]} {
if {([string tolower [lindex $text 0]] == [string tolower $botnick]) || [matchattr [lindex $text 0] +n]} {
putserv "NOTICE $nick :That user is protected."
	} else {
			if {[lindex $text 1] == ""} {
			putquick "KICK $chan [lindex $text 0] Bye."
			} else {
			putquick "KICK $chan [lindex $text 0] [lrange $text 1 end]"
			}
		}
	} else {
	putserv "NOTICE $nick :[lindex $text 0] is not on the channel."
	}
}
}
}

Code: Select all

bind pub - ${trigger}kick akick

proc akick {nick host hand chan text} {
global botnick
if {([matchattr $hand n] || [isop $nick $chan]) && [botisop $chan]} {
global botnick

if {$text == ""} {
putserv "NOTICE $nick :You need to enter a user."
return 0
}

if {![onchan [lindex $text 0] $chan]} {
putserv "NOTICE $nick :[lindex $text 0] is not on the channel."
return 0
}

if {([string tolower [lindex $text 0]] == [string tolower $botnick]) || [matchattr [lindex $text 0] +n]} {
putserv "NOTICE $nick :That user is protected."
return 0
}

if {[lindex $text 1] == ""} {
putquick "KICK $chan [lindex $text 0] Bye."
} else {
putquick "KICK $chan [lindex $text 0] [lrange $text 1 end]"
}
return 0
}
}
Both do the same action, but was wondering which is "better"?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

well both suck because they are posted with bad formating plus both use list functions on strings (read http://forum.egghelp.org/viewtopic.php?t=2603).
Other than that I dont see a major diffrence, seems the if structure is a bit diffrent, but almost unrecognizeable without formating.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Code: Select all

bind PUB o|mn ${trigger}kick trigger:kick
proc trigger:kick {nickname hostname handle channel arguments} {
 if {[botisop $channel]} {
  if {[lindex [split $arguments] 0] == "" || ![onchan [lindex [split $arguments] 0] $channel] || [string equal -nocase $nickname [lindex [split $arguments] 0]] || [isbotnick [lindex [split $arguments] 0]] || [string length [lindex [split $arguments] 0]] == "1"} {
   putquick "NOTICE $nickname :Usage: ${::lastbind} nickname ?reason?"
  } elseif {[validuser [nick2hand [lindex [split $arguments] 0]]] && (([matchattr [nick2hand [lindex [split $arguments] 0]] |o $channel] && ![matchattr $handle |m $channel]) || ([matchattr [nick2hand [lindex [split $arguments] 0]] |m $channel] && ![matchattr $handle |n $channel]))} {
   putquick "KICK $channel $nickname :Do not attempt to kick someone with a higher or equal level to you."
  } else {
   putquick "KICK $channel [string trim [lindex [split $arguments] 0]] :[expr {([join [string trim [lrange [split $arguments] 1 end]]] == "") ? "Requested by $handle." : "[join [lrange [split $arguments] 1 end]]"}]"
  }
 }
}
(Code looks nasty in the browser because it has to cut it into pieces)
Post Reply