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.

bind notc not working[SOLVED]

Help for those learning Tcl or writing their own scripts.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

bind notc not working[SOLVED]

Post by ztian299 »

Hello!

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

Code: Select all

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.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

From Tcl-commands.doc:
NOTC (stackable)
bind notc <flags> <mask> <proc>
procname <nick> <user@host> <handle> <text> <dest>

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.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

hi

Post by ztian299 »

Thanks for reply that fast Sir_Fz,

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]

putserv "PRIVMSG $nick :$result"
}

bot doesn't answer, and no error output
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

It's:
procname <nick> <user@host> <handle> <text> <dest>
Notice what's wrong with your procedure's arguments.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

I'm seriously not sure. Could you give me an example that you could help me better than that one? Appreciate your help!
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

What Sir_Fz is trying to tell you is that it should look like this:

Code: Select all

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]")
NML_375
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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.

http://www.xdobry.de/mysqltcl/mysqltcl.html documents all the function calls in the mysqltcl package.
NML_375
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

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.

Code: Select all

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
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Are you rehashing after you make the changes?
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

I've tried .rehash and .restart

I'm wondering about the notice action if it really works with mysqltcl
because it worked with search in pm, but not with notice.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Could you paste the output of ".binds notc all" after triggering the command a couple of times?
NML_375
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Code: Select all

Command bindings:
  TYPE FLGS     COMMAND              HITS BINDING (TCL)
  notc -|-           search                    0    notice:search
This is what I get in telnet..
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Are you sure you have the correct net-type setting in your eggdrop.conf? It seems like your bot is not recognizing notices.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Here is my conf: http://pastebin.com/d42679c0

Every time I send a notice to the bot it pop-up in telnet that I try.
But nothing happen
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

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?
Post Reply