source: trunk/plugins/admin_general.tcl @ 1143

Revision 1141, 12.1 KB checked in by james, 4 weeks ago (diff)

Fix TCL 8.4 not supporting lsearch -nocase

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1# bMotion admin plugins
2#
3
4###############################################################################
5# This is a bMotion plugin
6# Copyright (C) James Michael Seward 2000-2009
7#
8# This program is covered by the GPL, please refer the to LICENCE file in the
9# distribution; further information can be found in the headers of the scripts
10# in the modules directory.
11###############################################################################
12
13#                                                                                                name           regexp                                                   flags   callback
14bMotion_plugin_add_management "status" "^(status|info)"                 t                               bMotion_plugin_management_status "any"
15bMotion_plugin_add_management "queue" "^queue"                                          n                               bMotion_plugin_management_queue "any"
16bMotion_plugin_add_management "parse" "^parse"                                          n                               bMotion_plugin_management_parse "any"
17bMotion_plugin_add_management "rehash" "^rehash"                                        n                               bMotion_plugin_management_rehash "any"
18bMotion_plugin_add_management "reload" "^reload"                                        n                               bMotion_plugin_management_reload "any"
19bMotion_plugin_add_management "settings" "^settings" n bMotion_plugin_management_settings "any"
20bMotion_plugin_add_management "global" "^global" n bMotion_plugin_management_global "any"
21bMotion_plugin_add_management "interbot" "^interbot" n bMotion_plugin_management_interbot "any" bMotion_plugin_management_interbot_help
22bMotion_plugin_add_management "flux" "^flux capacitors?" n bMotion_plugin_management_flux "any"
23bMotion_plugin_add_management "away" "^away" n bMotion_plugin_management_away "any" bMotion_plugin_management_away_help
24bMotion_plugin_add_management "debug" "^debug" n bMotion_plugin_management_debug "any" bMotion_plugin_management_debug_help
25
26#################################################################################################################################
27# Declare plugin functions
28
29proc bMotion_plugin_management_status { handle { args "" } } {
30        global bMotionInfo botnicks bMotionSettings bMotionVersion bMotionChannels BMOTION_SLEEP botnick
31                bMotion_update_chanlist 
32
33                set my_botnick [string toupper $botnick]
34
35                bMotion_putadmin "I AM $my_botnick! I'm powered by bMotion $bMotionVersion. I'm $bMotionInfo(gender) and this week I have mostly been $bMotionInfo(orientation)."
36
37                if {$botnicks == ""} {
38                        bMotion_check_botnicks
39                }
40
41                bMotion_putadmin "My botnicks are currently /$botnicks/."
42
43                if {$args == "channels"} {
44                        bMotion_putadmin "I'm active on: $bMotionChannels"
45                }
46
47                if {[bMotion_setting_get "sleepy"]} {
48                                switch $bMotionSettings(asleep) {
49                                                0 {
50                                                                bMotion_putadmin "I'm currently awake and my next bedtime is [clock format $bMotionSettings(sleepy_nextchange)]."
51                                                }
52                                                1 {
53                                                                bMotion_putadmin "I'm currently in my pajamas."
54                                                }
55                                                2 {
56                                                                bMotion_putadmin "I'm actually asleep right now. My alarm's set for [clock format $bMotionSettings(sleepy_nextchange)]."
57                                                }
58                                                default {
59                                                                bMotion_putadmin "I'm not really sure if I'm awake or what. My current sleep state is $bMotionSettings(asleep) and my next event is [clock format $bMotionSettings(sleepy_nextchange)], although who knows what'll happen then."
60                                                }
61                                }
62                } else {
63                                bMotion_putadmin "I am impervious to tiredness and never need to sleep."
64                }
65
66        bMotion_putadmin "Random stuff happens at least every [bMotion_setting_get minRandomDelay]min, at most every [bMotion_setting_get maxRandomDelay]min, and not if channel quiet for more than [bMotion_setting_get maxIdleGap]min. Active channels have a line in the last [bMotion_setting_get active_idle_sec]sec."
67        if [bMotion_setting_get silence] {
68                bMotion_putadmin "I am silent."
69        }
70        if [bMotion_setting_get "away"] {
71                bMotion_putadmin "I am away."
72        }
73       
74        global bMotion_loaded_settings_from
75        bMotion_putadmin "I loaded my configuration from: $bMotion_loaded_settings_from"
76
77        return 0
78}
79
80proc bMotion_plugin_management_queue { handle { args "" }} {
81        global bMotion_queue
82
83        if {$args == ""} {
84                #display queue
85                bMotion_putadmin "Queue size: [bMotion_queue_size] lines"
86                        foreach item $bMotion_queue {
87                                set sec [lindex $item 0]
88                                set target [lindex $item 1]
89                                set content [lindex $item 2]
90                                bMotion_putadmin "Delay $sec sec, target $target: $content"
91                }
92                return 0
93        }
94
95        if [regexp -nocase "clear|flush|delete|reset" $args] {
96                bMotion_putadmin "Flushing queue..."
97                bMotion_queue_flush
98                return 0
99        }
100
101                if {$args == "freeze"} {
102                                bMotion_putadmin "Freezing queue..."
103                                bMotion_queue_freeze
104                                return 0
105                }
106
107                if {$args == "thaw"} {
108                                bMotion_putadmin "Thawing queue..."
109                                bMotion_queue_thaw
110                                return 0
111                }
112
113                if {$args == "run"} {
114                                bMotion_putadmin "Running queue..."
115                                bMotion_queue_run 1
116                                return 0
117                }
118}
119
120proc bMotion_plugin_management_parse { handle { arg "" } } {
121                if {$arg == ""} {
122                                bMotion_putadmin "You must supply something to parse"
123                                return 0
124                }
125
126                set output [bMotion_plugins_settings_get "admin" "type" "" ""]
127                set target [bMotion_plugins_settings_get "admin" "target" "" ""]
128
129                if {$output == ""} {
130                                return 0
131                }
132
133                if {($output == "dcc") || (![string match "#*" $target])} {
134                                #command syntax should be:
135                                # .bmotion parse #channel output
136                                if [regexp -nocase {(#[^ ]+) (.+)} $arg matches chan parse] {
137                                                bMotionDoAction $chan "somenick" "\[parse\] $parse"
138                                                bMotion_putadmin "Sent '$parse' to $chan"
139                                                return 0
140                                }
141                }
142
143                #puthelp $target
144                if [regexp {^-n ?([0-9]+) (.+)} $arg matches repeat parse] {
145                        putlog "Parsing '$parse' * $repeat in $target"
146                        for { set i 0 } { $i < $repeat } { incr i } {
147                                bMotionDoAction $target "somenick" $parse
148                        }
149                } else {
150                        putlog "Parsing '$arg', requested in $target"
151                        bMotionDoAction $target "somenick" $arg
152                }
153                return 0
154}
155
156proc bMotion_plugin_management_rehash { handle } {
157        global bMotion_testing bMotionRoot
158
159        #check we're not going to die
160        catch {
161                bMotion_putloglev d * "bMotion: Testing new code..."
162                set bMotion_testing 1
163                source "$bMotionRoot/bMotion.tcl"
164        } msg
165
166        if {$msg != ""} {
167                putlog "bMotion: FATAL: Cannot rehash due to error: $msg"
168                bMotion_putadmin "Cannot rehash due to error: $msg"
169                return 0
170        } else {
171                bMotion_putloglev d * "bMotion: New code ok, rehashing..."
172                bMotion_putadmin "Rehashing..."
173                set bMotion_testing 0
174                rehash
175        }
176}
177
178proc bMotion_plugin_management_reload { handle } {
179        global bMotion_testing bMotionRoot
180
181        #check we're not going to die
182        catch {
183                bMotion_putloglev d * "bMotion: Testing new code..."
184                set bMotion_testing 1
185                source "$bMotionRoot/bMotion.tcl"
186        } msg
187
188        if {$msg != ""} {
189                putlog "bMotion: FATAL: Cannot reload due to error: $msg"
190                bMotion_putadmin "Cannot reload due to error: $msg"
191                return 0
192        } else {
193                bMotion_putloglev d * "bMotion: New code ok, reloading..."
194                bMotion_putadmin "Reloading bMotion..."
195                set bMotion_testing 0
196                source "$bMotionRoot/bMotion.tcl"
197        }
198}
199
200proc bMotion_plugin_management_settings { handle { arg "" } } {
201        global bMotion_plugins_settings
202
203        if {$arg == "clear"} {
204                if {![info exists bMotion_plugins_settings]} {
205                                unset bMotion_plugins_settings
206                                set bMotion_plugins_settings(dummy,setting,channel,nick) "dummy"
207                }
208                bMotion_putadmin "Cleared plugins settings array"
209                return 0
210        }
211
212        if {$arg == "list"} {
213                set s [array startsearch bMotion_plugins_settings]
214                while {[set key [array nextelement bMotion_plugins_settings $s]] != ""} {
215                                bMotion_putadmin "$key = $bMotion_plugins_settings($key)"
216                }
217                array donesearch bMotion_plugins_settings $s
218        }
219}
220
221proc bMotion_plugin_management_global { handle { text "" } } {
222        global bMotionGlobal
223
224        if [string match -nocase "off" $text] {
225                bMotion_putadmin "globally disabling bmotion"
226                set bMotionGlobal 0
227                return 0
228        }
229
230        if [string match -nocase "on" $text] {
231                bMotion_putadmin "globally enabling bmotion"
232                set bMotionGlobal 1
233                return 0
234        }
235
236        if {$bMotionGlobal == 0} {
237                bMotion_putadmin "bMotion is currently disabled"
238        } else {
239                bMotion_putadmin "bMotion is currently enabled"
240        }
241        bMotion_putadmin "use: global off|on"
242        return 0
243}
244
245proc bMotion_plugin_management_interbot { handle { text "" } } {
246                global bMotion_interbot_nextbot_nick
247               
248                if [regexp -nocase "next (#.+)" $text matches chan] {
249                                set next $bMotion_interbot_nextbot_nick($chan)
250                                if {$next == ""} {
251                                                bMotion_putadmin "Next bot is unknown!"
252                                } else {
253                                                bMotion_putadmin "Next bot for $chan is $next"
254                                }
255                }
256
257                if [regexp -nocase "elect (#.+)" $text matches chan] {
258                                bMotion_putadmin "Forcing election on $chan..."
259
260                                bMotion_interbot_next_elect_do $chan
261                }
262
263                if [regexp -nocase "bots (#.+)" $text matches chan] {
264
265                                bMotion_putadmin "Known bMotion bots on $chan: "
266                                bMotion_putadmin [bMotion_interbot_otherbots $chan]
267                }
268
269                if [regexp -nocase "enable" $text] {
270                                global bMotion_interbot_enable
271
272                                if {$bMotion_interbot_enable} {
273                                                bMotion_putadmin "Interbot stuff is already enabled."
274                                                return
275                                } else {
276                                                set bMotion_interbot_enable 1
277                                                bMotion_putadmin "Interbot stuff enabled."
278                                                return
279                                }
280                }
281
282                if [regexp -nocase "disable" $text] {
283                                global bMotion_interbot_enable
284
285                                if {!$bMotion_interbot_enable} {
286                                                bMotion_putadmin "Interbot stuff is already disabled."
287                                                return
288                                } else {
289                                                set bMotion_interbot_enable 0
290                                                bMotion_putadmin "Interbot stuff disabled."
291                                                return
292                                }
293                }
294}
295
296proc bMotion_plugin_management_interbot_help { } {
297                bMotion_putadmin "Manage the interbot communication stuff."
298                bMotion_putadmin "      .bmotion interbot next #channel"
299                bMotion_putadmin "              Report the next bot for #channel"
300                bMotion_putadmin "      .bmotion interbot elect #channel"
301                bMotion_putadmin "              Force an election for #channel"
302                bMotion_putadmin "      .bmotion interbot bots #channel"
303                bMotion_putadmin "              Report bots discovered in #channel"
304                bMotion_putadmin "      .bmotion interbot enable"
305                bMotion_putadmin "      .bmotion interbot disable"
306                bMotion_putadmin "              Enable/disable interbot stuff entirely"
307}
308
309# um
310proc bMotion_plugin_management_flux { handle { text "" } } {
311                if {[string match "*off*" $text]} {
312                                bMotion_putadmin "i call it... MISTAR FUSION!"
313                                return
314                }
315                if {[string match "*on*" $text]} {
316                                bMotion_putadmin "ONE POINT TWENTY ONE JIGAWATS"
317                                return
318                }
319}
320
321proc bMotion_plugin_management_away { handle { text "" } } {
322        global bMotionInfo
323
324        if {$text == ""} {
325                if {$bMotionInfo(away)} {
326                        bMotion_putadmin "I am currently away."
327                } else {
328                        bMotion_putadmin "I am not away."
329                        }
330                return
331        }
332
333        if {$text == "off"} {
334                bMotion_putadmin "Coming back from being away."
335                set bMotionInfo(away) 0
336                set bMotionInfo(silent) 0
337                return
338        }
339
340        bMotion_putadmin "Use: .bmotion away [off]"
341}
342
343proc bMotion_plugin_management_away_help { } {
344        bMotion_putadmin "Check and adjust the bot's away status"
345        bMotion_putadmin "  .bmotion away"
346        bMotion_putadmin "    Show if the bot is away or not"
347        bMotion_putadmin "  .bmotion away off"
348        bMotion_putadmin "    Make the bot be not-away"
349}
350
351proc bMotion_plugin_management_debug { handle { text "" } } {
352        global bMotionDebug
353
354        if {$text == "" } {
355                if {[llength $bMotionDebug] == 0} {
356                        bMotion_putadmin "bMotion debug mode is currently disabled."
357                        return
358                } else {
359                        bMotion_putadmin "bMotion debug mode is currently enabled on $bMotionDebug"
360                        return
361                }
362        }
363
364        if [regexp -nocase {(on|off) ([#&][^ ]+)} $text matches toggle channel] {
365                set channel [string tolower $channel]
366                if {[string tolower $toggle] == "on"} {
367                        if {[lsearch $bMotionDebug $channel] > -1} {
368                                bMotion_putadmin "$channel already has the debug flag enabled."
369                                return
370                        }
371                        lappend bMotionDebug $channel
372                        bMotion_putadmin "Enabled debug mode for $channel"
373                        return
374                } else {
375                        if {[lsearch $bMotionDebug $channel] == -1} {
376                                bMotion_putadmin "$channel does not have debug mode enabled."
377                                return
378                        }
379                        set index [lsearch $bMotionDebug $channel]
380                        set bMotionDebug [lreplace $bMotionDebug $index $index]
381                        bMotion_putadmin "Disabled debug mode for $channel"
382                        return
383                }
384        } else {
385                bMotion_putadmin "Try .bmotion help debug"
386        }
387}
388
389proc bMotion_plugin_management_debug_help { } {
390        bMotion_putadmin "Enable and disable debug mode on channels. Debug mode makes all plugins fire at 100% chance and disables flood checking."
391        bMotion_putadmin "  .bmotion debug"
392        bMotion_putadmin "    Check the status of debug mode"
393        bMotion_putadmin "  .bmotion debug on #channel"
394        bMotion_putadmin "    Enable debug on #channel"
395        bMotion_putadmin "  .bmotion debug off #channel"
396        bMotion_putadmin "    Disable debug on #channel"
397}
Note: See TracBrowser for help on using the repository browser.