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.

URL Quick Linking Script

Help for those learning Tcl or writing their own scripts.
Post Reply
d
dokueki
Voice
Posts: 31
Joined: Sat Apr 28, 2007 8:42 am
Location: Bat Yam, Israel
Contact:

URL Quick Linking Script

Post by dokueki »

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):

Code: Select all

#=========================================================================== 
# ** 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!
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
NML_375
d
dokueki
Voice
Posts: 31
Joined: Sat Apr 28, 2007 8:42 am
Location: Bat Yam, Israel
Contact:

Post by dokueki »

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
Thanks for your help! I updated the script as so:

Code: Select all

#=========================================================================== 
# ** 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.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Oops, missed the second error...
tcl is newline-terminated, so this wont work:

Code: Select all

if {..} {
...
}
else {
...
}
However, this will:

Code: Select all

if {...} {
...
} else {
...
}
Simply put, "else" is not a command, but a parameter to "if".
NML_375
d
dokueki
Voice
Posts: 31
Joined: Sat Apr 28, 2007 8:42 am
Location: Bat Yam, Israel
Contact:

Post by dokueki »

Damn, It's still not working >_<
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

It would seem that you are using a msg-binding, rather than a pub-binding.
doc/tcl-commands.doc wrote: (1) MSG
bind msg <flags> <command> <proc>
procname <nick> <user@host> <handle> <text>

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?
NML_375
d
dokueki
Voice
Posts: 31
Joined: Sat Apr 28, 2007 8:42 am
Location: Bat Yam, Israel
Contact:

Post by dokueki »

nml375 wrote:It would seem that you are using a msg-binding, rather than a pub-binding.
doc/tcl-commands.doc wrote: (1) MSG
bind msg <flags> <command> <proc>
procname <nick> <user@host> <handle> <text>

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 :D
Post Reply