aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lilykarma.tcl116
1 files changed, 58 insertions, 58 deletions
diff --git a/lilykarma.tcl b/lilykarma.tcl
index bac2de1..133fa5c 100644
--- a/lilykarma.tcl
+++ b/lilykarma.tcl
@@ -1,13 +1,13 @@
# IRC Karma for Eggdrops by Lily (lily@disorg.net)
-# This is a Karma database script for Eggdrop bots.
-# It has flood control built in, and basic self-karma prevention.
-# Requires TCL8.4 or greater, and the sqlite3 tcl lib. (not mysql!)
-# For deb/ubuntu, that is the libsqlite3-tcl package. Adjust for your flavor.
-# !! 3.x USERS PLEASE NOTE!!! The database change for 4.x means that unless
+# This is a Karma database script for Eggdrop bots.
+# It has flood control built in, and basic self-karma prevention.
+# Requires TCL8.4 or greater, and the sqlite3 tcl lib. (not mysql!)
+# For deb/ubuntu, that is the libsqlite3-tcl package. Adjust for your flavor.
+# !! 3.x USERS PLEASE NOTE!!! The database change for 4.x means that unless
# you manually edit your db, you will have to start over. Sorry! You may not want
-# karma entropy and expiry anyway, and thats the big new feature here.
+# karma entropy and expiry anyway, and thats the big new feature here.
# 1.0 - self karma prevention
-# 2.0 - flood control, maries mods added
+# 2.0 - flood control, maries mods added
# 2.5 - command triggers fixed, extra commands removed. comments added. 20101220
# 3.0 - converted to sqlite. code cleanup. 20111030
# 3.1 - search and help. 20111104
@@ -15,22 +15,22 @@
# 4.0 - added db timestamping and karma expiry, changed scoring update loop. 20120828
# 4.1 - karma entropy 20120903
# 4.2 - !instant changes a random thing -/+1 , !random returns things. 20120905
-# 4.3 - locked text change, faster decay for high vals, trim item whitespace 20130215
+# 4.3 - locked text change, faster decay for high vals, trim item whitespace 20130215
# 4.4 - Immortal karma (user request). Expanded stats. Fixes (locked text, high val decay) 20130526
# 4.5 - strip ASCII codes from input. 20211221
-# TODO - randomize days a little on entropy
+# TODO - randomize days a little on entropy
### Usage ###
-# Once you have loaded this from your bots config and rehashed it,
+# Once you have loaded this from your bots config and rehashed it,
# do: .chanset #yourchannel +lkarma
# In your channel you can "!<item>++" and "!<item>--" with any word or phrase.
-# "!good" and "!bad" return the top (and bottom) ten. "!khelp" for help.
-# "!lfind" returns locked items. "!ifind" returns immortalized items.
-# "!karma <item>" for score. "!stats" for total items and average karma (unlocked items).
+# "!good" and "!bad" return the top (and bottom) ten. "!khelp" for help.
+# "!lfind" returns locked items. "!ifind" returns immortalized items.
+# "!karma <item>" for score. "!stats" for total items and average karma (unlocked items).
# "!find <item>" and "!rfind <item>" to search for things in the database.
# "!instant" changes a random thing -/+1 , "!random" returns some items.
# Privileged users can "!lock <item>", "!unlock <item>", and "!delete <item>"
-# They can also "!immortalize <item>" and remove it from entropy. Cannot be unset.
+# They can also "!immortalize <item>" and remove it from entropy. Cannot be unset.
### Settings ###
@@ -54,7 +54,7 @@ set karma(version) "4.5"
setudef flag lkarma
package require sqlite3
set kdbfile "./lkarma.db"
-if {![file exists $kdbfile]} {
+if {![file exists $kdbfile]} {
sqlite3 kdb $kdbfile
kdb eval {CREATE TABLE lkarma(item TEXT NOT NULL COLLATE NOCASE, karma INTEGER NOT NULL, locked TEXT NOT NULL default 'N', modtime INTEGER NOT NULL)}
kdb close
@@ -65,11 +65,11 @@ bind pubm $karma(flags) "% *++" fixkarma
proc fixkarma {nick uhost hand chan text} {
global karma kdbfile kfcount kfflood
- if {[string match "*+lkarma*" [channel info $chan]]} {
+ if {[string match "*+lkarma*" [channel info $chan]]} {
set uhost [string tolower $uhost]
set acct [getaccount $nick]
set hand [finduser -account $acct]
- set chan [string tolower $chan]
+ set chan [string tolower $chan]
set item [string range $text 0 [expr [string length $text] -3]]
set item [stripcodes bcruag $item]
set item [string trim $item]
@@ -94,15 +94,15 @@ proc fixkarma {nick uhost hand chan text} {
set scoring +1
} elseif {[string match "--" $score]} {
set scoring -1
- }
+ }
- if {[kdb eval {SELECT locked FROM lkarma WHERE item=$item}] == "Y"} {
+ if {[kdb eval {SELECT locked FROM lkarma WHERE item=$item}] == "Y"} {
set lockedk [kdb eval {SELECT karma FROM lkarma WHERE item=$item}]
puthelp "NOTICE $chan :\[karma\] '$item' now has $lockedk karma!"
if {[string match "++" $score]} {
puthelp "PRIVMSG $karma(logchan) :\[karma\] $nick!$uhost ($acct) ++'d locked '$item' in $chan - score: $lockedk"
} elseif {[string match "--" $score]} {
- puthelp "PRIVMSG $karma(logchan) :\[karma\] $nick!$uhost ($acct) --'d locked '$item' in $chan - score: $lockedk"
+ puthelp "PRIVMSG $karma(logchan) :\[karma\] $nick!$uhost ($acct) --'d locked '$item' in $chan - score: $lockedk"
}
return 0
}
@@ -116,7 +116,7 @@ proc fixkarma {nick uhost hand chan text} {
if {[string match "++" $score]} {
puthelp "PRIVMSG $karma(logchan) :\[karma\] *ignored - flood* $nick!$uhost ($acct) ++'d '$item' in $chan"
} elseif {[string match "--" $score]} {
- puthelp "PRIVMSG $karma(logchan) :\[karma\] *ignored - flood* $nick!$uhost ($acct) --'d '$item' in $chan"
+ puthelp "PRIVMSG $karma(logchan) :\[karma\] *ignored - flood* $nick!$uhost ($acct) --'d '$item' in $chan"
}
return 0
}
@@ -126,7 +126,7 @@ proc fixkarma {nick uhost hand chan text} {
# if {[string match "++" $score]} {
# puthelp "PRIVMSG $karma(logchan) :\[karma\] *ignored - starts with !* $nick!$uhost ($acct) ++'d '$item' in $chan"
# } elseif {[string match "--" $score]} {
- # puthelp "PRIVMSG $karma(logchan) :\[karma\] *ignored - starts with !* $nick!$uhost ($acct) --'d '$item' in $chan"
+ # puthelp "PRIVMSG $karma(logchan) :\[karma\] *ignored - starts with !* $nick!$uhost ($acct) --'d '$item' in $chan"
# }
# return 0
#}
@@ -142,22 +142,22 @@ proc fixkarma {nick uhost hand chan text} {
if {[string match "++" $score]} {
puthelp "PRIVMSG $karma(logchan) :\[karma\] *ignored - is a known bot* $nick!$uhost ($acct) ++'d '$item' in $chan"
} elseif {[string match "--" $score]} {
- puthelp "PRIVMSG $karma(logchan) :\[karma\] *ignored - is a known bot* $nick!$uhost ($acct) --'d '$item' in $chan"
+ puthelp "PRIVMSG $karma(logchan) :\[karma\] *ignored - is a known bot* $nick!$uhost ($acct) --'d '$item' in $chan"
}
return 0
}
}
-
+
incr kfcount($uhost)
set ktime [clock seconds]
-
+
if {[llength [kdb eval {SELECT karma FROM lkarma WHERE item=$item}]] == 0} {
kdb eval {INSERT INTO lkarma (item,karma,modtime) VALUES ($item,0,$ktime)}
- }
-
+ }
+
if {[kdb eval {SELECT karma FROM lkarma WHERE item=$item}] < 900} {
kdb eval {UPDATE lkarma SET karma=karma+$scoring, modtime=$ktime WHERE item=$item}
- } {
+ } {
kdb eval {UPDATE lkarma SET karma=karma+$scoring WHERE item=$item}
}
set newkarma [kdb eval {SELECT karma FROM lkarma WHERE item=$item}]
@@ -165,9 +165,9 @@ proc fixkarma {nick uhost hand chan text} {
if {[string match "++" $score]} {
puthelp "PRIVMSG $karma(logchan) :\[karma\] $nick!$uhost ($acct) ++'d '$item' in $chan - new score: $newkarma"
} elseif {[string match "--" $score]} {
- puthelp "PRIVMSG $karma(logchan) :\[karma\] $nick!$uhost ($acct) --'d '$item' in $chan - new score: $newkarma"
+ puthelp "PRIVMSG $karma(logchan) :\[karma\] $nick!$uhost ($acct) --'d '$item' in $chan - new score: $newkarma"
}
- kdb close
+ kdb close
}
}
@@ -188,13 +188,13 @@ proc checkkarma {nick uhost hand chan text} {
global karma kdbfile
if {[string match "" $text]} {
set text $nick
- }
+ }
set item [string trim $text]
sqlite3 kdb $kdbfile
set current [kdb eval {SELECT karma FROM lkarma WHERE item=$item}]
if {[llength $current] == 0} {
set current 0
- }
+ }
if {[kdb eval {SELECT locked FROM lkarma WHERE item=$item}] == "Y"} {
puthelp "NOTICE $chan :\[karma\] \"$item\"\ is locked at \002$current\002."
} else {
@@ -202,7 +202,7 @@ proc checkkarma {nick uhost hand chan text} {
}
if {[kdb eval {SELECT locked FROM lkarma WHERE item=$item}] == "U"} {
puthelp "NOTICE $chan :\[karma\] \"$item\" has been immortalized"
- }
+ }
kdb close
}
}
@@ -218,10 +218,10 @@ proc karmastats {nick uhost hand chan text} {
set gcount [kdb eval {SELECT COUNT(*) FROM lkarma WHERE karma > 0 AND locked='N'}]
set bcount [kdb eval {SELECT COUNT(*) FROM lkarma WHERE karma < 0 AND locked='N'}]
set total [kdb eval {SELECT COUNT(*) FROM lkarma}]
- set average [kdb eval {SELECT AVG(karma) FROM lkarma WHERE locked='N'}]
+ set average [kdb eval {SELECT AVG(karma) FROM lkarma WHERE locked='N'}]
set average [expr round($average)]
- puthelp "NOTICE $chan :\[karma\] stats: $total items in the database. good: $gcount, bad: $bcount, average karma: $average"
- kdb close
+ puthelp "NOTICE $chan :\[karma\] stats: $total items in the database. good: $gcount, bad: $bcount, average karma: $average"
+ kdb close
}
}
@@ -263,12 +263,12 @@ proc badkarma {nick uhost hand chan text} {
# if {[string match "*+lkarma*" [channel info $chan]]} {
# sqlite3 kdb $kdbfile
# set lcount [kdb eval {SELECT COUNT(*) FROM lkarma WHERE locked='Y'}]
-# if {$lcount != 0} {
+# if {$lcount != 0} {
# foreach {item score} [kdb eval {SELECT item,karma FROM lkarma WHERE locked='Y' ORDER BY karma DESC} ] {
# append outvar "$item:\002$score\002 "
# }
# puthelp "NOTICE $chan :\[karma\] \002$lcount\002 locked items: $outvar"
-# } {
+# } {
# puthelp "NOTICE $chan :\[karma\] there are no locked items."
# }
# kdb close
@@ -283,14 +283,14 @@ proc badkarma {nick uhost hand chan text} {
# if {[string match "*+lkarma*" [channel info $chan]]} {
# sqlite3 kdb $kdbfile
# set icount [kdb eval {SELECT COUNT(*) FROM lkarma WHERE locked='U'}]
-# if {$icount != 0} {
+# if {$icount != 0} {
# foreach {item score} [kdb eval {SELECT item,karma FROM lkarma WHERE locked='U' ORDER BY karma DESC} ] {
# append outvar "$item:\002$score\002 "
# }
# puthelp "NOTICE $chan :\[karma\] \002$icount\002 immortal items: $outvar"
-# } {
+# } {
# puthelp "NOTICE $chan :\[karma\] there are no immortal items."
-# }
+# }
# kdb close
# }
#}
@@ -316,7 +316,7 @@ proc randkarma {nick uhost hand chan text} {
# global karma kdbfile kfcount kfflood
# if {[string match "*+lkarma*" [channel info $chan]]} {
# set uhost [string tolower $uhost]
-# set chan [string tolower $chan]
+# set chan [string tolower $chan]
# sqlite3 kdb $kdbfile
# if {![info exists kfcount($uhost:$chan)]} {
# set kfcount($uhost:$chan) 0
@@ -325,7 +325,7 @@ proc randkarma {nick uhost hand chan text} {
# puthelp "PRIVMSG $chan :Please dont flood karma, $nick, try again later."
# return 0
# }
-# incr kfcount($uhost:$chan)
+# incr kfcount($uhost:$chan)
# lappend choices "+1" "-1"
# set scoring [lindex $choices [expr {int(rand()*[llength $choices])}]]
# putlog "$scoring instant karma randomly selected"
@@ -334,7 +334,7 @@ proc randkarma {nick uhost hand chan text} {
# set rando [kdb onecolumn {SELECT item FROM lkarma WHERE locked='N' ORDER BY RANDOM() LIMIT 1}]
# kdb eval {UPDATE lkarma SET karma=karma+$scoring, modtime=$ktime WHERE item=$rando}
# set newkarma [kdb eval {SELECT karma FROM lkarma WHERE item=$rando}]
-# puthelp "PRIVMSG $chan :Karma for \002$rando\002 is now \002$newkarma\002."
+# puthelp "PRIVMSG $chan :Karma for \002$rando\002 is now \002$newkarma\002."
# kdb close
# }
#}
@@ -357,8 +357,8 @@ proc findkarma {nick uhost hand chan text} {
if {$scount < 9 } {
foreach {item score} [kdb eval {SELECT item,karma FROM lkarma WHERE item LIKE $spatrn ORDER BY karma DESC LIMIT 0,9}] {
append sreturn "$item: '$score' "
- }
- puthelp "NOTICE $chan :\[karma\] $scount matches for '$word': $sreturn"
+ }
+ puthelp "NOTICE $chan :\[karma\] $scount matches for '$word': $sreturn"
} {
foreach {item score} [kdb eval {SELECT item,karma FROM lkarma WHERE item LIKE $spatrn ORDER BY karma DESC LIMIT 0,10}] {
append spos "$item: $score "
@@ -366,7 +366,7 @@ proc findkarma {nick uhost hand chan text} {
puthelp "NOTICE $chan :\[karma\] $scount matches for '$word'. top 10 matches: $spos"
}
}
- kdb close
+ kdb close
}
}
}
@@ -389,16 +389,16 @@ proc rfindkarma {nick uhost hand chan text} {
if {$scount < 9 } {
foreach {item score} [kdb eval {SELECT item,karma FROM lkarma WHERE item LIKE $spatrn ORDER BY karma ASC LIMIT 0,9}] {
append sreturn "$item: $score "
- }
- puthelp "NOTICE $chan :\[karma\] $scount matches for '$word': $sreturn"
+ }
+ puthelp "NOTICE $chan :\[karma\] $scount matches for '$word': $sreturn"
} {
foreach {item score} [kdb eval {SELECT item,karma FROM lkarma WHERE item LIKE $spatrn ORDER BY karma ASC LIMIT 0,10}] {
append sneg "$item: $score "
}
- puthelp "NOTICE $chan :\[karma\] $scount matches for '$word'. bottom 10 matches: $sneg"
+ puthelp "NOTICE $chan :\[karma\] $scount matches for '$word'. bottom 10 matches: $sneg"
}
}
- kdb close
+ kdb close
}
}
}
@@ -497,7 +497,7 @@ proc rfindkarma {nick uhost hand chan text} {
# } {
# kdb eval {DELETE FROM lkarma WHERE item=$item}
# puthelp "NOTICE $chan :\[karma\] \002$item\002 deleted."
-# }
+# }
# }
# kdb close
# }
@@ -512,7 +512,7 @@ proc karmaupdate {} {
# global kdbfile
# sqlite3 kdb $kdbfile
# set kutime [clock seconds]
-## plus/minus 1 to 5 days to kutime at random here? or in each loop?
+## plus/minus 1 to 5 days to kutime at random here? or in each loop?
#
# set xtime [expr $kutime - (90 * 86400)]
# kdb eval {DELETE FROM lkarma WHERE modtime < $xtime AND karma between -1 and 1 and locked='N'}
@@ -525,16 +525,16 @@ proc karmaupdate {} {
#
# set yytime [expr $kutime - (7 * 86400)]
# kdb eval {UPDATE lkarma SET karma=karma-1, modtime=$kutime WHERE modtime < $yytime AND karma between 55 and 80 AND locked='N'}
-# kdb eval {UPDATE lkarma SET karma=karma+1, modtime=$kutime WHERE modtime < $yytime AND karma between -80 and -55 AND locked='N'}
+# kdb eval {UPDATE lkarma SET karma=karma+1, modtime=$kutime WHERE modtime < $yytime AND karma between -80 and -55 AND locked='N'}
#
# set yyytime [expr $kutime - (2 * 86400)]
# kdb eval {UPDATE lkarma SET karma=karma-1, modtime=$kutime WHERE modtime < $yyytime AND karma between 81 and 120 AND locked='N'}
-# kdb eval {UPDATE lkarma SET karma=karma+1, modtime=$kutime WHERE modtime < $yyytime AND karma between -120 and -81 AND locked='N'}
+# kdb eval {UPDATE lkarma SET karma=karma+1, modtime=$kutime WHERE modtime < $yyytime AND karma between -120 and -81 AND locked='N'}
#
# set ztime [expr $kutime - 86400]
# kdb eval {UPDATE lkarma SET karma=karma-1, modtime=$kutime WHERE modtime < $ztime AND karma between 121 and 540 AND locked='N'}
# kdb eval {UPDATE lkarma SET karma=karma+1, modtime=$kutime WHERE modtime < $ztime AND karma between -540 and -121 AND locked='N'}
-#
+#
# set zztime [expr $kutime - (86400 / 3)]
# kdb eval {UPDATE lkarma SET karma=karma-1, modtime=$kutime WHERE modtime < $zztime AND karma between 541 and 959 AND locked='N'}
# kdb eval {UPDATE lkarma SET karma=karma+1, modtime=$kutime WHERE modtime < $zztime AND karma between -959 and -541 AND locked='N'}
@@ -542,8 +542,8 @@ proc karmaupdate {} {
# set zzztime [expr $kutime - (86400 / 5)]
# kdb eval {UPDATE lkarma SET karma=karma-1, modtime=$kutime WHERE modtime < $zzztime AND karma > 960 AND locked='N'}
# kdb eval {UPDATE lkarma SET karma=karma+1, modtime=$kutime WHERE modtime < $zzztime AND karma < -960 AND locked='N'}
-#
-# kdb close
+#
+# kdb close
}
proc kfreset {} {