Hey everyone. I'm pretty new to TCL scripting, and I could use some help
I'm making a script that will respond to a user saying !xpro [args] and will show text accordingly. The script is right here (including better description of everything):
#===========================================================================
# ** Quick Links 1.0 by Hen Asraf (C)2007
#===========================================================================
# * Description:
#---------------------------------------------------------------------------
# * Allows quick link command to show a link with a keyword
# Example:
# !wikipedia Main_Page
# will output:
# http://en.wikipedia.org/wiki/Main_Page (Requested by Nickname)
#---------------------------------------------------------------------------
# * Future Plans:
#---------------------------------------------------------------------------
# * Multiple quicklinks drawn from a text file
# * Managable from chatroom/PM/DCC
#===========================================================================
# Set version number for the script
set quicklink(version) "1.0"
# Command used to call the script. Default is "!command".
set quicklink(cmd) "!xpro"
# Quick link URL. Put two links in here:
# 1. Base URL (Example: http://www.domain.com) w/o following slash.
# This will be echoed when only the shortcut is entered, with no
# arguments.
# 2. Scripts relative URL (Example: index.php?) w/o slash before it.
# This will be echoed along with the URL before it and arguments
# after it.
# Seperate the arguments with a vertical line (" | ")
set quicklink(url) "http://xpro.zeeblo.com|index.php?"
# Split the arguments
set quicklink(url) [split $quicklink(url) |]
# Bindings
bind msg - $quicklink(cmd) msg:gen_url
# Generate URLs
proc msg:gen_url { nick host hand chan args } {
if {[lindex $args 0] == ""} {
putserv "PRIVMSG $chan :[lindex $quicklink(url) 0] (Requested by $nick)"
}
else {
putserv "PRIVMSG $chan :[lindex $quicklink(url) 0]/[lindex $quicklink(url) 1][lindex $args 0] (Requested by $nick)"
}
return 0
}
putlog "Quick Links $quicklink(version) by Hen Asraf Loaded"
Thing is, I say !xpro or for example !xpro topic=36 and nothing happens.
Anyone got any idea? Thanks in advance!
You are using localspace variables when you're actually trying to access globalspace variables within your msg:gen_url proc.
change $quicklink(url) to $::quicklink(url).
Secondly, try to avoid using "args" as a parameter for your proc, as it a "magic" name, allowing it to take 1 or more arguments (each placed as a list item within $args). Saves you the trouble of using [lindex $args 0] just to get the parameter in the first place
nml375 wrote:You are using localspace variables when you're actually trying to access globalspace variables within your msg:gen_url proc.
change $quicklink(url) to $::quicklink(url).
Secondly, try to avoid using "args" as a parameter for your proc, as it a "magic" name, allowing it to take 1 or more arguments (each placed as a list item within $args). Saves you the trouble of using [lindex $args 0] just to get the parameter in the first place
#===========================================================================
# ** Quick Links 1.0 by Hen Asraf (C)2007
#===========================================================================
# * Description:
#---------------------------------------------------------------------------
# * Allows quick link command to show a link with a keyword
# Example:
# !wikipedia Main_Page
# will output:
# http://en.wikipedia.org/wiki/Main_Page (Requested by Nickname)
#---------------------------------------------------------------------------
# * Future Plans:
#---------------------------------------------------------------------------
# * Multiple quicklinks drawn from a text file
# * Managable from chatroom/PM/DCC
#===========================================================================
# Set version number for the script
set quicklink(version) "1.0"
# Command used to call the script. Default is "!command".
set quicklink(cmd) "!xpro"
# Quick link URL. Put two links in here:
# 1. Base URL (Example: http://www.domain.com) w/o following slash.
# This will be echoed when only the shortcut is entered, with no
# arguments.
# 2. Scripts relative URL (Example: index.php?) w/o slash before it.
# This will be echoed along with the URL before it and arguments
# after it.
# Seperate the arguments with a vertical line (" | ")
set quicklink(url) "http://xpro.zeeblo.com|index.php?"
# Split the arguments
set quicklink(url) [split $quicklink(url) |]
# Bindings
bind msg - $quicklink(cmd) msg:gen_url
# Generate URLs
proc msg:gen_url { nick host hand chan action } {
if {$action == ""} {
putserv "PRIVMSG $chan :[lindex $::quicklink(url) 0] (Requested by $nick)"
}
else {
putserv "PRIVMSG $chan :[lindex $::quicklink(url) 0]/[lindex $::quicklink(url) 1]$action (Requested by $nick)"
}
return 0
}
putlog "Quick Links $quicklink(version) by Hen Asraf Loaded"
But it's still not working. I'd appreciate it very much if you would continue helping.
Description: used for /msg commands. The first word of the user's
msg is the command, and everything else becomes the text argument.
Module: server
...
(4) PUB
bind pub <flags> <command> <proc>
procname <nick> <user@host> <handle> <channel> <text>
Description: used for commands given on a channel. The first word
becomes the command and everything else is the text argument.
Module: irc
As you can see, there is no channel argument for msg-bindings (as it is not related to any channel). It would seem you intended to use a pub-binding but accidentally used the msg-binding?
Description: used for /msg commands. The first word of the user's
msg is the command, and everything else becomes the text argument.
Module: server
...
(4) PUB
bind pub <flags> <command> <proc>
procname <nick> <user@host> <handle> <channel> <text>
Description: used for commands given on a channel. The first word
becomes the command and everything else is the text argument.
Module: irc
As you can see, there is no channel argument for msg-bindings (as it is not related to any channel). It would seem you intended to use a pub-binding but accidentally used the msg-binding?
Works like a charm, thank you very much! You've been very helpful