egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

URL Quick Linking Script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
dokueki
Voice


Joined: 28 Apr 2007
Posts: 31
Location: Bat Yam, Israel

PostPosted: Sat Apr 28, 2007 8:48 am    Post subject: URL Quick Linking Script Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Apr 28, 2007 8:55 am    Post subject: Reply with quote

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
View user's profile Send private message
dokueki
Voice


Joined: 28 Apr 2007
Posts: 31
Location: Bat Yam, Israel

PostPosted: Sat Apr 28, 2007 9:02 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Apr 28, 2007 9:18 am    Post subject: Reply with quote

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
View user's profile Send private message
dokueki
Voice


Joined: 28 Apr 2007
Posts: 31
Location: Bat Yam, Israel

PostPosted: Sat Apr 28, 2007 9:48 am    Post subject: Reply with quote

Damn, It's still not working >_<
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Apr 28, 2007 12:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
dokueki
Voice


Joined: 28 Apr 2007
Posts: 31
Location: Bat Yam, Israel

PostPosted: Sat Apr 28, 2007 2:16 pm    Post subject: Reply with quote

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 Very Happy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber