| 1 | # bMotion - Mood handling |
|---|
| 2 | # |
|---|
| 3 | |
|---|
| 4 | ############################################################################### |
|---|
| 5 | # bMotion - an 'AI' TCL script for eggdrops |
|---|
| 6 | # Copyright (C) James Michael Seward 2000-2008 |
|---|
| 7 | # |
|---|
| 8 | # This program is free software; you can redistribute it and/or modify |
|---|
| 9 | # it under the terms of the GNU General Public License as published by |
|---|
| 10 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | # (at your option) any later version. |
|---|
| 12 | # |
|---|
| 13 | # This program is distributed in the hope that it will be useful, but |
|---|
| 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 16 | # General Public License for more details. |
|---|
| 17 | # |
|---|
| 18 | # You should have received a copy of the GNU General Public License |
|---|
| 19 | # along with this program; if not, write to the Free Software |
|---|
| 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | ############################################################################### |
|---|
| 22 | |
|---|
| 23 | #Init variables |
|---|
| 24 | set mood(happy) 0 |
|---|
| 25 | set mood(horny) 0 |
|---|
| 26 | set mood(lonely) 0 |
|---|
| 27 | set mood(electricity) 2 |
|---|
| 28 | set mood(stoned) 0 |
|---|
| 29 | |
|---|
| 30 | set moodtarget(happy) 0 |
|---|
| 31 | set moodtarget(horny) 0 |
|---|
| 32 | set moodtarget(lonely) 5 |
|---|
| 33 | set moodtarget(electricity) 2 |
|---|
| 34 | set moodtarget(stoned) 0 |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | ## MOOD ROUTINES _________________________________________________________________________________ |
|---|
| 38 | proc bMotionGetHappy {} { |
|---|
| 39 | global mood |
|---|
| 40 | incr mood(happy) 1 |
|---|
| 41 | checkmood "" "" |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | proc bMotionGetSad {} { |
|---|
| 45 | global mood |
|---|
| 46 | incr mood(happy) -1 |
|---|
| 47 | checkmood "" "" |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | proc bMotionGetHorny {} { |
|---|
| 51 | global mood |
|---|
| 52 | incr mood(horny) 1 |
|---|
| 53 | checkmood "" "" |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | proc bMotionGetUnHorny {} { |
|---|
| 57 | global mood |
|---|
| 58 | incr mood(horny) -1 |
|---|
| 59 | checkmood "" "" |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | proc bMotionGetLonely {} { |
|---|
| 63 | global mood |
|---|
| 64 | incr mood(lonely) 1 |
|---|
| 65 | checkmood "" "" |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | proc bMotionGetUnLonely {} { |
|---|
| 69 | global mood |
|---|
| 70 | incr mood(lonely) -1 |
|---|
| 71 | checkmood "" "" |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | ## Checkmood: checks the moods are within limits |
|---|
| 75 | proc checkmood {nick channel} { |
|---|
| 76 | global mood |
|---|
| 77 | foreach r {happy horny lonely electricity stoned} { |
|---|
| 78 | if {$r < -30} { |
|---|
| 79 | set mood($r) -30 |
|---|
| 80 | bMotion_putloglev d * "bMotion: mood $r went OOB, resetting to -30" |
|---|
| 81 | } |
|---|
| 82 | if {$mood($r) > 30} { |
|---|
| 83 | bMotion_putloglev d * "bMotion: mood $r went OOB, resetting to 30" |
|---|
| 84 | set mood($r) 30 |
|---|
| 85 | } |
|---|
| 86 | } |
|---|
| 87 | if {$nick == ""} {return 0} |
|---|
| 88 | |
|---|
| 89 | if {($mood(happy) > 10) && ($mood(lonely) > 5) && ($mood(horny) > 5)} { |
|---|
| 90 | mee $channel "replicates some tissues" |
|---|
| 91 | mee $channel "locks [getPronoun] in the bathroom" |
|---|
| 92 | set mood(horny) [expr $mood(horny) - 10] |
|---|
| 93 | set mood(lonely) [expr $mood(lonely) -3] |
|---|
| 94 | } |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | ## Driftmood: Drifts all moods towards 0 |
|---|
| 99 | proc driftmood {} { |
|---|
| 100 | set driftSummary "" |
|---|
| 101 | global mood mooddrifttimer moodtarget |
|---|
| 102 | foreach r {happy horny lonely electricity stoned} { |
|---|
| 103 | set drift 0 |
|---|
| 104 | set driftString "" |
|---|
| 105 | if {$mood($r) > $moodtarget($r)} { |
|---|
| 106 | set drift -1 |
|---|
| 107 | set driftString "$moodtarget($r)--($drift)-->$mood($r)" |
|---|
| 108 | } |
|---|
| 109 | if {$mood($r) < $moodtarget($r)} { |
|---|
| 110 | set drift 2 |
|---|
| 111 | set driftString "$mood($r)--(+$drift)-->$moodtarget($r)" |
|---|
| 112 | } |
|---|
| 113 | if {$drift != 0} { |
|---|
| 114 | set mood($r) [expr $mood($r) + $drift] |
|---|
| 115 | set driftSummary "$driftSummary $r:($driftString) " |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | if {$driftSummary != ""} { |
|---|
| 119 | bMotion_putloglev d * "bMotion: drifted mood $driftSummary" |
|---|
| 120 | } |
|---|
| 121 | checkmood "" "" |
|---|
| 122 | set mooddrifttimer 1 |
|---|
| 123 | |
|---|
| 124 | timer 10 driftmood |
|---|
| 125 | return 0 |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | ## moodTimerStart: Used to start the mood drift timer when the script initialises |
|---|
| 130 | ## and other timers now, too |
|---|
| 131 | proc moodTimerStart {} { |
|---|
| 132 | global mooddrifttimer |
|---|
| 133 | if {![info exists mooddrifttimer]} { |
|---|
| 134 | timer 10 driftmood |
|---|
| 135 | #utimer 5 loldec |
|---|
| 136 | # utimer 90 smileyhandler |
|---|
| 137 | timer [expr [rand 30] + 3] doRandomStuff |
|---|
| 138 | set mooddrifttimer 1 |
|---|
| 139 | } |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | ## moodHander: DCC .mood |
|---|
| 144 | proc moodhandler {handle idx arg} { |
|---|
| 145 | #global mood |
|---|
| 146 | #putidx $idx "My current mood is $mood(happy) $mood(horny) $mood(lonely) $mood(electricity) $mood(stoned): happy horny lonely electricity stoned" |
|---|
| 147 | #if {$arg != ""} { |
|---|
| 148 | # if {$arg == "drift"} { |
|---|
| 149 | # driftmood |
|---|
| 150 | # return 0 |
|---|
| 151 | # } |
|---|
| 152 | # set moodtype [lindex $arg 0] |
|---|
| 153 | # set moodsetting [lindex $arg 1] |
|---|
| 154 | # set mood($moodtype) $moodsetting |
|---|
| 155 | # putlog "bMotion: Mood($moodtype) changed to $moodsetting by $handle" |
|---|
| 156 | #} |
|---|
| 157 | #checkmood "" "" |
|---|
| 158 | putidx $idx "Please use .bmotion mood" |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | ## pubm_moodHandler: !mood |
|---|
| 163 | proc pubm_moodhandler {nick host handle channel text} { |
|---|
| 164 | if {![matchattr $handle n]} { |
|---|
| 165 | return 0 |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | global botnick |
|---|
| 169 | |
|---|
| 170 | bMotionDoAction $channel $nick "%%: Please use .bmotion $botnick mood" |
|---|
| 171 | return 0 |
|---|
| 172 | # global mood botnick |
|---|
| 173 | # set text [string trim $text] |
|---|
| 174 | # if [regexp -nocase "^${botnick}$" $text] { |
|---|
| 175 | # set ming "Mood: " |
|---|
| 176 | # foreach r {happy horny lonely electricity stoned} { |
|---|
| 177 | # append ming " $r=$mood($r) " |
|---|
| 178 | # } |
|---|
| 179 | # global bMotionCache |
|---|
| 180 | # append ming " chanmood=[makeSmiley $bMotionCache($channel,mood)]" |
|---|
| 181 | # bMotionDoAction $channel "" $ming |
|---|
| 182 | # return 0 |
|---|
| 183 | # } |
|---|
| 184 | # |
|---|
| 185 | # if [regexp -nocase "^$botnick (.+)" $text args] { |
|---|
| 186 | # if {[matchattr $handle m]} { |
|---|
| 187 | # if {$args == "drift"} { |
|---|
| 188 | # driftmood |
|---|
| 189 | # return 0 |
|---|
| 190 | # } |
|---|
| 191 | # set moodtype [lindex $args 1] |
|---|
| 192 | # set moodsetting [lindex $args 2] |
|---|
| 193 | # if {[catch {expr $moodsetting}]} { |
|---|
| 194 | # putserv "PRIVMSG $nick :Fewl, that's not right." |
|---|
| 195 | # return 0 |
|---|
| 196 | # } |
|---|
| 197 | # set mood($moodtype) $moodsetting |
|---|
| 198 | # putlog "bMotion: Mood($moodtype) changed to $moodsetting by $handle" |
|---|
| 199 | # mee $channel "undergoes mood swing" |
|---|
| 200 | # return 0 |
|---|
| 201 | # } else { |
|---|
| 202 | # bMotionDoAction $channel "" "No." |
|---|
| 203 | # putlog "bMotion: $nick tried mood $args on $channel and failed." |
|---|
| 204 | # return 0 |
|---|
| 205 | # } |
|---|
| 206 | # } |
|---|
| 207 | # checkmood "" "" |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | # management command |
|---|
| 211 | proc bMotion_mood_admin { handle { arg "" } } { |
|---|
| 212 | global mood |
|---|
| 213 | |
|---|
| 214 | if {($arg == "") || ($arg == "status")} { |
|---|
| 215 | #output our mood |
|---|
| 216 | bMotion_putadmin "Current mood status:" |
|---|
| 217 | foreach moodtype {happy horny lonely electricity stoned} { |
|---|
| 218 | bMotion_putadmin " $moodtype: $mood($moodtype)" |
|---|
| 219 | } |
|---|
| 220 | return 0 |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | if {$arg == "drift"} { |
|---|
| 224 | bMotion_putadmin "Drifting mood values..." |
|---|
| 225 | driftmood |
|---|
| 226 | return 0 |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | if {[regexp -nocase {set ([^ ]+) ([0-9]+)} $arg matches moodname moodval]} { |
|---|
| 230 | if {[info tclversion] < 8.4} { |
|---|
| 231 | bMotion_putadmin "Sorry, the mood set command needs TCL >= 8.4 :/" |
|---|
| 232 | return |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | if {!([lsearch -inline {happy horny lonely electricity stoned} $moodname] == $moodname)} { |
|---|
| 236 | bMotion_putadmin "Unknown mood type '$moodname'" |
|---|
| 237 | return 0 |
|---|
| 238 | } |
|---|
| 239 | set mood($moodname) $moodval |
|---|
| 240 | bMotion_putadmin "Mood '$moodname' changed to $moodval" |
|---|
| 241 | return 0 |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | bMotion_putadmin "use: mood \[status|drift|set <type> <value>\]" |
|---|
| 245 | return 0 |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | # management help callback |
|---|
| 249 | proc bMotion_mood_admin_help { } { |
|---|
| 250 | bMotion_putadmin "Controls the mood system:" |
|---|
| 251 | bMotion_putadmin " .bmotion mood [status]" |
|---|
| 252 | bMotion_putadmin " View a list of all moods and their values" |
|---|
| 253 | bMotion_putadmin " .bmotion mood set <name> <value>" |
|---|
| 254 | bMotion_putadmin " Set mood <name> to <value>. The neutral value is usually 0. Max/min is (-)30." |
|---|
| 255 | bMotion_putadmin " .bmotion mood drift" |
|---|
| 256 | bMotion_putadmin " Runs a mood tick." |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | if {$bMotion_testing == 0} { |
|---|
| 260 | bMotion_plugin_add_management "mood" "^mood" n bMotion_mood_admin "any" bMotion_mood_admin_help |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | #add some default moods |
|---|
| 264 | |
|---|
| 265 | set mood(happy) 0 |
|---|
| 266 | set moodtarget(happy) 0 |
|---|
| 267 | #bMotion_mood_add "happy" -30 30 0 1 2 |
|---|
| 268 | |
|---|
| 269 | set mood(horny) 0 |
|---|
| 270 | set moodtarget(horny) 0 |
|---|
| 271 | #bMotion_mood_add "horny" -30 30 0 1 2 |
|---|
| 272 | |
|---|
| 273 | set mood(lonely) 0 |
|---|
| 274 | set moodtarget(lonely) 5 |
|---|
| 275 | #bMotion_mood_add "lonely" -30 30 5 1 2 |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | set mood(electricity) 2 |
|---|
| 279 | set moodtarget(electricity) 2 |
|---|
| 280 | #bMotion_mood_add "electricity" 0 2 2 1 2 |
|---|
| 281 | |
|---|
| 282 | set mood(stoned) 0 |
|---|
| 283 | set moodtarget(stoned) 0 |
|---|
| 284 | #bMotion_mood_add "stoned" 0 30 0 1 2 |
|---|
| 285 | |
|---|
| 286 | bMotion_putloglev d * "bMotion: mood module loaded" |
|---|