| 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 |
|---|
| 15 | set bMotionRoot "scripts/bmotion" |
|---|
| 16 | set bMotionModules "$bMotionRoot/modules" |
|---|
| 17 | set bMotionPlugins "$bMotionRoot/plugins" |
|---|
| 18 | set bMotionLocal "$bMotionRoot/local" |
|---|
| 19 | |
|---|
| 20 | ### We need to do this early on in case something breaks |
|---|
| 21 | setudef flag bmotion |
|---|
| 22 | |
|---|
| 23 | if {![info exists bMotion_log_regexp]} { |
|---|
| 24 | set bMotion_log_regexp "" |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | if {![info exists bMotion_testing]} { |
|---|
| 28 | putloglev d * "bMotion: bMotion_testing is not defined, setting to 0." |
|---|
| 29 | set bMotion_testing 0 |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | source "$bMotionRoot/VERSION" |
|---|
| 34 | if {$bMotion_testing == 0} { |
|---|
| 35 | putlog "bMotion $bMotionVersion starting up..." |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | if {$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 | |
|---|
| 47 | proc 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 | # init default variables |
|---|
| 69 | if {$bMotion_testing == 1} { |
|---|
| 70 | putlog "... loading variables" |
|---|
| 71 | } |
|---|
| 72 | source "$bMotionModules/variables.tcl" |
|---|
| 73 | |
|---|
| 74 | # load counters |
|---|
| 75 | if {$bMotion_testing == 1} { |
|---|
| 76 | putlog "... loading counters" |
|---|
| 77 | } |
|---|
| 78 | source "$bMotionModules/counters.tcl" |
|---|
| 79 | |
|---|
| 80 | # load settings |
|---|
| 81 | if {$bMotion_testing == 1} { |
|---|
| 82 | putlog "... loading settings" |
|---|
| 83 | } |
|---|
| 84 | # try the original location first |
|---|
| 85 | set bMotion_loaded_settings 0 |
|---|
| 86 | if [file exists "$bMotionModules/settings.tcl"] { |
|---|
| 87 | source "$bMotionModules/settings.tcl" |
|---|
| 88 | bMotion_putloglev d * "loaded settings from modules directory" |
|---|
| 89 | set bMotion_loaded_settings 1 |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | #try to load a file for this bot |
|---|
| 93 | catch { |
|---|
| 94 | if {${botnet-nick} != ""} { |
|---|
| 95 | source "$bMotionModules/settings_${botnet-nick}.tcl" |
|---|
| 96 | bMotion_putloglev d * "loaded settings for this bot from settings_${botnet-nick}.tcl" |
|---|
| 97 | set bMotion_loaded_settings 1 |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | #try to load from the local dir |
|---|
| 102 | if [file exists "$bMotionLocal/settings.tcl"] { |
|---|
| 103 | source "$bMotionLocal/settings.tcl" |
|---|
| 104 | bMotion_putloglev d * "loaded local settings from $bMotionLocal/settings.tcl" |
|---|
| 105 | set bMotion_loaded_settings 1 |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | if {$bMotion_loaded_settings == 0} { |
|---|
| 109 | putlog "bMotion: FATAL! Could not load from any settings file! bMotion is not going to work! :(" |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | #load system functions |
|---|
| 113 | if {$bMotion_testing == 1} { |
|---|
| 114 | putlog "... loading system" |
|---|
| 115 | } |
|---|
| 116 | source "$bMotionModules/system.tcl" |
|---|
| 117 | |
|---|
| 118 | #load new abstract system |
|---|
| 119 | if {$bMotion_testing == 1} { |
|---|
| 120 | putlog "... loading abstract system" |
|---|
| 121 | } |
|---|
| 122 | source "$bMotionModules/abstract.tcl" |
|---|
| 123 | |
|---|
| 124 | # load output functions |
|---|
| 125 | if {$bMotion_testing == 1} { |
|---|
| 126 | putlog "... loading output" |
|---|
| 127 | } |
|---|
| 128 | source "$bMotionModules/output.tcl" |
|---|
| 129 | |
|---|
| 130 | # load event functions |
|---|
| 131 | if {$bMotion_testing == 1} { |
|---|
| 132 | putlog "... loading events" |
|---|
| 133 | } |
|---|
| 134 | source "$bMotionModules/events.tcl" |
|---|
| 135 | |
|---|
| 136 | if {$bMotion_testing == 1} { |
|---|
| 137 | putlog "... loading events support" |
|---|
| 138 | } |
|---|
| 139 | source "$bMotionModules/events_support.tcl" |
|---|
| 140 | |
|---|
| 141 | # load interbot bits |
|---|
| 142 | if {$bMotion_testing == 1} { |
|---|
| 143 | putlog "... loading interbot" |
|---|
| 144 | } |
|---|
| 145 | source "$bMotionModules/interbot.tcl" |
|---|
| 146 | |
|---|
| 147 | # load friendship code |
|---|
| 148 | if {$bMotion_testing == 1} { |
|---|
| 149 | putlog "... loading friendship" |
|---|
| 150 | } |
|---|
| 151 | source "$bMotionModules/friendship.tcl" |
|---|
| 152 | |
|---|
| 153 | # load anti-flood code |
|---|
| 154 | if {$bMotion_testing == 1} { |
|---|
| 155 | putlog "... loading flood" |
|---|
| 156 | } |
|---|
| 157 | source "$bMotionModules/flood.tcl" |
|---|
| 158 | |
|---|
| 159 | # load queue code |
|---|
| 160 | if {$bMotion_testing == 1} { |
|---|
| 161 | putlog "... loading queue" |
|---|
| 162 | } |
|---|
| 163 | source "$bMotionModules/queue.tcl" |
|---|
| 164 | |
|---|
| 165 | # load plugins |
|---|
| 166 | if {$bMotion_testing == 1} { |
|---|
| 167 | putlog "... loading plugins" |
|---|
| 168 | } |
|---|
| 169 | source "$bMotionModules/plugins.tcl" |
|---|
| 170 | |
|---|
| 171 | # load mood functions |
|---|
| 172 | if {$bMotion_testing == 1} { |
|---|
| 173 | putlog "... loading mood" |
|---|
| 174 | } |
|---|
| 175 | source "$bMotionModules/mood.tcl" |
|---|
| 176 | |
|---|
| 177 | if {$bMotion_testing == 1} { |
|---|
| 178 | putlog "... loading plugin settings" |
|---|
| 179 | } |
|---|
| 180 | source "$bMotionModules/plugins_settings.tcl" |
|---|
| 181 | |
|---|
| 182 | ### That's everything but the plugins stuff loaded. Now load extra modules |
|---|
| 183 | bMotion_putloglev d * "looking for 3rd party modules..." |
|---|
| 184 | set files [lsort [glob -nocomplain "$bMotionModules/extra/*.tcl"]] |
|---|
| 185 | foreach f $files { |
|---|
| 186 | bMotion_putloglev 1 * "... loading extra module: $f" |
|---|
| 187 | catch { |
|---|
| 188 | source $f |
|---|
| 189 | } |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | ### Done, load the plugins: |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | #load local abstracts |
|---|
| 197 | catch { |
|---|
| 198 | source "$bMotionLocal/abstracts.tcl" |
|---|
| 199 | bMotion_putloglev d * "loaded abstracts for this bot from local abstracts.tcl" |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | # load other bits |
|---|
| 203 | if {$bMotion_testing == 1} { |
|---|
| 204 | putlog "... loading leet" |
|---|
| 205 | } |
|---|
| 206 | source "$bMotionModules/leet.tcl" |
|---|
| 207 | |
|---|
| 208 | # load diagnostics |
|---|
| 209 | catch { |
|---|
| 210 | if {$bMotion_testing == 1} { |
|---|
| 211 | putlog "... loading self-diagnostics" |
|---|
| 212 | } |
|---|
| 213 | source "$bMotionModules/diagnostics.tcl" |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | # Ignition! |
|---|
| 217 | |
|---|
| 218 | bMotion_startTimers |
|---|
| 219 | if {$bMotion_testing == 0} { |
|---|
| 220 | bMotion_diagnostic_utimers |
|---|
| 221 | bMotion_diagnostic_timers |
|---|
| 222 | |
|---|
| 223 | putlog "\002bMotion $bMotionVersion AI online\002 :D" |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | set bMotion_loading 0 |
|---|
| 227 | set bMotion_testing 0 |
|---|
| 228 | |
|---|
| 229 | # To hide this message from your bot's startup/rehash, edit your settings.tcl and change |
|---|
| 230 | # the bMotion_show_copyright value to 0 |
|---|
| 231 | if {![info exists bMotion_show_copyright]} { |
|---|
| 232 | set bMotion_show_copyright 1 |
|---|
| 233 | } |
|---|
| 234 | if {$bMotion_show_copyright == 1} { |
|---|
| 235 | putlog "bMotion is Copyright (C) 2007 James Seward. bMotion comes with ABSOLUTELY NO WARRANTY;" |
|---|
| 236 | putlog "This is free software, and you are welcome to redistribute it under certain conditions." |
|---|
| 237 | putlog "See the COPYRIGHT file for details. See bMotion.tcl to hide this message once you have read it." |
|---|
| 238 | } |
|---|