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.

[SOLVED]Taking 3 Variables and merging to one

Help for those learning Tcl or writing their own scripts.
Post Reply
e
eXcel
Voice
Posts: 13
Joined: Mon Apr 28, 2008 8:03 pm

[SOLVED]Taking 3 Variables and merging to one

Post by eXcel »

Hello,

I am trying to get 3 variables to merge to one for chaning a topic.

I have this

Code: Select all

set fulltopic $info_topiccss,$info_topiccs,$info_topich3
putserv "PRIVMSG ChanServ :topic $chan [set fulltopic]"
But when I do this I only get the $info_topiccss part and the rest is ignored. How do I get all 3 to be implemented.

Thanks for your help!
Last edited by eXcel on Thu May 15, 2008 8:26 pm, edited 1 time in total.
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

set fulltopic "$info_topiccss, $info_topiccs, $info_topich3"
putserv "privmsg chanserv :topic $chan $fulltopic"

Code: Select all

set fulltopic ""
append fulltopic $info_topiccss
append fulltopic ", $info_topiccs"
append fulltopic ", $info_topich3"
putserv "privmsg chanserv :topic $chan $fulltopic"
Just two of the several ways to combine strings. Both acheiving the same result, same exact contents of $fulltopic.
e
eXcel
Voice
Posts: 13
Joined: Mon Apr 28, 2008 8:03 pm

Post by eXcel »

Hmm, Well I tried that but still.


Heres what i have

Code: Select all

# MULTICLAN BOT V1 SCRIPTS #
# TOPIC SETUP SCRIPT #

bind pub o|o .csnews topic_cschange
bind pub o|o .cssnews topic_csschange
bind pub o|o .h3news topic_h3change

bind pub o|o .updatetopic topic_set

proc topic_cschange { nick uhost hand chan arg } {
set cstopic [open /home/crave/irc/cravebot/scripts/cstopics.log w]
set topic $arg
puts $cstopic $topic
close $cstopic
putserv "NOTICE $nick :CS Topic Changed to $arg"
topic_set $chan $nick
}

proc topic_csschange { nick uhost hand chan arg } {
set csstopic [open /home/crave/irc/cravebot/scripts/csstopics.log w]
set topic $arg
puts $csstopic $topic
close $csstopic
putserv "NOTICE $nick :CS:S Topic Changed to $arg"
topic_set $chan $nick
}

proc topic_h3change { nick uhost hand chan arg } {
set h3topic [open /home/crave/irc/cravebot/scripts/h3topics.log w]
set topic $arg
puts $h3topic $topic
close $h3topic
putserv "NOTICE $nick :h3 Topic Changed to $arg"
topic_set $chan $nick
}


proc topic_set { chan nick } {
#CS
set topic_cs [open /home/crave/irc/cravebot/scripts/cstopics.log r]
set info_topiccs [read $topic_cs]
close $topic_cs

#CSS

set topic_css [open /home/crave/irc/cravebot/scripts/csstopics.log r]
set info_topiccss [read $topic_cs]
close $topic_css

#h3

set topic_h3 [open /home/crave/irc/cravebot/scripts/h3topics.log r]
set info_topich3 [read $topic_h3]
close $topic_h3

set fulltopic "$info_topiccss, $info_topiccs, $info_topich3" 
putserv "privmsg chanserv :topic $chan $fulltopic"
putserv "NOTICE $nick :Updated Topic"

}
putlog "Mult-Bots V1.0 by Saurav Pokhrel - Topics Script Loaded -"
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Where should we start, let's choose the obvious.

Code: Select all

proc topic_set { chan nick } { 
Why have u omitted things, and instead generalized the parameter declarations? These are static. You cannot arbitrarily choose what to receive, as doing so destroys symbolic correlation. Change it to look like the code below:

Code: Select all

proc topic_set {nick uhost hand chan arg} {
You must also make the changes noted below. Since you bound this procedure to the public using bind pub o|o .updatetopic topic_set, this is no longer a sub-procedure. I can also see why the parameter declarations above appear incorrect. This public binding to .updatetopic is the 'new addition', thereby corrupting parameter passing whenever it is used. Correcting this involves matching parameter ordering to the binding arguments.

Code: Select all

change all occurrences of:
topic_set $chan $nick

into:
topic_set $nick $uhost $hand $chan $arg
This corrects the problem with flawed argument/parameter passing, now we move onto the problem you will have next, concerning your variable assignments.

Code: Select all

#CS
set topic_cs [open /home/crave/irc/cravebot/scripts/cstopics.log r]
set info_topiccs [read $topic_cs]
close $topic_cs

#CSS

set topic_css [open /home/crave/irc/cravebot/scripts/csstopics.log r]
set info_topiccss [read $topic_cs]
close $topic_css

#h3

set topic_h3 [open /home/crave/irc/cravebot/scripts/h3topics.log r]
set info_topich3 [read $topic_h3]
close $topic_h3 
The above methods are problematic because your reading entire files into these variables. This induces newlines, carriage returns, etc which become enmeshed into the variable and when interpreted/messaged by the eggdrop signals the terminatation of that line. Meaning, anything your trying to display that is beyond one of those beauties is therefore made null and unprintable. You will need to use the code below to solve this if it becomes a problem, as foreach line [split $text \n] cannot be used because the topic must fit within one line.

Code: Select all

set fulltopic "[join $info_topiccss], [join $info_topiccs], [join $info_topich3]"
regsub -all {(?:\n|\r|\t|\v)} $fulltopic "" fulltopic
putserv "privmsg chanserv :topic $chan $fulltopic"
putserv "notice $nick :Updated Topic" 
The above uses a regsub to remove those things...You can substitute "gets" for "read" as I've shown below for the h3 procedure, this will make the regsub unnecessary.

Code: Select all

set info_topich3 [gets $topic_h3]
Gets behaves differently than read, as get only reads the next line from the file given by fileId and discards the terminating newline character.

Next up is this issue of curly bracing and other special tcl characters being written to the file which could throw tcl errors. This is the reason for "set fulltopic "[join $info_topiccss], [join $info_topiccs], [join $info_topich3]". The joins are needed to return from the splits we will be using below.

Code: Select all

set topic $arg
puts $h3topic $topic
close $h3topic 
Change all the above references in all 3 procedures (css,cs,h3) to resemble what I have below, keeping in mind this simply corrects h3. Obviously changes will need to be made for variable names to apply this to css and cs.

Code: Select all

puts $h3topic [split $arg]
close $h3topic 
Splitting allows you an extra layer of security if malicious users decide to 'test' the strength of the scripting by giving it senseless symbols and random characters as input. Split guarantees issue free performance, instead of crashing you bot these users will just look silly. Combined, all the above steps should rectify your issues.
e
eXcel
Voice
Posts: 13
Joined: Mon Apr 28, 2008 8:03 pm

Post by eXcel »

Wow, thank you alot. Not only did you fix my problem you explained what my errors were. Thank you very much it was a good learning experience for me :)
Post Reply