source: trunk/bMotion.tcl @ 1072

Revision 1072, 6.1 KB checked in by james, 23 months ago (diff)

fix loading file named for bot from local/ folder (was only looking in modules/)
load settings files in correct order for overriding defaults
report which settings files were loaded when we start
report which settings files were loaded in .bmotion status

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#bMotion core
2#
3# $Id$
4#
5
6#
7# #5270 +(28)- [X]
8#
9# <Procyan> is there like 1 person on earth that knows tcl/tk and is writing all of the apps?
10# <unSlider> procyan: no, there are a bunch of people who dont know tcl/tk but are writing apps for it anyway
11#                                               (www.bash.org)
12
13
14### Set some important variables
15set bMotionRoot "scripts/bmotion"
16set bMotionModules "$bMotionRoot/modules"
17set bMotionPlugins "$bMotionRoot/plugins"
18set bMotionLocal "$bMotionRoot/local"
19
20### We need to do this early on in case something breaks
21setudef flag bmotion
22
23if {![info exists bMotion_log_regexp]} {
24        set bMotion_log_regexp ""
25}
26
27if {![info exists bMotion_testing]} {
28  putloglev d * "bMotion: bMotion_testing is not defined, setting to 0."
29  set bMotion_testing 0
30}
31
32
33source "$bMotionRoot/VERSION"
34if {$bMotion_testing == 0} {
35  putlog "bMotion $bMotionVersion starting up..."
36}
37
38
39if {$bMotion_testing == 1} {
40  putlog "bMotion: INFO: Code loading in testing mode"
41  set bMotion_loading 0
42} else {
43  putloglev 1 * "bMotion: INFO: Code loading in running mode"
44  set bMotion_loading 1
45}
46
47proc bMotion_putloglev { level star text } {
48  global bMotion_testing bMotion_log_regexp
49       
50        if {$bMotion_log_regexp != ""} {
51                if {![regexp -nocase $bMotion_log_regexp $text]} {
52                        return 0
53                }
54        }
55
56  regsub "bMotion:" $text "" text
57  set text2 ""
58  if {$level != "d"} {
59    set text2 [string repeat " " $level]
60  }
61  set text "bMotion:$text2 $text"
62
63  if {$bMotion_testing == 0} {
64    putloglev $level $star "($level)$text"
65  }
66}
67
68# needed for variables
69if {$bMotion_testing == 1} {
70  putlog "... loading plugin settings"
71}
72source "$bMotionModules/plugins_settings.tcl"
73
74# init default variables
75if {$bMotion_testing == 1} {
76  putlog "... loading variables"
77}
78source "$bMotionModules/variables.tcl"
79
80# load settings
81if {$bMotion_testing == 1} {
82  putlog "... loading settings"
83}
84
85set bMotion_loaded_settings_from [list]
86
87# try the original location first
88set bMotion_loaded_settings 0
89if [file exists "$bMotionModules/settings.tcl"] {
90        source "$bMotionModules/settings.tcl"
91        bMotion_putloglev d * "loaded settings from modules directory"
92        set bMotion_loaded_settings 1
93        lappend bMotion_loaded_settings_from "$bMotionModules/settings.tcl"
94}
95
96#try to load from the local dir
97if [file exists "$bMotionLocal/settings.tcl"] {
98        source "$bMotionLocal/settings.tcl"
99        bMotion_putloglev d * "loaded local settings from $bMotionLocal/settings.tcl"
100        set bMotion_loaded_settings 1
101        lappend bMotion_loaded_settings_from "$bMotionLocal/settings.tcl"
102}
103
104#try to load a file for this bot
105catch {
106  if {${botnet-nick} != ""} {
107    source "$bMotionModules/settings_${botnet-nick}.tcl"
108    bMotion_putloglev d * "loaded settings for this bot from settings_${botnet-nick}.tcl"
109                set bMotion_loaded_settings 1
110                lappend bMotion_loaded_settings_from "$bMotionModules/settings_${botnet-nick}.tcl"
111  }
112}
113
114#try to load a file for this bot
115catch {
116  if {${botnet-nick} != ""} {
117    source "$bMotionLocal/settings_${botnet-nick}.tcl"
118    bMotion_putloglev d * "loaded settings for this bot from settings_${botnet-nick}.tcl"
119                set bMotion_loaded_settings 1
120                lappend bMotion_loaded_settings_from "$bMotionLocal/settings_${botnet-nick}.tcl"
121  }
122}
123
124putlog "bMotion: loaded settings from the following files: $bMotion_loaded_settings_from"
125
126if {$bMotion_loaded_settings == 0} {
127        putlog "bMotion: FATAL! Could not load from any settings file! bMotion is not going to work! :("
128}
129
130#load system functions
131if {$bMotion_testing == 1} {
132  putlog "... loading system"
133}
134source "$bMotionModules/system.tcl"
135
136#load new abstract system
137if {$bMotion_testing == 1} {
138  putlog "... loading abstract system"
139}
140source "$bMotionModules/abstract.tcl"
141
142# load output functions
143if {$bMotion_testing == 1} {
144  putlog "... loading output"
145}
146source "$bMotionModules/output.tcl"
147
148# load event functions
149if {$bMotion_testing == 1} {
150  putlog "... loading events"
151}
152source "$bMotionModules/events.tcl"
153
154if {$bMotion_testing == 1} {
155  putlog "... loading events support"
156}
157source "$bMotionModules/events_support.tcl"
158
159# load interbot bits
160if {$bMotion_testing == 1} {
161  putlog "... loading interbot"
162}
163source "$bMotionModules/interbot.tcl"
164
165# load friendship code
166if {$bMotion_testing == 1} {
167  putlog "... loading friendship"
168}
169source "$bMotionModules/friendship.tcl"
170
171# load anti-flood code
172if {$bMotion_testing == 1} {
173  putlog "... loading flood"
174}
175source "$bMotionModules/flood.tcl"
176
177# load queue code
178if {$bMotion_testing == 1} {
179  putlog "... loading queue"
180}
181source "$bMotionModules/queue.tcl"
182
183# load plugins
184if {$bMotion_testing == 1} {
185  putlog "... loading plugins"
186}
187source "$bMotionModules/plugins.tcl"
188
189# load mood functions
190if {$bMotion_testing == 1} {
191  putlog "... loading mood"
192}
193source "$bMotionModules/mood.tcl"
194
195
196### That's everything but the plugins stuff loaded. Now load extra modules
197bMotion_putloglev d * "looking for 3rd party modules..."
198set files [lsort [glob -nocomplain "$bMotionModules/extra/*.tcl"]]
199foreach f $files {
200  bMotion_putloglev 1 * "... loading extra module: $f"
201  catch {
202    source $f
203  }
204}
205
206### Done, load the plugins:
207
208
209
210#load local abstracts
211catch {
212        source "$bMotionLocal/abstracts.tcl"
213        bMotion_putloglev d * "loaded abstracts for this bot from local abstracts.tcl"
214}
215
216# load other bits
217if {$bMotion_testing == 1} {
218  putlog "... loading leet"
219}
220source "$bMotionModules/leet.tcl"
221
222# load diagnostics
223catch {
224  if {$bMotion_testing == 1} {
225    putlog "... loading self-diagnostics"
226  }
227  source "$bMotionModules/diagnostics.tcl"
228}
229
230# Ignition!
231
232bMotion_startTimers
233if {$bMotion_testing == 0} {
234        bMotion_diagnostic_utimers
235        bMotion_diagnostic_timers
236
237  putlog "\002bMotion $bMotionVersion AI online\002 :D"
238}
239
240set bMotion_loading 0
241set bMotion_testing 0
242
243# To hide this message from your bot's startup/rehash, edit your settings.tcl and change
244# the bMotion_show_copyright value to 0
245if {![info exists bMotion_show_copyright]} {
246        set bMotion_show_copyright 1
247}
248if {$bMotion_show_copyright == 1} {
249        putlog "bMotion is Copyright (C) 2007 James Seward. bMotion comes with ABSOLUTELY NO WARRANTY;"
250  putlog "This is free software, and you are welcome to redistribute it under certain conditions."
251  putlog "See the COPYRIGHT file for details. See bMotion.tcl to hide this message once you have read it."
252}
Note: See TracBrowser for help on using the repository browser.