Changeset 37 for QuoteEngine


Ignore:
Timestamp:
04/16/07 04:46:13 (5 years ago)
Author:
notopic
Message:

add auto-quote-spewing stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • QuoteEngine/QuoteEngine.tcl

    r17 r37  
    3535# CHANGE ME (use blank if you're not using the PHP script) 
    3636set php_page "http://sakaki.jamesoff.net/~notopic/" 
     37 
     38# automatically spew "relevant" quotes? 
     39set quote_automatic 1 
     40 
     41# minimum number of seconds between automatic quotes 
     42set quote_automatic_minimum 7200 
    3743 
    3844# bind commands CHANGE as needed 
     
    5258bind pub "-|-" !quoteversion quote_version 
    5359bind pub "-|-" !quotehelp quote_help 
     60bind pubm "-|ov" * quote_auto 
    5461 
    5562# a user with this flag(s) can't use the script at all 
     
    6370#1.00 
    6471set quote_version "cvs" 
     72set quote_auto_last(blah) 0 
    6573 
    6674#add setting to channel 
     
    235243#   Find all quotes with "text" in them. (in random order) 
    236244#   The first 5 (by default) are listed in the channel. The rest are /msg'd to 
    237 #   you up to the maxiumum (default 5). 
     245#   you up to the maximum (default 5). 
    238246#     --all: Search all channels, not just current one 
    239247#     --channel: Search given channel 
     
    503511} 
    504512 
     513proc 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 
    505591quote_connect 
    506592putlog "QuoteEngine $quote_version loaded" 
Note: See TracChangeset for help on using the changeset viewer.