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] Retrieving replies from mysql gives unexpected ...

Help for those learning Tcl or writing their own scripts.
Post Reply
D
DjSlash
Voice
Posts: 8
Joined: Wed Jul 29, 2009 7:12 am
Location: Groningen, Netherlands
Contact:

[SOLVED] Retrieving replies from mysql gives unexpected ...

Post by DjSlash »

Hi all,

I'm playing with an idea I have for a while and I'm using the mysql module from BarkerJr for it. I have made a script that makes bindings according to the stuff in the database. Since it is just an experiment, I didn't put much tought to it. However, what's been bugging me for a couple of hours now is that I don't get the expected result from what I have right now.

This is the code:

Code: Select all

proc tb:respond { nick uhost hand chan arg binding} {
        global talkbot
        mysql_connect $talkbot(db_name) $talkbot(db_host) $talkbot(db_uname) $talkbot(db_pass)
        set respond_query "SELECT reply FROM talkbot WHERE binding = '$binding' ORDER BY RAND() LIMIT 1"
        set result [mysql_query $respond_query]
        if {[mysql_affected_rows] < 1} {
                putlog "TalkBot MySQL error: $result ([mysql_errno])"
                return 0
        } else {
                set reply [lindex [lindex $result 0] 0]
                putserv "privmsg $chan :$reply"
        }
}
This is what I have in the database:

Code: Select all

mysql> select reply from talkbot where binding = 'test';
+---------------------+
| reply               |
+---------------------+
| \001ACTION test\001 |
+---------------------+
1 row in set (0.00 sec)
This should make the bot do an action, however this is what I get:

Code: Select all

23:41 <@DjSlash> !test
23:41 <@StatsBot> \001ACTION test\001
I've been trying all kinds of things, but the result remains the same. Any ideas?
Last edited by DjSlash on Tue Aug 31, 2010 6:00 pm, edited 1 time in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

You'll need to use the subst command if you'd like the escape-sequences to be substituted properly. Most likely, you'll want to use the -nocommands -novariables options to prevent unintended injections.
NML_375
D
DjSlash
Voice
Posts: 8
Joined: Wed Jul 29, 2009 7:12 am
Location: Groningen, Netherlands
Contact:

Post by DjSlash »

ahhh, ofcourse. Thanks NML!

PS, your signature isn't correct ;)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Well, my poor linux system had a fatal filesystem/harddrive crash some week ago.. Thus I havn't gotten 'round starting up my idling client yet...
NML_375
Post Reply