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.

A little help to modify script

Help for those learning Tcl or writing their own scripts.
Post Reply
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

A little help to modify script

Post by blake »

Id like this changed from public commands to commands issued in bots private message

Also would like to get the nick is connecting from line added also to the whois proc

Theirs also some bindings that need taking out
<ChanGuardian> [19:15] Tcl error [whois:ircop]: no such binding
<ChanGuardian> [19:27] Tcl error [who:info]: no such binding
<ChanGuardian> [19:27] Tcl error [who:eof]: no such binding

if this isnt possible just a small script that will do a whois nickname and notice the details

Code: Select all

# rsh-serverCmds.tcl - by rehash
# Copyright (C) 2004, 2005 rehash.
# All rights reserverd.
#
#            _            _
#    _ _ ___| |_  __ _ __| |_
#   | '_/ -_) ' \/ _` (_-< ' \
#   |_| \___|_||_\__,_/__/_||_|
#   rehash@relevant-undernet.org
#
#  Contact: E-mail: rehash@relevant-undernet.org
#  Web: www.relevant-undernet.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
######################################################################
# Some CREDIT #
###############
set whois(author) "rehash"
set whois(version) "0.1"

# Global Settings.
# You cand set it like: "privmsg" if you want the bot to echo you the results in a separate
# query window or "notice" for echo it via NOTICE command.
set whois(echo) "notice"

###################################################
# Flags required for usage.                       #
# - : anyone                                      #
# o : +o flagged users                            #
# m : bot masters..                               #
# and so on see the EggDrops flags documentation. #
# Default: "-".                                   #
###################################################
set whois(flags) "ho|ho"

# Bindings.
bind pub "$whois(flags)" "!whois" pub:whois
bind pub "$whois(flags)" "!whowas" pub:whowas
bind pub "$whois(flags)" "!who" pub:who
bind pub "$whois(flags)" "!version" pub:version
bind pub "$whois(flags)" "!userhost" pub:userhost
bind pub "$whois(flags)" "!userip" pub:userip
bind pub "$whois(flags)" "!help" pub:help


# Proc for NOTICE command.
proc notice {nick message} {
	putquick "NOTICE $nick :$message"
}

# Proc for PRIVMSG command.
proc privmsg {nick message} {
	putquick "PRIVMSG $nick :$message"
}

################################
# The main procedure of WHOIS. #
################################
proc pub:whois {nick host hand chan text} {
	set whom [lindex $text 0]
	if {$whom == ""} { notice $nick "Syntax: $::whois(cmdChar)whois <nickname>"; return 1; }
	if {[string length $whom] >= "32"} { notice $nick "Nickname specified is more then 12 characters long!"; return 1; }
	putquick "WHOIS $whom $whom"
	# Setting global variables.
	set ::whoischan $chan
	set ::whoisnick $whom
	set ::whoisfrom $nick
	# Binds of RAW type.
	bind raw - 311 whois:info
	bind raw - 319 whois:chans
	bind raw - 301 whois:away
	bind raw - 312 whois:server
	bind raw - 313 whois:ircop
	bind raw - 317 whois:time
	bind raw - 330 whois:auth
	bind raw - 401 whois:nosuch
	bind raw - 318 whois:eof
}

#################################
# The main procedure of WHOWAS. #
#################################
proc pub:whowas {nick host hand chan text} {
	set whom [lindex $text 0]
	if {$whom == ""} { notice $nick "Syntax: $::whois(cmdChar)whowas <nickname>"; return 1; }
	if {[string length $whom] >= "32"} { notice $nick "Nickname specified is more then 12 characters long!"; return 1; }
	putquick "WHOWAS $whom"
	# Setting global variables.
	set ::whowaschan $chan
	set ::whowasnick $whom
	set ::whowasfrom $nick
	# Binds of RAW type.
	bind raw - 314 whowas:info
	bind raw - 369 whowas:eof
	bind raw - 301 whowas:away
	bind raw - 406 whowas:nosuch
}

##############################
# The main procedure of WHO. #
##############################
proc pub:who {nick host hand chan text} {
	set whom [lindex $text 0]
	if {$whom == ""} { notice $nick "Syntax: $::whois(cmdChar)who <nickname/hostmask>"; return 1; }
	putquick "WHO $whom"
	# Setting global variables.
	set ::whochan $chan
	set ::whonick $whom
	set ::whofrom $nick
	# Binds of RAW type.
	bind raw - 352 who:info
	bind raw - 315 who:eof
	bind raw - 416 who:error
}

##################################
# The main procedure of VERSION. #
##################################
proc pub:version {nick host hand chan text} {
	putquick "VERSION"
	# Setting global variables.
	set ::versionfrom $nick
	# Binds of RAW type.
	bind raw - 351 version:info
}

###################################
# The main procedure of USERHOST. #
###################################
proc pub:userhost {nick host hand chan text} {
	set whom [lindex $text 0]
	if {$whom == ""} { notice $nick "Syntax: $::whois(cmdChar)userhost <nickname>"; return 1; }
	if {[string length $whom] >= "32"} { notice $nick "Nickname specified is more then 12 characters long!"; return 1; }
	putquick "USERHOST $whom"
	# Setting global variables.
	set ::userhostfrom $nick
	set ::userhostnick $whom
	# Binds of RAW type.
	bind raw - 302 userhost:info
}

#################################
# The main procedure of USERIP. #
#################################
proc pub:userip {nick host hand chan text} {
	set whom [lindex $text 0]
	if {$whom == ""} { notice $nick "Syntax: $::whois(cmdChar)userip <nickname>"; return 1; }
	if {[string length $whom] >= "32"} { notice $nick "Nickname specified is more then 12 characters long!"; return 1; }
	putquick "USERIP $whom"
	# Setting global variables.
	set ::useripfrom $nick
	set ::useripnick $whom
	# Binds of RAW type.
	bind raw - 340 userip:info
}

####################
# WHOIS PROCEDURES #
####################
proc whois:info {from keyword arg} {
	set chan $::whoischan
	set nick [lindex [split $arg] 1]
	set ident [lindex [split $arg] 2]
	set host [lindex [split $arg] 3]
	set realname [string range [join [lrange $arg 5 end]] 1 end]
	$::whois(echo) $::whoisfrom "$nick is $ident@$host * $realname"
	unbind raw - 311 whois:info
}

proc whois:chans {from keyword arg} {
	set nick $::whoisnick
	set chans [string range [join [lrange $arg 2 end]] 1 end]
	$::whois(echo) $::whoisfrom "$nick on $chans"
	unbind raw - 319 whois:chans
}

proc whois:away {from keyword arg} {
	set nick $::whoisnick
	set awayMessage [string range [lrange $arg 2 end] 1 end]
	$::whois(echo) $::whoisfrom "$nick is away: $awayMessage"
	unbind raw - 301 whois:away
}

proc whois:server {from keyword arg} {
	set nick $::whoisnick
	set server [lindex [split $arg] 2]
	set info [string range [join [lrange $arg 3 end]] 1 end]
	$::whois(echo) $::whoisfrom "$nick using $server $info"
	unbind raw - 312 whois:server
}

proc whois:ircop {from keyword arg} {
	set nick $::whoisnick
	set msg [string range [lrange $arg 2 end] 1 end]
	$::whois(echo) $::whoisfrom "$nick $msg"
	unbind raw - 313 whois:server
}

proc whois:time {from keyword arg} {
	set nick $::whoisnick
	set idle [lindex [split $arg] 2]
	set signedon [lindex [split $arg] 3]
	$::whois(echo) $::whoisfrom "$nick has been idle for [duration $idle]. signed on [ctime $signedon]"
	unbind raw - 317 whois:time
}

proc whois:auth {from keyword arg} {
	set nick $::whoisnick
	set authname [lindex [split $arg] 2]
	$::whois(echo) $::whoisfrom "$nick is logged in as $authname"
	unbind raw - 330 whois:auth
}

proc whois:nosuch {from keyword arg} {
	set nick $::whoisnick
	$::whois(echo) $::whoisfrom "$nick No such nick"
	unbind raw - 401 whois:nosuch
}

proc whois:eof {from keyword arg} {
	set nick $::whoisnick
	set eof [string range [join [lrange [split $arg] 2 end]] 1 end]
	$::whois(echo) $::whoisfrom "$nick $eof"
	unbind raw - 318 whois:eof
}

#####################
# WHOWAS PROCEDURES #
#####################
proc whowas:info {from keyword arg} {
	set nick [lindex [split $arg] 1]
	set ident [lindex [split $arg] 2]
	set host [lindex [split $arg] 3]
	set realname [string range [join [lrange $arg 5 end]] 1 end]
	$::whois(echo) $::whowasfrom "$nick was $ident@$host * $realname"
	unbind raw - 314 whowas:info
}

proc whowas:nosuch {from keyword arg} {
	set nick $::whowasnick
	$::whois(echo) $::whowasfrom "$nick There was no such nickname"
	unbind raw - 406 whowas:nosuch
}

proc whowas:away {from keyword arg} {
	set nick $::whowasnick
	set awayMessage [string range [lrange $arg 2 end] 1 end]
	$::whois(echo) $::whoisfrom "$nick was away: $awayMessage"
	unbind raw - 301 whowas:away
}

proc whowas:eof {from keyword arg} {
	set eof [string range [join [lrange [split $arg] 2 end]] 1 end]
	$::whois(echo) $::whowasfrom "$eof"
	unbind raw - 369 whowas:eof
}

##################
# WHO PROCEDURES #
##################
proc who:info {from keyword arg} {
	set nick [lindex $arg 5]
	set ident [lindex $arg 2]
	set addr [lindex $arg 3]
	set server [lindex $arg 4]
	set flags [lindex $arg 6]
	set hops [lindex $arg 7]
	set info [string range [join [lrange $arg 8 end]] 0 end]
	$::whois(echo) $::whofrom "* $nick $flags $ident@$addr $hops $info"
	unbind raw - 314 who:info
}

proc who:error {from keyword arg} {
	$::whois(echo) $::whofrom "Too many lines in the output, restrict your query"
	unbind raw - 416 who:error
}

proc who:eof {from keyword arg} {
	$::whois(echo) $::whofrom "* End of /WHO list."
	unbind raw - 369 who:eof
}

######################
# VERSION PROCEDURES #
######################
proc version:info {from keyword arg} {
	set version [lindex [split $arg] 1]
	set server [lindex [split $arg] 2]
	$::whois(echo) $::versionfrom "$version - $server"
	unbind raw - 351 version:info
}

#######################
# USERHOST PROCEDURES #
#######################
proc userhost:info {from keyword arg} {
	set usershost [string range [join [lrange $arg 1 end]] 1 end]
	$::whois(echo) $::userhostfrom "userhost: $usershost"
	unbind raw - 302 userhost:info
}

#####################
# USERIP PROCEDURES #
#####################
proc userip:info {from keyword arg} {
	set usersip [string range [join [lrange $arg 1 end]] 1 end]
	$::whois(echo) $::useripfrom "userip: $usersip"
	unbind raw - 340 userip:info
}
############
# THE HELP #
############

proc pub:help {nick host hand chan text} {
	$::whois(echo) $nick "\002rsh-serverCmds\002 commands list:"
	$::whois(echo) $nick "---------------------------------------------------------------"
	$::whois(echo) $nick "!whois <nickname> : Returns the WHOIS info for NICKNAME."
	$::whois(echo) $nick "!whowas <nickname> : Returns the WHOWAS info for NICKNAME."
	$::whois(echo) $nick "!who <nick/host/mask> : Returns the WHO command results."
	$::whois(echo) $nick "!version : Returns the server VERSION."
	$::whois(echo) $nick "!userip <nickname> : Returns the USERIP info for NICKNAME."
	$::whois(echo) $nick "!userhost <nickname> : Returns the USERHOST info for NICKNAME."
	$::whois(echo) $nick "!about : Information regarding the script."
	$::whois(echo) $nick "---------------------------------------------------------------"
	$::whois(echo) $nick "End of HELP."
}
putlog "\002rsh-serverCmds.tcl\002 version \002$::whois(version)\002 by \002$::whois(author)\002 succesfully loaded."
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 in those procedures is that they're trying to remove a non-existing bind. For example in proc [whois:ircop] you'll find:

Code: Select all

unbind raw - 313 whois:server
which is not bound (most probably what was meant is: unbind raw - 313 whois:ircop but that's just a guess).

Another unrecommended practice is applying string methods on lists. Look at

Code: Select all

set awayMessage [string range [lrange $arg 2 end] 1 end]
[lrange] returns a list but [string] is supposed to be applied on strings and not lists. To fix this, it should be changed to:

Code: Select all

set awayMessage [string range [join [lrange [split $arg] 2 end]] 1 end]
[join] returns a string from the elements of the list (there are more lines that need to be modified like this as well).

Edit: Oh, and you should use [split] on $arg before applying [lrange] on it since it's a string and supposed to be a list.
Post Reply