| View previous topic :: View next topic |
| Author |
Message |
dokueki Voice
Joined: 28 Apr 2007 Posts: 31 Location: Bat Yam, Israel
|
Posted: Sat Apr 28, 2007 8:48 am Post subject: URL Quick Linking Script |
|
|
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: | #===========================================================================
# ** 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! |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Apr 28, 2007 8:55 am Post subject: |
|
|
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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
dokueki Voice
Joined: 28 Apr 2007 Posts: 31 Location: Bat Yam, Israel
|
Posted: Sat Apr 28, 2007 9:02 am Post subject: |
|
|
| 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: | #===========================================================================
# ** 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. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Apr 28, 2007 9:18 am Post subject: |
|
|
Oops, missed the second error...
tcl is newline-terminated, so this wont work:
| Code: | if {..} {
...
}
else {
...
} | However, this will:
| Code: | if {...} {
...
} else {
...
} |
Simply put, "else" is not a command, but a parameter to "if". _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
dokueki Voice
Joined: 28 Apr 2007 Posts: 31 Location: Bat Yam, Israel
|
Posted: Sat Apr 28, 2007 9:48 am Post subject: |
|
|
| Damn, It's still not working >_< |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Apr 28, 2007 12:29 pm Post subject: |
|
|
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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
dokueki Voice
Joined: 28 Apr 2007 Posts: 31 Location: Bat Yam, Israel
|
Posted: Sat Apr 28, 2007 2:16 pm Post subject: |
|
|
| 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  |
|
| Back to top |
|
 |
|