| View previous topic :: View next topic |
| Author |
Message |
eXcel Voice
Joined: 28 Apr 2008 Posts: 13
|
Posted: Wed May 14, 2008 6:42 pm Post subject: [SOLVED]Taking 3 Variables and merging to one |
|
|
Hello,
I am trying to get 3 variables to merge to one for chaning a topic.
I have this
| Code: |
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 |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Wed May 14, 2008 6:47 pm Post subject: |
|
|
| Code: | set fulltopic "$info_topiccss, $info_topiccs, $info_topich3"
putserv "privmsg chanserv :topic $chan $fulltopic" |
| Code: | 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. |
|
| Back to top |
|
 |
eXcel Voice
Joined: 28 Apr 2008 Posts: 13
|
Posted: Wed May 14, 2008 9:31 pm Post subject: |
|
|
Hmm, Well I tried that but still.
Heres what i have
| Code: |
# 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 -"
|
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Wed May 14, 2008 9:37 pm Post subject: |
|
|
Where should we start, let's choose the obvious.
| Code: | | 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: | | 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: | 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: | #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: | 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: | | 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: | 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: | 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. |
|
| Back to top |
|
 |
eXcel Voice
Joined: 28 Apr 2008 Posts: 13
|
Posted: Thu May 15, 2008 8:26 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
|
|
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
|
|