# HG changeset patch # User Matti Hamalainen # Date 1315236620 -10800 # Node ID 5162abae15fd975b804c8b1fdeae1c92e72d0826 # Parent 45b76d81e25676e119e82110f3ead98755323f0b Removing obsolete scripts. diff -r 45b76d81e256 -r 5162abae15fd mndb.tcl --- a/mndb.tcl Mon Sep 05 17:08:45 2011 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,346 +0,0 @@ -########################################################################## -# -# MattiNykanenDB v0.7 by ccr/TNSP -# -# Not for public use or distribution. If you happen to find this, -# send your questions and/or problems to /dev/null, thank you. -# -########################################################################## - -### -### General options -### -# Filename where the logged quote data goes -set mndb_file "data.mndb" - -# 1 = Verbose: Say messages PUBLIC when quote is OK, bad, etc. -# 0 = Quiet : Say privately -set mndb_verbose 0 - -# 1 = Put some info to bot's Logfile when doing stuff... -# 0 = Don't. -set mndb_logmsg 1 - -# What IRC "command" should we use to send messages: -# (Valid alternatives are "PRIVMSG" and "NOTICE") -set mndb_preferredmsg "PRIVMSG" - - -### -### Search related settings -### - -# How many quote's should the !mnfind command show (maximum limit) -set mndb_showmax_pub 3 - -# For private-search, this is the default limit (user can change it) -set mndb_showmax_priv 5 - - -########################################################################## -# No need to look below this line -########################################################################## -#------------------------------------------------------------------------- -set mndb_name "MattiNykanenDB" -set mndb_version "0.7" - - -#------------------------------------------------------------------------- -### Binding initializations -bind pub - !mnfind mndb_pub_find -bind pub - !mnadd mndb_pub_add -bind pub - !mn mndb_pub_mn -bind msg - mnfind mndb_msg_find -bind msg - mn mndb_msg_mn - - -### Initialization messages -set mndb_message "$mndb_name v$mndb_version by ccr/TNSP" -putlog "$mndb_message" - - -#------------------------------------------------------------------------- -### Utility functions -proc mndb_log { jarg } { - global mndb_logmsg mndb_name - - if {$mndb_logmsg != 0} { - putlog "$mndb_name: $jarg" - } -} - - -proc mndb_ctime { utime } { - - if {$utime == "" || $utime == "*"} { - set utime 0 - } - - return [clock format $utime -format "%d.%m.%Y %H:%M"] -} - - -proc mndb_isnumber { uarg } { - set ufoo 1 - - foreach i [split $uarg {}] { - if ![string match \[0-9\] $i] {set ufoo 0} - } - - return $ufoo -} - - -proc mndb_msg {apublic anick achan amsg} { -global mndb_preferredmsg - -if {$apublic == 0} { - putserv "$mndb_preferredmsg $anick :$amsg" - } else { - putserv "$mndb_preferredmsg $achan :$anick, $amsg" - } -} - - -#------------------------------------------------------------------------- -proc mndb_add {utext unick uhost uchan upublic} { -global mndb_file - - if {[string length $utext] < 10} { - mndb_msg $upublic $unick $uchan "pyh." - return 0 - } - -### Create the database file if it does not exist yet - set fd [open $mndb_file a+] - close $fd - -### OK. The quote is valid, but let's check if we already know it. - set fd [open $mndb_file r] - set sindex 0 - set smax -1 - - while {![eof $fd]} { - gets $fd foo - incr sindex - - set foo [split $foo "|"] - set qindex [lindex $foo 0] - if {$qindex > $smax} { set smax $qindex } - } - - close $fd - -### OK, the quote was not already known and IS valid. Add it. - - incr smax - - set fd [open $mndb_file a+] - puts $fd "$smax|$utext|[unixtime]|$unick|$uhost|$uchan" - close $fd - -### Log some data - mndb_log "Added quote #$smax ($unick @ $uchan): $utext" - -### Let's report success to user - mndb_msg $upublic $unick $uchan "tietokantaa sörkitty (#$smax / $sindex), kiitos." - - return 1 -} - - -#------------------------------------------------------------------------- -proc mndb_find {ipatterns imax} { -global mndb_file - -### Search the database for pattern -### Clear the count, open the quote logfile -set iresults {} -set nresults 0 -set fd [open $mndb_file r] - -### Start searching... -while {![eof $fd]} { - -# Get one quote for inspection - gets $fd foo - set irecord [split [string tolower $foo] "|"] - set itext [lindex $irecord 1] - set iname [lindex $irecord 3] - -# Match with all given patterns and rules - set imatched 1 - - foreach ipattern $ipatterns { - - set foob [split [string tolower $ipattern] " "] - set ftoken [lindex $foob 0] - set fparam [lindex $foob 1] - set fmatch [string match $fparam $itext] - - if {($ftoken == "+") && ($fmatch == 0)} { set imatched 0 } - - if {($ftoken == "-") && ($fmatch == 1)} { set imatched 0 } - - if {($ftoken == "%") && ([string match $fparam $iname] == 0)} { set imatched 0 } - - } - -# If the all patterns matched, add to the list... - if {($imatched == 1) && ($foo != "")} { - incr nresults - lappend iresults $foo - } - - } - -# Close file -close $fd - -# Take only last imax results -return [lrange $iresults [expr $nresults-$imax] $nresults] -} - - - -#------------------------------------------------------------------------- -proc mndb_get { unick uhand uindex } { -global mndb_file - -set ifound 0 -set iindex 0 -set iresults {} -set nresults 0 - -### Create the database file if it does not exist yet -set fd [open $mndb_file a+] -close $fd - -### OK. The quote is valid, but let's check if we already know it. -set fd [open $mndb_file r] - -if {$uindex == ""} { -### Log search - mndb_log "$unick/$uhand get random quote" - -### Do search - while {![eof $fd]} { - gets $fd foo - incr nresults - lappend iresults $foo - } - - set foo [split [lindex $iresults [rand $nresults]] "|"] - set ifound 1 - -} else { -### Log search - mndb_log "$unick/$uhand searched quote #$uindex" - -### Do search - while {![eof $fd] && !$ifound} { - gets $fd foo - set foo [split $foo "|"] - - if {[lindex $foo 0] == $uindex} { - set ifound 1 - } - } -} - -### Close file -close $fd - -### Return result -if {$ifound} { - return "#[lindex $foo 0]: [lindex $foo 1]" - } else { - return "ei löydy." - } -} - - -#------------------------------------------------------------------------- -proc mndb_search {unick uhand uchan utext upublic} { -global mndb_showmax_pub spmsg_nomatch - -### Log search - mndb_log "$unick/$uhand searched quote: $utext" - -### Parse the given command - set footokens [split $utext " "] - foreach ftoken $footokens { - set foomark [string range $ftoken 0 0] - set foopat [string range $ftoken 1 end] - - if {$foomark == "-" || $foomark == "+" || $foomark == "%"} { - lappend ipatlist "$foomark *$foopat*" - } else { - lappend ipatlist "+ *$ftoken*" - } - } - - -### Get the matches - - set iresults [mndb_find $ipatlist $mndb_showmax_pub] - -### Show the results - if {$iresults != ""} { - foreach i $iresults { - set foo [split $i "|"] - mndb_msg $upublic $unick $uchan "#[lindex $foo 0]: [lindex $foo 1]" - } - -# If no quotes were found - } else { - mndb_msg $upublic $unick $uchan "ei löydy." - } -} - - -#------------------------------------------------------------------------- -proc mndb_pub_mn {unick uhost uhand uchan utext} { - -mndb_msg 0 $uchan "" [mndb_get $unick $uhand $utext] -} - - -#------------------------------------------------------------------------- -proc mndb_msg_mn {unick uhost uhand utext} { - -mndb_msg 0 $unick "" [mndb_get $unick $uhand $utext] -} - - -#------------------------------------------------------------------------- -proc mndb_pub_add {unick uhost uhand uchan utext} { - - mndb_add $utext $unick $uhost $uchan 1 -} - - -#------------------------------------------------------------------------- -proc mndb_pub_rm {unick uhost uhand uchan utext} { - - mndb_rm $utext $unick $uhost $uchan 1 -} - - -#------------------------------------------------------------------------- -proc mndb_pub_find {unick uhost uhand uchan utext} { - - mndb_search $unick $uhand $uchan $utext 1 -} - - -#------------------------------------------------------------------------- -proc mndb_msg_find {unick uhost uhand utext} { - - mndb_search $unick $uhand "" $utext 0 -} - - -#------------------------------------------------------------------------- - -# end of script diff -r 45b76d81e256 -r 5162abae15fd spededb.tcl --- a/spededb.tcl Mon Sep 05 17:08:45 2011 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,347 +0,0 @@ -########################################################################## -# -# SpedeDB v0.7 by ccr/TNSP -# -# Not for public use or distribution. If you happen to find this, -# send your questions and/or problems to /dev/null, thank you. -# -########################################################################## - -### -### General options -### -# Filename where the logged SPEDE data goes -set spdb_file "data.spededb" - -# 1 = Verbose: Say messages PUBLIC when SPEDE is OK, bad, etc. -# 0 = Quiet : Say privately -set spdb_verbose 0 - -# 1 = Put some info to bot's Logfile when doing stuff... -# 0 = Don't. -set spdb_logmsg 1 - -# What IRC "command" should we use to send messages: -# (Valid alternatives are "PRIVMSG" and "NOTICE") -set spdb_preferredmsg "PRIVMSG" - - -### -### Search related settings -### - -# How many SPEDE's should the !spedefind command show (maximum limit) -set spdb_showmax_pub 3 - -# For private-search, this is the default limit (user can change it) -set spdb_showmax_priv 5 - - -########################################################################## -# No need to look below this line -########################################################################## -#------------------------------------------------------------------------- -set spdb_name "SpedeDB" -set spdb_version "0.7" - - -#------------------------------------------------------------------------- -### Binding initializations -bind pub - !spedefind spdb_pub_find -bind pub - !spedeadd spdb_pub_add -bind pub - !spede spdb_pub_spede -bind msg - spedefind spdb_msg_find -bind msg - spede spdb_msg_spede - - -### Initialization messages -set spdb_message "$spdb_name v$spdb_version by ccr/TNSP" -putlog "$spdb_message" - - -#------------------------------------------------------------------------- -### Utility functions -proc spdb_log { jarg } { - global spdb_logmsg spdb_name - - if {$spdb_logmsg != 0} { - putlog "$spdb_name: $jarg" - } -} - - -proc spdb_ctime { utime } { - - if {$utime == "" || $utime == "*"} { - set utime 0 - } - - return [clock format $utime -format "%d.%m.%Y %H:%M"] -} - - -proc spdb_isnumber { uarg } { - set ufoo 1 - - foreach i [split $uarg {}] { - if ![string match \[0-9\] $i] {set ufoo 0} - } - - return $ufoo -} - - -proc spdb_msg {apublic anick achan amsg} { -global spdb_preferredmsg - -if {$apublic == 0} { - putserv "$spdb_preferredmsg $anick :$amsg" - } else { - putserv "$spdb_preferredmsg $achan :$anick, $amsg" - } -} - - -#------------------------------------------------------------------------- -proc spdb_add {utext unick uhost uchan upublic} { -global spdb_file - - -if {"x$utext" == "x"} { - spdb_msg $upublic $unick $uchan "pyh." - return 0 - } - -### Create the database file if it does not exist yet - set fd [open $spdb_file a+] - close $fd - -### OK. The SPEDE is valid, but let's check if we already know it. - set fd [open $spdb_file r] - set sindex 0 - set smax -1 - - while {![eof $fd]} { - gets $fd foo - incr sindex - - set foo [split $foo "|"] - set qindex [lindex $foo 0] - if {$qindex > $smax} { set smax $qindex } - } - - close $fd - -### OK, the SPEDE was not already known and IS valid. Add it. - - incr smax - - set fd [open $spdb_file a+] - puts $fd "$smax|$utext|[unixtime]|$unick|$uhost|$uchan" - close $fd - -### Log some data - spdb_log "Added SPEDE #$smax ($unick @ $uchan): $utext" - -### Let's report success to user - spdb_msg $upublic $unick $uchan "tietokantaa sörkitty (#$smax / $sindex), kiitos." - - return 1 -} - - -#------------------------------------------------------------------------- -proc spdb_find {ipatterns imax} { -global spdb_file - -### Search the database for pattern -### Clear the count, open the SPEDE logfile -set iresults {} -set nresults 0 -set fd [open $spdb_file r] - -### Start searching... -while {![eof $fd]} { - -# Get one SPEDE for inspection - gets $fd foo - set irecord [split [string tolower $foo] "|"] - set itext [lindex $irecord 1] - set iname [lindex $irecord 3] - -# Match with all given patterns and rules - set imatched 1 - - foreach ipattern $ipatterns { - - set foob [split [string tolower $ipattern] " "] - set ftoken [lindex $foob 0] - set fparam [lindex $foob 1] - set fmatch [string match $fparam $itext] - - if {($ftoken == "+") && ($fmatch == 0)} { set imatched 0 } - - if {($ftoken == "-") && ($fmatch == 1)} { set imatched 0 } - - if {($ftoken == "%") && ([string match $fparam $iname] == 0)} { set imatched 0 } - - } - -# If the all patterns matched, add to the list... - if {($imatched == 1) && ($foo != "")} { - incr nresults - lappend iresults $foo - } - - } - -# Close file -close $fd - -# Take only last imax results -return [lrange $iresults [expr $nresults-$imax] $nresults] -} - - - -#------------------------------------------------------------------------- -proc spdb_get { unick uhand uindex } { -global spdb_file - -set ifound 0 -set iindex 0 -set iresults {} -set nresults 0 - -### Create the database file if it does not exist yet -set fd [open $spdb_file a+] -close $fd - -### OK. The SPEDE is valid, but let's check if we already know it. -set fd [open $spdb_file r] - -if {$uindex == ""} { -### Log search - spdb_log "$unick/$uhand get random SPEDE" - -### Do search - while {![eof $fd]} { - gets $fd foo - incr nresults - lappend iresults $foo - } - - set foo [split [lindex $iresults [rand $nresults]] "|"] - set ifound 1 - -} else { -### Log search - spdb_log "$unick/$uhand searched SPEDE #$uindex" - -### Do search - while {![eof $fd] && !$ifound} { - gets $fd foo - set foo [split $foo "|"] - - if {[lindex $foo 0] == $uindex} { - set ifound 1 - } - } -} - -### Close file -close $fd - -### Return result -if {$ifound} { - return "#[lindex $foo 0]: [lindex $foo 1] ([lindex $foo 3])" - } else { - return "ei löydy." - } -} - - -#------------------------------------------------------------------------- -proc spdb_search {unick uhand uchan utext upublic} { -global spdb_showmax_pub spmsg_nomatch - -### Log search - spdb_log "$unick/$uhand searched SPEDE: $utext" - -### Parse the given command - set footokens [split $utext " "] - foreach ftoken $footokens { - set foomark [string range $ftoken 0 0] - set foopat [string range $ftoken 1 end] - - if {$foomark == "-" || $foomark == "+" || $foomark == "%"} { - lappend ipatlist "$foomark *$foopat*" - } else { - lappend ipatlist "+ *$ftoken*" - } - } - - -### Get the matches - - set iresults [spdb_find $ipatlist $spdb_showmax_pub] - -### Show the results - if {$iresults != ""} { - foreach i $iresults { - set foo [split $i "|"] - spdb_msg $upublic $unick $uchan "#[lindex $foo 0]: [lindex $foo 1] ([lindex $foo 3] @ [spdb_ctime [lindex $foo 2]])" - } - -# If no SPEDEs were found - } else { - spdb_msg $upublic $unick $uchan "ei löydy." - } -} - - -#------------------------------------------------------------------------- -proc spdb_pub_spede {unick uhost uhand uchan utext} { - -spdb_msg 0 $uchan "" [spdb_get $unick $uhand $utext] -} - - -#------------------------------------------------------------------------- -proc spdb_msg_spede {unick uhost uhand utext} { - -spdb_msg 0 $unick "" [spdb_get $unick $uhand $utext] -} - - -#------------------------------------------------------------------------- -proc spdb_pub_add {unick uhost uhand uchan utext} { - - spdb_add $utext $unick $uhost $uchan 1 -} - - -#------------------------------------------------------------------------- -proc spdb_pub_rm {unick uhost uhand uchan utext} { - - spdb_rm $utext $unick $uhost $uchan 1 -} - - -#------------------------------------------------------------------------- -proc spdb_pub_find {unick uhost uhand uchan utext} { - - spdb_search $unick $uhand $uchan $utext 1 -} - - -#------------------------------------------------------------------------- -proc spdb_msg_find {unick uhost uhand utext} { - - spdb_search $unick $uhand "" $utext 0 -} - - -#------------------------------------------------------------------------- - -# end of script