source: trunk/modules/mood.tcl @ 1143

Revision 1112, 7.4 KB checked in by james, 10 months ago (diff)

mega-commit including but not limited to:

debug notice tidyup, should make +d less spammy

fixes for output_english and output_colloquial
new %SMILEY macro allowing the bot to use a consistent smiley type
new improved stoplist for sillyThings list with better filtering
other fixes and improvements

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
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
24set mood(happy) 0
25set mood(horny) 0
26set mood(lonely) 0
27set mood(electricity) 2
28set mood(stoned) 0
29
30set moodtarget(happy) 0
31set moodtarget(horny) 0
32set moodtarget(lonely) 5
33set moodtarget(electricity) 2
34set moodtarget(stoned) 0
35
36
37## MOOD ROUTINES _________________________________________________________________________________
38proc bMotionGetHappy {} {
39  global mood
40  incr mood(happy) 1
41  checkmood "" ""
42}
43
44proc bMotionGetSad {} {
45  global mood
46  incr mood(happy) -1
47  checkmood "" ""
48}
49
50proc bMotionGetHorny {} {
51  global mood
52  incr mood(horny) 1
53  checkmood "" ""
54}
55
56proc bMotionGetUnHorny {} {
57  global mood
58  incr mood(horny) -1
59  checkmood "" ""
60}
61
62proc bMotionGetLonely {} {
63  global mood
64  incr mood(lonely) 1
65  checkmood "" ""
66}
67
68proc bMotionGetUnLonely {} {
69  global mood
70  incr mood(lonely) -1
71  checkmood "" ""
72}
73
74## Checkmood: checks the moods are within limits
75proc 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
99proc 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
131proc 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
144proc 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
163proc 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
211proc 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
249proc 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
259if {$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
265set mood(happy) 0
266set moodtarget(happy) 0
267#bMotion_mood_add "happy" -30 30 0 1 2
268
269set mood(horny) 0
270set moodtarget(horny) 0
271#bMotion_mood_add "horny" -30 30 0 1 2
272
273set mood(lonely) 0
274set moodtarget(lonely) 5
275#bMotion_mood_add "lonely" -30 30 5 1 2
276
277
278set mood(electricity) 2
279set moodtarget(electricity) 2
280#bMotion_mood_add "electricity" 0 2 2 1 2
281
282set mood(stoned) 0
283set moodtarget(stoned) 0
284#bMotion_mood_add "stoned" 0 30 0 1 2
285
286bMotion_putloglev d * "bMotion: mood module loaded"
Note: See TracBrowser for help on using the repository browser.