| 1 | # bMotion: admin plugin file for plugin mangement |
|---|
| 2 | # |
|---|
| 3 | # $Id$ |
|---|
| 4 | # |
|---|
| 5 | |
|---|
| 6 | ############################################################################### |
|---|
| 7 | # This is a bMotion plugin |
|---|
| 8 | # Copyright (C) James Michael Seward 2000-2002 |
|---|
| 9 | # |
|---|
| 10 | # This program is covered by the GPL, please refer the to LICENCE file in the |
|---|
| 11 | # distribution; further information can be found in the headers of the scripts |
|---|
| 12 | # in the modules directory. |
|---|
| 13 | ############################################################################### |
|---|
| 14 | |
|---|
| 15 | #register the plugin |
|---|
| 16 | bMotion_plugin_add_management "plugin" "^plugin" n "bMotion_plugin_management_plugins" "any" |
|---|
| 17 | |
|---|
| 18 | proc bMotion_plugin_management_plugins { handle { arg "" }} { |
|---|
| 19 | #plugin remove <type> <id> |
|---|
| 20 | if [regexp -nocase {remove ([^ ]+) (.+)} $arg matches t id] { |
|---|
| 21 | bMotion_putadmin "Removing $t plugin $id..." |
|---|
| 22 | set full_array_name_for_upvar "bMotion_plugins_$t" |
|---|
| 23 | upvar #0 $full_array_name_for_upvar TEH_ARRAY |
|---|
| 24 | unset TEH_ARRAY($id) |
|---|
| 25 | bMotion_putadmin "...done." |
|---|
| 26 | return 0 |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | #enable a plugin |
|---|
| 30 | set channel "" |
|---|
| 31 | if [regexp -nocase {enable ([^ ]+) (.+?)( .+)?} $arg matches t id channel] { |
|---|
| 32 | if {$t == "output"} { |
|---|
| 33 | if {$channel != ""} { |
|---|
| 34 | set channel [string trim $channel] |
|---|
| 35 | bMotion_putadmin "Enabling output plugin $id on channel $channel..." |
|---|
| 36 | if [bMotion_plugin_set_output_channel $id $channel 1] { |
|---|
| 37 | bMotion_putadmin "...done." |
|---|
| 38 | } |
|---|
| 39 | return 0 |
|---|
| 40 | } else { |
|---|
| 41 | bMotion_putadmin "Enabling output plugin $id globally..." |
|---|
| 42 | if [bMotion_plugin_set_output $id 1] { |
|---|
| 43 | bMotion_putadmin "...done." |
|---|
| 44 | } |
|---|
| 45 | return 0 |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | #invalid plugin to enable |
|---|
| 50 | bMotion_putadmin "That's not a valid plugin type for enabling." |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | #disable a plugin |
|---|
| 54 | if [regexp -nocase {disable ([^ ]+) (.+?)( .+)?} $arg matches t id channel] { |
|---|
| 55 | if {$t == "output"} { |
|---|
| 56 | if {$channel != ""} { |
|---|
| 57 | set channel [string trim $channel] |
|---|
| 58 | bMotion_putadmin "Disabling output plugin $id on channel $channel..." |
|---|
| 59 | if [bMotion_plugin_set_output_channel $id $channel 0] { |
|---|
| 60 | bMotion_putadmin "...done." |
|---|
| 61 | } |
|---|
| 62 | return 0 |
|---|
| 63 | } else { |
|---|
| 64 | bMotion_putadmin "Disable output plugin $id globally..." |
|---|
| 65 | if [bMotion_plugin_set_output $id 0] { |
|---|
| 66 | bMotion_putadmin "...done." |
|---|
| 67 | } |
|---|
| 68 | return 0 |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | #invalid plugin to enable |
|---|
| 73 | bMotion_putadmin "That's not a valid plugin type for disabling." |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | if [regexp -nocase {info ([^ ]+) (.+)} $arg matches t id] { |
|---|
| 77 | global bMotion_plugins_output_perchan |
|---|
| 78 | |
|---|
| 79 | set full_array_name_for_upvar "bMotion_plugins_$t" |
|---|
| 80 | upvar #0 $full_array_name_for_upvar TEH_ARRAY |
|---|
| 81 | |
|---|
| 82 | set details $TEH_ARRAY($id) |
|---|
| 83 | |
|---|
| 84 | switch $t { |
|---|
| 85 | "simple" - |
|---|
| 86 | "action_simple" { |
|---|
| 87 | global BMOTION_PLUGIN_SIMPLE_MATCH BMOTION_PLUGIN_SIMPLE_CHANCE BMOTION_PLUGIN_SIMPLE_RESPONSE BMOTION_PLUGIN_SIMPLE_LANGUAGE |
|---|
| 88 | bMotion_putadmin "Plugin details for ${t}:$id ([lindex $details $BMOTION_PLUGIN_SIMPLE_LANGUAGE]) [lindex $details $BMOTION_PLUGIN_SIMPLE_CHANCE]%" |
|---|
| 89 | bMotion_putadmin " Match on: [lindex $details $BMOTION_PLUGIN_SIMPLE_MATCH]" |
|---|
| 90 | bMotion_putadmin " Response list: [lindex $details $BMOTION_PLUGIN_SIMPLE_RESPONSE]" |
|---|
| 91 | return 0 |
|---|
| 92 | } |
|---|
| 93 | "complex" - |
|---|
| 94 | "action_complex" { |
|---|
| 95 | global BMOTION_PLUGIN_COMPLEX_MATCH BMOTION_PLUGIN_COMPLEX_CHANCE BMOTION_PLUGIN_COMPLEX_CALLBACK BMOTION_PLUGIN_COMPLEX_LANGUAGE |
|---|
| 96 | bMotion_putadmin "Plugin details for ${t}:$id ([lindex $details $BMOTION_PLUGIN_COMPLEX_LANGUAGE]) [lindex $details $BMOTION_PLUGIN_COMPLEX_CHANCE]%" |
|---|
| 97 | bMotion_putadmin " Match on: [lindex $details $BMOTION_PLUGIN_COMPLEX_MATCH]" |
|---|
| 98 | bMotion_putadmin " Callback: [lindex $details $BMOTION_PLUGIN_COMPLEX_CALLBACK]" |
|---|
| 99 | return 0 |
|---|
| 100 | } |
|---|
| 101 | "output" { |
|---|
| 102 | global BMOTION_PLUGIN_OUTPUT_PRIORITY BMOTION_PLUGIN_OUTPUT_ENABLED BMOTION_PLUGIN_OUTPUT_LANGUAGE BMOTION_PLUGIN_OUTPUT_CALLBACK |
|---|
| 103 | bMotion_putadmin "Plugin details for output:$id ([lindex $details $BMOTION_PLUGIN_OUTPUT_LANGUAGE]) Priority:[lindex $details $BMOTION_PLUGIN_OUTPUT_PRIORITY]" |
|---|
| 104 | if {[lindex $details $BMOTION_PLUGIN_OUTPUT_ENABLED] == 1} { |
|---|
| 105 | bMotion_putadmin " Enabled on: all channels" |
|---|
| 106 | } else { |
|---|
| 107 | set current [list] |
|---|
| 108 | catch { |
|---|
| 109 | set current $bMotion_plugins_output_perchan($id) |
|---|
| 110 | } |
|---|
| 111 | if {[llength $current] > 0} { |
|---|
| 112 | bMotion_putadmin " Enabled on channels: $current" |
|---|
| 113 | } else { |
|---|
| 114 | bMotion_putadmin " Enabled: no" |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | bMotion_putadmin " Callback: [lindex $details $BMOTION_PLUGIN_OUTPUT_CALLBACK]" |
|---|
| 118 | return 0 |
|---|
| 119 | } |
|---|
| 120 | "event" - |
|---|
| 121 | "irc_event" { |
|---|
| 122 | global BMOTION_PLUGIN_EVENT_TYPE BMOTION_PLUGIN_EVENT_MATCH BMOTION_PLUGIN_EVENT_CHANCE BMOTION_PLUGIN_EVENT_CALLBACK BMOTION_PLUGIN_EVENT_LANGUAGE |
|---|
| 123 | bMotion_putadmin "Plugin details for irc_event:$id ([lindex $details $BMOTION_PLUGIN_EVENT_LANGUAGE]) [lindex $details $BMOTION_PLUGIN_EVENT_CHANCE]%" |
|---|
| 124 | bMotion_putadmin " Event type: [lindex $details $BMOTION_PLUGIN_EVENT_TYPE], match on: [lindex $details $BMOTION_PLUGIN_EVENT_MATCH]" |
|---|
| 125 | bMotion_putadmin " Callback: [lindex $details $BMOTION_PLUGIN_EVENT_CALLBACK]" |
|---|
| 126 | return 0 |
|---|
| 127 | } |
|---|
| 128 | "management" { |
|---|
| 129 | global BMOTION_PLUGIN_MANAGEMENT_MATCH BMOTION_PLUGIN_MANAGEMENT_FLAGS BMOTION_PLUGIN_MANAGEMENT_CALLBACK BMOTION_PLUGIN_MANAGEMENT_HELPCALLBACK |
|---|
| 130 | bMotion_putadmin "Plugin details for management:$id ([lindex $details $BMOTION_PLUGIN_MANAGEMENT_FLAGS])" |
|---|
| 131 | bMotion_putadmin " Match: [lindex $details $BMOTION_PLUGIN_MANAGEMENT_MATCH]" |
|---|
| 132 | bMotion_putadmin " Callback: [lindex $details $BMOTION_PLUGIN_MANAGEMENT_CALLBACK]" |
|---|
| 133 | bMotion_putadmin " Help callback: [lindex $details $BMOTION_PLUGIN_MANAGEMENT_HELPCALLBACK]" |
|---|
| 134 | return 0 |
|---|
| 135 | } |
|---|
| 136 | default { |
|---|
| 137 | bMotion_putadmin "?" |
|---|
| 138 | return 0 |
|---|
| 139 | } |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | #all else fails, list the modules: |
|---|
| 144 | if [regexp -nocase {list( (.+))?} $arg matches what re] { |
|---|
| 145 | global BMOTION_PLUGIN_OUTPUT_ENABLED BMOTION_PLUGIN_OUTPUT_PRIORITY |
|---|
| 146 | |
|---|
| 147 | set total 0 |
|---|
| 148 | if {$re != ""} { |
|---|
| 149 | bMotion_putadmin "Installed bMotion plugins (filtered for '$re'):" |
|---|
| 150 | } else { |
|---|
| 151 | bMotion_putadmin "Installed bMotion plugins:" |
|---|
| 152 | } |
|---|
| 153 | foreach t {simple complex output action_simple action_complex irc_event management} { |
|---|
| 154 | set arrayName "bMotion_plugins_$t" |
|---|
| 155 | upvar #0 $arrayName plugins |
|---|
| 156 | set plugin_names [lsort [array names plugins]] |
|---|
| 157 | set a "\002$t\002: " |
|---|
| 158 | set count 0 |
|---|
| 159 | foreach n $plugin_names { |
|---|
| 160 | if {($re == "") || [regexp -nocase $re $n]} { |
|---|
| 161 | if {[string length $a] > 55} { |
|---|
| 162 | bMotion_putadmin "$a" |
|---|
| 163 | set a " " |
|---|
| 164 | } |
|---|
| 165 | incr count |
|---|
| 166 | incr total |
|---|
| 167 | if {$t == "output"} { |
|---|
| 168 | set details $plugins($n) |
|---|
| 169 | append a [lindex $plugins($n) $BMOTION_PLUGIN_OUTPUT_PRIORITY] |
|---|
| 170 | if {[lindex $plugins($n) $BMOTION_PLUGIN_OUTPUT_ENABLED] == 1} { |
|---|
| 171 | append a "/$n\[on\], " |
|---|
| 172 | } else { |
|---|
| 173 | append a "/$n\[off\], " |
|---|
| 174 | } |
|---|
| 175 | } else { |
|---|
| 176 | append a "$n, " |
|---|
| 177 | } |
|---|
| 178 | } |
|---|
| 179 | } |
|---|
| 180 | regsub ", *\$" $a "" a |
|---|
| 181 | if {($re != "") && $count} { |
|---|
| 182 | bMotion_putadmin "$a ($count)\n" |
|---|
| 183 | } else { |
|---|
| 184 | bMotion_putadmin $a |
|---|
| 185 | } |
|---|
| 186 | } |
|---|
| 187 | bMotion_putadmin "Total plugins: $total" |
|---|
| 188 | return 0 |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | #all else fails, give usage: |
|---|
| 192 | bMotion_putadmin "usage: plugins (list|info|remove|enable|disable)" |
|---|
| 193 | return 0 |
|---|
| 194 | } |
|---|