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

Post by Sir_Fz »

You meant

Code: Select all

proc notice:search {nick uhost handle text {dest ""}} {
 global dbhandling sqltable chan2 sqltable2
 if {$dest == ""} {set dest $::botnick}

 # check if nick is on #chan

 if {[onchan $nick $kanal2]} {
  set site [lindex [split $text] 1]

  # mysql...

  set result [mysqlsel $dbhandling "SELECT url FROM $sqltable WHERE site='$site' LIMIT 1" -list]

  foreach url $result {
   mysqlexec $dbhandling "DELETE FROM $sqltable WHERE url='$url'"
   mysqlexec $dbhandling "INSERT INTO $sqltable2 (site, url) VALUES ('$site', '$url')"
   putserv "PRIVMSG $nick :$url"
   putlog "$site searched by $nick"
   putlog "$site moved $sqltable -> $sqltable2"
  }
 }
}
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

I thought it was necessary to use two foreach.

Example:

Code: Select all

timer 10 [list
 mysqlexec $dbhandling "DELETE FROM $sqltable2 WHERE url='$url'"
 mysqlexec $dbhandling "INSERT INTO $sqltable (site, url, nick) VALUES ('$site', '$url', '$nick')"]
Will not work because timer can't do both(I heard).
I got two options:
-make timer in a proc
-make timer again under DELETE.
What is best? I writed this:

Code: Select all

proc timer:notice {nick uhost handle arg} {
global dbhandling sqltable sqltable2

timer 10 [list mysqlexec $dbhandling "DELETE FROM $sqltable2 WHERE url='$url'"]
putlog "deleted from $sqltable2"

timer 10 [list mysqlexec $dbhandling "INSERT INTO $sqltable (site, url) VALUES ('$site', '$url')"]
putlog "added to $sqltable"
}
I'm trying, but don't know if this is working?
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 more optimal to create a new procedure.

Code: Select all

proc sql:insert {nick site url} {
 global dbhandling
 mysqlexec $dbhandling "DELETE FROM $sqltable2 WHERE url='$url'"
 mysqlexec $dbhandling "INSERT INTO $sqltable (site, url, nick) VALUES ('$site', '$url', '$nick')"
}
and just call the timer like this

Code: Select all

timer 10 [list sql:insert $nick $site $url]
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Can I ask what command that tells the proc sql:insert to execute those lines?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

ztian299 wrote:Can I ask what command that tells the proc sql:insert to execute those lines?
What do you meant "what command?" it's called within the timer if that's what you mean.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Code: Select all

proc notice:search {nick uhost handle text {dest ""}} {
 global dbhandling sqltable chan2 sqltable2
 if {$dest == ""} {set dest $::botnick}

 # check if nick is on #chan

 if {[onchan $nick $kanal2]} {
  set site [lindex [split $text] 1]

  # mysql...

  set result [mysqlsel $dbhandling "SELECT url FROM $sqltable WHERE site='$site' LIMIT 1" -list]

  foreach url $result {
   mysqlexec $dbhandling "DELETE FROM $sqltable WHERE url='$url'"
   mysqlexec $dbhandling "INSERT INTO $sqltable2 (site, url) VALUES ('$site', '$url')"
   putserv "PRIVMSG $nick :$url"
   putlog "$site searched by $nick"
   putlog "$site moved $sqltable -> $sqltable2"
  }
 }
}

Code: Select all

proc sql:insert {nick site url} {
global dbhandling
 mysqlexec $dbhandling "DELETE FROM $sqltable2 WHERE url='$url'"
 mysqlexec $dbhandling "INSERT INTO $sqltable (site, url, nick) VALUES ('$site', '$url', '$nick')"
timer 1 [list sql:insert $nick $site $url]
putlog "DONE"
}
How does proc sql:insert work since not any variables or anything call it?

Sorry about confusing questions. But this part is getting hard :oops:
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Your failing to understand how tcl works entirely.

Code: Select all

timer 1 [list sql:insert $nick $site $url] 
This calls sql:insert if it is OUTSIDE any procedure and left in global space, it will be executed once and start the sql:insert procedure You can then place an additional timer calling sql:insert inside the actual sql:insert procedure so that this behavior will keep occuring at regular intervals. Understand?
Last edited by speechles on Sat Apr 26, 2008 2:00 pm, edited 1 time 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 »

You're not being clear about what you want, I guess you want this:

Code: Select all

proc notice:search {nick uhost handle text {dest ""}} {
 global dbhandling sqltable chan2 sqltable2
 if {$dest == ""} {set dest $::botnick}

 # check if nick is on #chan

 if {[onchan $nick $kanal2]} {
  set site [lindex [split $text] 1]

  # mysql...

  set result [mysqlsel $dbhandling "SELECT url FROM $sqltable WHERE site='$site' LIMIT 1" -list]

  foreach url $result {
   timer 10 [list sql:insert $nick $url $site]
   putserv "PRIVMSG $nick :$url"
   putlog "$site searched by $nick"
  }
 }
}

proc sql:insert {nick url site} {
 global dbhandling sqltable sqltable2
 mysqlexec $dbhandling "DELETE FROM $sqltable WHERE url='$url'"
 mysqlexec $dbhandling "INSERT INTO $sqltable2 (site, url, nick) VALUES ('$site', '$url', '$nick')"
 putlog "$site moved $sqltable -> $sqltable2"
}
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

When I see the code Sir_Fz pasted it answer all my answers.
I'm probably not that good to ask questions!
Thanks for explanation speechles..
I asked how the timer could be executed.. In the answer I was hoping to get this.
I appreciate your guys help, I'm sorry for my bad ass questions
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

I continue.. I need to set how many times people can search, and if exceed ignore for 6hours!

I'm not sure how the "if exceed" would be done. Help appreciated
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Search for 'throttled'.
z
ztian299
Halfop
Posts: 59
Joined: Sat Apr 19, 2008 4:57 pm
Location: *.no

Post by ztian299 »

Right, tried to find some doc on throttled but nothing.
I have searched throttled. but didn't find anything about restriction?
because i need search restriction for my script
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

See this thread:
http://forum.egghelp.org/viewtopic.php?t=9009&start=3
Use the new function this creates as I have below:

Code: Select all

 If {[throttled $id $duration]} {return 0} else {#something}
$id = unique identifier for each individual, you tailor this to your whims
$duration = amount in seconds to ignore the user after their initial request.
Post Reply