Changeset 37 for QuoteEngine
- Timestamp:
- 04/16/07 04:46:13 (5 years ago)
- File:
-
- 1 edited
-
QuoteEngine/QuoteEngine.tcl (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
QuoteEngine/QuoteEngine.tcl
r17 r37 35 35 # CHANGE ME (use blank if you're not using the PHP script) 36 36 set php_page "http://sakaki.jamesoff.net/~notopic/" 37 38 # automatically spew "relevant" quotes? 39 set quote_automatic 1 40 41 # minimum number of seconds between automatic quotes 42 set quote_automatic_minimum 7200 37 43 38 44 # bind commands CHANGE as needed … … 52 58 bind pub "-|-" !quoteversion quote_version 53 59 bind pub "-|-" !quotehelp quote_help 60 bind pubm "-|ov" * quote_auto 54 61 55 62 # a user with this flag(s) can't use the script at all … … 63 70 #1.00 64 71 set quote_version "cvs" 72 set quote_auto_last(blah) 0 65 73 66 74 #add setting to channel … … 235 243 # Find all quotes with "text" in them. (in random order) 236 244 # The first 5 (by default) are listed in the channel. The rest are /msg'd to 237 # you up to the maxi umum (default 5).245 # you up to the maximum (default 5). 238 246 # --all: Search all channels, not just current one 239 247 # --channel: Search given channel … … 503 511 } 504 512 513 proc quote_auto { nick host handle channel text } { 514 global quote_automatic 515 if {$quote_automatic == 0} { 516 return 517 } 518 519 if {![channel get $channel quoteengine]} { 520 return 521 } 522 523 global quote_auto_last db_handle 524 if [info exists quote_auto_last($channel)] { 525 set diff [expr [clock seconds] - $quote_auto_last($channel)] 526 } else { 527 set diff 3601 528 set quote_auto_last($channel) 0 529 } 530 531 if {$diff < 3600} { 532 return 533 } 534 535 set words [split $text] 536 set newwords [list] 537 538 foreach word $words { 539 if [regexp -nocase {^[a-z0-9']+$} $word] { 540 if {[lsearch [list "about" "their" "there"] $word] > -1} { 541 continue 542 } 543 544 if [onchan $word] { 545 continue 546 } 547 548 if {[string length $word] > 4} { 549 lappend newwords [mysqlescape $word] 550 } 551 } 552 } 553 554 if {[llength $newwords] == 0} { 555 return 556 } 557 558 putloglev d * "quoteengine: candidate words for random quote in $channel: $newwords" 559 560 if {![quote_ping]} { 561 return 562 } 563 564 set thisword [pickRandom $newwords] 565 putloglev d * "quoteengine: using $thisword" 566 567 if {[rand 100] < 95} { 568 putloglev d * "quoteengine: not random enough, ignoring" 569 return 570 } 571 572 573 set where_clause "WHERE channel='[mysqlescape $channel]' AND quote LIKE '%$thisword%' ORDER BY RAND() LIMIT 1" 574 putloglev d * "quoteengine: $where_clause" 575 set sql "SELECT * FROM quotes $where_clause" 576 577 set result [mysqlquery $db_handle $sql] 578 if {[set row [mysqlnext $result]] != ""} { 579 set id [lindex $row 0] 580 set quote [lindex $row 3] 581 582 putlog "RANDOM QUOTE: $quote ($id)" 583 puthelp "PRIVMSG $channel :\[\002$id\002\] $quote" 584 set quote_auto_last($channel) [clock seconds] 585 } 586 mysqlendquery $result 587 588 } 589 590 505 591 quote_connect 506 592 putlog "QuoteEngine $quote_version loaded"
Note: See TracChangeset
for help on using the changeset viewer.
