I'm trying to make a search to mysql with notice.
/notice bot1 search <site>
This is my own code and I try to learn. Searched google many hours but didn't find it useful so I decided to ask here. Appreciate help
bind notc - search notice:search
set dbhandling [mysqlexec -u root -p test123 -db search]
set sqltable "test"
proc notice:search {nick uhost handle text {dest ""}} {
global dbhandling sqltable
if {$dest == ""} {set dest $::botnick}
set site [lindex $text 0]
set result [mysqlsel $dbhandling "SELECT url FROM $sqltable WHERE site='$site' LIMIT 1" -list]
putserv "PRIVMSG $nick :$result"
}
I'm back with this problem, the bot doesn't output anything. No text, no errors[/code]
Last edited by ztian299 on Sun Apr 20, 2008 12:12 pm, edited 3 times in total.
Description: dest will be a nickname (the bot's nickname,
bviously) or a channel name. mask is matched against the entire
notice and can contain wildcards. It is considered a breach of
protocol to respond to a /notice on IRC, so this is intended for
internal use (logging, etc.) only. Note that server notices do
not trigger the NOTC bind. If the proc returns 1, Eggdrop will
not log the message that triggered this bind.
New Tcl procs should be declared as
proc notcproc {nick uhost hand text {dest ""}} {
global botnick; if {$dest == ""} {set dest $botnick}
...
}
for compatibility.
I have been looking at that one LONG time.. and have tried it but won't work!
here's the code with that!
---------------------------------
set dbhandling [mysqlexec -u root -p test123 -db search]
set sqltable "test"
bind notc - search notice:search
proc notice:search {nick uhost hand arg text {dest ""}} {
global dbhandling sqltable botnick
if {$dest == ""}
{set dest $botnick}
set site [lindex $arg 0]
set result [mysqlsel $dbhandling "SELECT url FROM $sqltable WHERE site='$site' LIMIT 1" -list]
bind notc - search notice:search
set dbhandling [mysqlexec -u root -p test123 -db search]
set sqltable "test"
proc notice:search {nick uhost handle text {dest ""}} {
global dbhandling sqltable
if {$dest == ""} {set dest $::botnick}
set site [lindex $text 0]
set result [mysqlsel $dbhandling "SELECT url FROM $sqltable WHERE site='$site' LIMIT 1" -list]
putserv "PRIVMSG $nick :$result"
}
In your first piece of code, you've mixed up the order of the parameters: The arguments you write in your notice-command (/notice search <parameters>) will always be the 4th argument.
Further on, it is a very bad idea to use lindex on strings; especially ones from untrusted sources... Use split to convert it into a list first.
(that is, change "set site [lindex $text 0]" into "set site [lindex [split $text] 0]")
Looking further, it seems you do not create a valid database-handle. You should use mysqlconnect to connect to the database, not mysqlexec. Hence, your mysqlsel command will never be able to retrieve any data from the database. I would also re-emphasis the last paragraph in my previous post - don't use lindex on strings, take the effort of converting it to a list first.
Ah, sorry..
to explain, I don't really use mysqlexec in the connect, I was to tired this morning when i wrote it on this post.. But I use mysqlconnect.
Then as you told, I could use split function with lindex.. I asked on #eggtcl @ EFnet and got the answer "set test [lindex [split $arg] 0]"
I assume you already told me that, but I will try again.
bind notc - search notice:search
set dbhandling [mysqlconnect -u root -p test123 -db search]
set sqltable "test"
proc notice:search {nick uhost handle text {dest ""}} {
global dbhandling sqltable
if {$dest == ""} {set dest $::botnick}
set site [lindex [split $text] 0]
set result [mysqlsel $dbhandling "SELECT url FROM $sqltable WHERE site='$site' LIMIT 1" -list]
putserv "PRIVMSG $nick :$result"
}
Still no reply from bot when notice
Appreciate your help. thanks
You have a custom eggdrop.conf file, I suggest you reconfigure a fresh original copy. However, you have net-type 5 set; is it the correct net-type setting for you?