4 # :title: rbot plugin management
10 Config.register Config::ArrayValue.new('plugins.blacklist',
11 :default => [], :wizard => false, :requires_rescan => true,
12 :desc => "Plugins that should not be loaded")
13 Config.register Config::ArrayValue.new('plugins.whitelist',
14 :default => [], :wizard => false, :requires_rescan => true,
15 :desc => "Only whitelisted plugins will be loaded unless the list is empty")
17 require 'rbot/messagemapper'
20 BotModule is the base class for the modules that enhance the rbot
21 functionality. Rather than subclassing BotModule, however, one should
22 subclass either CoreBotModule (reserved for system modules) or Plugin
25 A BotModule interacts with Irc events by defining one or more of the following
26 methods, which get called as appropriate when the corresponding Irc event
29 map(template, options)::
30 map!(template, options)::
31 map is the new, cleaner way to respond to specific message formats without
32 littering your plugin code with regexps, and should be used instead of
33 #register() and #privmsg() (see below) when possible.
35 The difference between map and map! is that map! will not register the new
36 command as an alternative name for the plugin.
40 plugin.map 'karmastats', :action => 'karma_stats'
42 # while in the plugin...
43 def karma_stats(m, params)
47 # the default action is the first component
50 # attributes can be pulled out of the match string
51 plugin.map 'karma for :key'
52 plugin.map 'karma :key'
54 # while in the plugin...
57 m.reply 'karma for #{item}'
60 # you can setup defaults, to make parameters optional
61 plugin.map 'karma :key', :defaults => {:key => 'defaultvalue'}
63 # the default auth check is also against the first component
64 # but that can be changed
65 plugin.map 'karmastats', :auth => 'karma'
67 # maps can be restricted to public or private message:
68 plugin.map 'karmastats', :private => false
69 plugin.map 'karmastats', :public => false
71 See MessageMapper#map for more information on the template format and the
75 Called for all messages of any type. To
76 differentiate them, use message.kind_of? It'll be
77 either a PrivMessage, NoticeMessage, KickMessage,
78 QuitMessage, PartMessage, JoinMessage, NickMessage,
81 ctcp_listen(UserMessage)::
82 Called for all messages that contain a CTCP command.
83 Use message.ctcp to get the CTCP command, and
84 message.message to get the parameter string. To reply,
85 use message.ctcp_reply, which sends a private NOTICE
88 message(PrivMessage)::
89 Called for all PRIVMSG. Hook on this method if you
90 need to handle PRIVMSGs regardless of whether they are
91 addressed to the bot or not, and regardless of
93 privmsg(PrivMessage)::
94 Called for a PRIVMSG if the first word matches one
95 the plugin #register()ed for. Use m.plugin to get
96 that word and m.params for the rest of the message,
99 unreplied(PrivMessage)::
100 Called for a PRIVMSG which has not been replied to.
102 notice(NoticeMessage)::
103 Called for all Notices. Please notice that in general
104 should not be replied to.
107 Called when a user (or the bot) is kicked from a
108 channel the bot is in.
110 invite(InviteMessage)::
111 Called when the bot is invited to a channel.
114 Called when a user (or the bot) joins a channel
117 Called when a user (or the bot) parts a channel
120 Called when a user (or the bot) quits IRC
123 Called when a user (or the bot) changes Nick
124 modechange(ModeChangeMessage)::
125 Called when a User or Channel mode is changed
126 topic(TopicMessage)::
127 Called when a user (or the bot) changes a channel
130 welcome(WelcomeMessage)::
131 Called when the welcome message is received on
132 joining a server succesfully.
135 Called when the Message Of The Day is fully
136 recevied from the server.
138 connect:: Called when a server is joined successfully, but
139 before autojoin channels are joined (no params)
141 set_language(String)::
142 Called when the user sets a new language
143 whose name is the given String
145 save:: Called when you are required to save your plugin's
146 state, if you maintain data between sessions
148 cleanup:: called before your plugin is "unloaded", prior to a
149 plugin reload or bot quit - close any open
150 files/connections or flush caches here
157 # the plugin registry
158 attr_reader :registry
160 # the message map handler
163 # Initialise your bot module. Always call super if you override this method,
164 # as important variables are set up for you:
169 # the botmodule's registry, which can be used to store permanent data
170 # (see Registry::Accessor for additional documentation)
172 # Other instance variables which are defined and should not be overwritten
173 # byt the user, but aren't usually accessed directly, are:
176 # the plugins manager instance
177 # @botmodule_triggers::
178 # an Array of words this plugin #register()ed itself for
180 # the MessageMapper that handles this plugin's maps
183 @manager = Plugins::manager
187 @botmodule_triggers = Array.new
189 @handler = MessageMapper.new(self)
190 @registry = Registry::Accessor.new(@bot, self.class.to_s.gsub(/^.*::/, ""))
192 @manager.add_botmodule(self)
193 if self.respond_to?('set_language')
194 self.set_language(@bot.lang.language)
198 # Changing the value of @priority directly will cause problems,
199 # Please use priority=.
204 # Returns the symbol :BotModule
209 # Method called to flush the registry, thus ensuring that the botmodule's permanent
210 # data is committed to disk
213 # debug "Flushing #{@registry}"
217 # Method called to cleanup before the plugin is unloaded. If you overload
218 # this method to handle additional cleanup tasks, remember to call super()
219 # so that the default cleanup actions are taken care of as well.
222 # debug "Closing #{@registry}"
226 # Handle an Irc::PrivMessage for which this BotModule has a map. The method
227 # is called automatically and there is usually no need to call it
234 # Signal to other BotModules that an even happened.
236 def call_event(ev, *args)
237 @bot.plugins.delegate('event_' + ev.to_s.gsub(/[^\w\?!]+/, '_'), *(args.push Hash.new))
240 # call-seq: map(template, options)
242 # This is the preferred way to register the BotModule so that it
243 # responds to appropriately-formed messages on Irc.
249 # call-seq: map!(template, options)
251 # This is the same as map but doesn't register the new command
252 # as an alternative name for the plugin.
258 # Auxiliary method called by #map and #map!
259 def do_map(silent, *args)
260 @handler.map(self, *args)
264 self.register name, :auth => nil, :hidden => silent
265 @manager.register_map(self, map)
266 unless self.respond_to?('privmsg')
267 def self.privmsg(m) #:nodoc:
273 # Sets the default auth for command path _cmd_ to _val_ on channel _chan_:
274 # usually _chan_ is either "*" for everywhere, public and private (in which
275 # case it can be omitted) or "?" for private communications
277 def default_auth(cmd, val, chan="*")
284 Auth::defaultbotuser.set_default_permission(propose_default_path(c), val)
287 # Gets the default command path which would be given to command _cmd_
288 def propose_default_path(cmd)
289 [name, cmd].compact.join("::")
292 # Return an identifier for this plugin, defaults to a list of the message
293 # prefixes handled (used for error messages etc)
295 self.class.to_s.downcase.sub(/^#<module:.*?>::/,"").sub(/(plugin|module)?$/,"")
308 # Return a help string for your module. For complex modules, you may wish
309 # to break your help into topics, and return a list of available topics if
310 # +topic+ is nil. +plugin+ is passed containing the matching prefix for
311 # this message - if your plugin handles multiple prefixes, make sure you
312 # return the correct help for the prefix requested
313 def help(plugin, topic)
317 # Register the plugin as a handler for messages prefixed _cmd_.
319 # This can be called multiple times for a plugin to handle multiple message
322 # This command is now superceded by the #map() command, which should be used
323 # instead whenever possible.
325 def register(cmd, opts={})
326 raise ArgumentError, "Second argument must be a hash!" unless opts.kind_of?(Hash)
327 who = @manager.who_handles?(cmd)
329 raise "Command #{cmd} is already handled by #{who.botmodule_class} #{who}" if who != self
332 if opts.has_key?(:auth)
333 @manager.register(self, cmd, opts[:auth])
335 @manager.register(self, cmd, propose_default_path(cmd))
337 @botmodule_triggers << cmd unless opts.fetch(:hidden, false)
340 # Default usage method provided as a utility for simple plugins. The
341 # MessageMapper uses 'usage' as its default fallback method.
343 def usage(m, params = {})
344 if params[:failures].respond_to? :find
345 friendly = params[:failures].find do |f|
346 f.kind_of? MessageMapper::FriendlyFailure
349 m.reply friendly.friendly
353 m.reply(_("incorrect usage, ask for help using '%{command}'") % {:command => "#{@bot.nick}: help #{m.plugin}"})
356 # Define the priority of the module. During event delegation, lower
357 # priority modules will be called first. Default priority is 1
361 @bot.plugins.mark_priorities_dirty
365 # Directory name to be joined to the botclass to access data files. By
366 # default this is the plugin name itself, but may be overridden, for
367 # example by plugins that share their datafiles or for backwards
373 # Filename for a datafile built joining the botclass, plugin dirname and
376 @bot.path dirname, *fname
380 # A CoreBotModule is a BotModule that provides core functionality.
382 # This class should not be used by user plugins, as it's reserved for system
383 # plugins such as the ones that handle authentication, configuration and basic
386 class CoreBotModule < BotModule
392 # A Plugin is a BotModule that provides additional functionality.
394 # A user-defined plugin should subclass this, and then define any of the
395 # methods described in the documentation for BotModule to handle interaction
398 class Plugin < BotModule
404 # Singleton to manage multiple plugins and delegate messages to them for
406 class PluginManagerClass
409 attr_reader :botmodules
412 # This is the list of patterns commonly delegated to plugins.
413 # A fast delegation lookup is enabled for them.
414 DEFAULT_DELEGATE_PATTERNS = %r{^(?:
416 listen|ctcp_listen|privmsg|unreplied|
418 save|cleanup|flush_registry|
424 :CoreBotModule => [],
428 @names_hash = Hash.new
429 @commandmappers = Hash.new
432 # modules will be sorted on first delegate call
433 @sorted_modules = nil
435 @delegate_list = Hash.new { |h, k|
439 @core_module_dirs = []
449 ret = self.to_s[0..-2]
450 ret << ' corebotmodules='
451 ret << @botmodules[:CoreBotModule].map { |m|
455 ret << @botmodules[:Plugin].map { |m|
461 # Reset lists of botmodules
462 def reset_botmodule_lists
463 @botmodules[:CoreBotModule].clear
464 @botmodules[:Plugin].clear
466 @commandmappers.clear
468 @failures_shown = false
469 mark_priorities_dirty
472 # Associate with bot _bot_
473 def bot_associate(bot)
474 reset_botmodule_lists
478 # Returns the botmodule with the given _name_
480 @names_hash[name.to_sym]
483 # Returns +true+ if _cmd_ has already been registered as a command
484 def who_handles?(cmd)
485 return nil unless @commandmappers.has_key?(cmd.to_sym)
486 return @commandmappers[cmd.to_sym][:botmodule]
489 # Registers botmodule _botmodule_ with command _cmd_ and command path _auth_path_
490 def register(botmodule, cmd, auth_path)
491 raise TypeError, "First argument #{botmodule.inspect} is not of class BotModule" unless botmodule.kind_of?(BotModule)
492 @commandmappers[cmd.to_sym] = {:botmodule => botmodule, :auth => auth_path}
495 # Registers botmodule _botmodule_ with map _map_. This adds the map to the #maps hash
496 # which has three keys:
498 # botmodule:: the associated botmodule
499 # auth:: an array of auth keys checked by the map; the first is the full_auth_path of the map
500 # map:: the actual MessageTemplate object
503 def register_map(botmodule, map)
504 raise TypeError, "First argument #{botmodule.inspect} is not of class BotModule" unless botmodule.kind_of?(BotModule)
505 @maps[map.template] = { :botmodule => botmodule, :auth => [map.options[:full_auth_path]], :map => map }
508 def add_botmodule(botmodule)
509 raise TypeError, "Argument #{botmodule.inspect} is not of class BotModule" unless botmodule.kind_of?(BotModule)
510 kl = botmodule.botmodule_class
511 if @names_hash.has_key?(botmodule.to_sym)
512 case self[botmodule].botmodule_class
514 raise "#{kl} #{botmodule} already registered!"
516 raise "#{self[botmodule].botmodule_class} #{botmodule} already registered, cannot re-register as #{kl}"
519 @botmodules[kl] << botmodule
520 @names_hash[botmodule.to_sym] = botmodule
521 mark_priorities_dirty
524 # Returns an array of the loaded plugins
526 @botmodules[:CoreBotModule]
529 # Returns an array of the loaded plugins
534 # Returns a hash of the registered message prefixes and associated
540 # Tells the PluginManager that the next time it delegates an event, it
541 # should sort the modules by priority
542 def mark_priorities_dirty
543 @sorted_modules = nil
546 # Makes a string of error _err_ by adding text _str_
547 def report_error(str, err)
548 ([str, err.inspect] + err.backtrace).join("\n")
551 # This method is the one that actually loads a module from the
554 # _desc_ is a simple description of what we are loading (plugin/botmodule/whatever)
556 # It returns the Symbol :loaded on success, and an Exception
559 def load_botmodule_file(fname, desc=nil)
560 # create a new, anonymous module to "house" the plugin
561 # the idea here is to prevent namespace pollution. perhaps there
563 plugin_module = Module.new
564 # each plugin uses its own textdomain, we bind it automatically here
565 bindtextdomain_to(plugin_module, "rbot-#{File.basename(fname, '.rb')}")
567 desc = desc.to_s + " " if desc
570 plugin_string = IO.read(fname)
571 debug "loading #{desc}#{fname}"
572 plugin_module.module_eval(plugin_string, fname)
574 rescue Exception => err
575 # rescue TimeoutError, StandardError, NameError, LoadError, SyntaxError => err
576 raise if err.kind_of? DBFatal
577 error report_error("#{desc}#{fname} load failed", err)
578 bt = err.backtrace.select { |line|
579 line.match(/^(\(eval\)|#{fname}):\d+/)
582 el.gsub(/^\(eval\)(:\d+)(:in `.*')?(:.*)?/) { |m|
586 msg = err.to_s.gsub(/^\(eval\)(:\d+)(:in `.*')?(:.*)?/) { |m|
590 newerr = err.class.new(msg)
591 rescue ArgumentError => err_in_err
592 # Somebody should hang the ActiveSupport developers by their balls
593 # with barbed wire. Their MissingSourceFile extension to LoadError
594 # _expects_ a second argument, breaking the usual Exception interface
595 # (instead, the smart thing to do would have been to make the second
596 # parameter optional and run the code in the from_message method if
598 # Anyway, we try to cope with this in the simplest possible way. On
599 # the upside, this new block can be extended to handle other similar
601 if err.class.respond_to? :from_message
602 newerr = err.class.from_message(msg)
607 newerr.set_backtrace(bt)
611 private :load_botmodule_file
613 # add one or more directories to the list of directories to
614 # load core modules from
615 def add_core_module_dir(*dirlist)
616 @core_module_dirs += dirlist
617 debug "Core module loading paths: #{@core_module_dirs.join(', ')}"
620 # add one or more directories to the list of directories to
622 def add_plugin_dir(*dirlist)
623 @plugin_dirs += dirlist
624 debug "Plugin loading paths: #{@plugin_dirs.join(', ')}"
627 def clear_botmodule_dirs
628 @core_module_dirs.clear
630 debug "Core module and plugin loading paths cleared"
633 def scan_botmodules(opts={})
639 dirs = @core_module_dirs
643 @bot.config['plugins.blacklist'].each { |p|
645 processed[pn.intern] = :blacklisted
648 whitelist = @bot.config['plugins.whitelist'].map { |p|
654 next unless FileTest.directory?(dir)
656 d.sort.each do |file|
657 next unless file =~ /\.rb$/
658 next if file =~ /^\./
662 if !whitelist.empty? && !whitelist.include?(file)
663 @ignored << {:name => file, :dir => dir, :reason => :"not whitelisted" }
665 elsif processed.has_key?(file.intern)
666 @ignored << {:name => file, :dir => dir, :reason => processed[file.intern]}
670 if(file =~ /^(.+\.rb)\.disabled$/)
671 # GB: Do we want to do this? This means that a disabled plugin in a directory
672 # will disable in all subsequent directories. This was probably meant
673 # to be used before plugins.blacklist was implemented, so I think
674 # we don't need this anymore
675 processed[$1.intern] = :disabled
676 @ignored << {:name => $1, :dir => dir, :reason => processed[$1.intern]}
681 did_it = load_botmodule_file("#{dir}/#{file}", "plugin")
684 processed[file.intern] = did_it
686 @failed << { :name => file, :dir => dir, :reason => did_it }
692 # load plugins from pre-assigned list of directories
698 scan_botmodules(:type => :core)
699 scan_botmodules(:type => :plugins)
701 debug "finished loading plugins: #{status(true)}"
702 (core_modules + plugins).each { |p|
703 p.methods.grep(DEFAULT_DELEGATE_PATTERNS).each { |m|
704 @delegate_list[m.intern] << p
707 mark_priorities_dirty
710 # call the save method for each active plugin
712 delegate 'flush_registry'
716 # call the cleanup method for each active plugin
719 reset_botmodule_lists
722 # drop all plugins and rescan plugins on disk
723 # calls save and cleanup for each plugin before dropping them
730 def status(short=false)
732 if self.core_length > 0
734 output << n_("%{count} core module loaded", "%{count} core modules loaded",
735 self.core_length) % {:count => self.core_length}
737 output << n_("%{count} core module: %{list}",
738 "%{count} core modules: %{list}", self.core_length) %
739 { :count => self.core_length,
740 :list => core_modules.collect{ |p| p.name}.sort.join(", ") }
743 output << _("no core botmodules loaded")
745 # Active plugins first
748 output << n_("%{count} plugin loaded", "%{count} plugins loaded",
749 self.length) % {:count => self.length}
751 output << n_("%{count} plugin: %{list}",
752 "%{count} plugins: %{list}", self.length) %
753 { :count => self.length,
754 :list => plugins.collect{ |p| p.name}.sort.join(", ") }
757 output << "no plugins active"
759 # Ignored plugins next
760 unless @ignored.empty? or @failures_shown
762 output << n_("%{highlight}%{count} plugin ignored%{highlight}",
763 "%{highlight}%{count} plugins ignored%{highlight}",
765 { :count => @ignored.length, :highlight => Underline }
767 output << n_("%{highlight}%{count} plugin ignored%{highlight}: use %{bold}%{command}%{bold} to see why",
768 "%{highlight}%{count} plugins ignored%{highlight}: use %{bold}%{command}%{bold} to see why",
770 { :count => @ignored.length, :highlight => Underline,
771 :bold => Bold, :command => "help ignored plugins"}
774 # Failed plugins next
775 unless @failed.empty? or @failures_shown
777 output << n_("%{highlight}%{count} plugin failed to load%{highlight}",
778 "%{highlight}%{count} plugins failed to load%{highlight}",
780 { :count => @failed.length, :highlight => Reverse }
782 output << n_("%{highlight}%{count} plugin failed to load%{highlight}: use %{bold}%{command}%{bold} to see why",
783 "%{highlight}%{count} plugins failed to load%{highlight}: use %{bold}%{command}%{bold} to see why",
785 { :count => @failed.length, :highlight => Reverse,
786 :bold => Bold, :command => "help failed plugins"}
792 # return list of help topics (plugin names)
795 @failures_shown = true
807 # return help for +topic+ (call associated plugin's help method)
810 when /fail(?:ed)?\s*plugins?.*(trace(?:back)?s?)?/
811 # debug "Failures: #{@failed.inspect}"
812 return _("no plugins failed to load") if @failed.empty?
813 return @failed.collect { |p|
814 _('%{highlight}%{plugin}%{highlight} in %{dir} failed with error %{exception}: %{reason}') % {
815 :highlight => Bold, :plugin => p[:name], :dir => p[:dir],
816 :exception => p[:reason].class, :reason => p[:reason],
817 } + if $1 && !p[:reason].backtrace.empty?
818 _('at %{backtrace}') % {:backtrace => p[:reason].backtrace.join(', ')}
823 when /ignored?\s*plugins?/
824 return _('no plugins were ignored') if @ignored.empty?
828 reason = p[:loaded] ? _('overruled by previous') : _(p[:reason].to_s)
829 ((tmp[p[:dir]] ||= Hash.new)[reason] ||= Array.new).push(p[:name])
832 return tmp.map do |dir, reasons|
833 # FIXME get rid of these string concatenations to make gettext easier
834 s = reasons.map { |r, list|
835 list.map { |_| _.sub(/\.rb$/, '') }.join(', ') + " (#{r})"
839 when /^(\S+)\s*(.*)$/
843 # Let's see if we can match a plugin by the given name
844 (core_modules + plugins).each { |p|
845 next unless p.name == key
847 return p.help(key, params)
848 rescue Exception => err
849 #rescue TimeoutError, StandardError, NameError, SyntaxError => err
850 error report_error("#{p.botmodule_class} #{p.name} help() failed:", err)
854 # Nope, let's see if it's a command, and ask for help at the corresponding botmodule
856 if commands.has_key?(k)
857 p = commands[k][:botmodule]
859 return p.help(key, params)
860 rescue Exception => err
861 #rescue TimeoutError, StandardError, NameError, SyntaxError => err
862 error report_error("#{p.botmodule_class} #{p.name} help() failed:", err)
870 @sorted_modules = (core_modules + plugins).sort do |a, b|
871 a.priority <=> b.priority
874 @delegate_list.each_value do |list|
875 list.sort! {|a,b| a.priority <=> b.priority}
879 # call-seq: delegate</span><span class="method-args">(method, m, opts={})</span>
880 # <span class="method-name">delegate</span><span class="method-args">(method, opts={})
882 # see if each plugin handles _method_, and if so, call it, passing
883 # _m_ as a parameter (if present). BotModules are called in order of
884 # priority from lowest to highest.
886 # If the passed _m_ is a BasicUserMessage and is marked as #ignored?, it
887 # will only be delegated to plugins with negative priority. Conversely, if
888 # it's a fake message (see BotModule#fake_message), it will only be
889 # delegated to plugins with positive priority.
891 # Note that _m_ can also be an exploded Array, but in this case the last
892 # element of it cannot be a Hash, or it will be interpreted as the options
893 # Hash for delegate itself. The last element can be a subclass of a Hash, though.
894 # To be on the safe side, you can add an empty Hash as last parameter for delegate
895 # when calling it with an exploded Array:
896 # @bot.plugins.delegate(method, *(args.push Hash.new))
898 # Currently supported options are the following:
900 # if specified, the delegation will only consider plugins with a priority
901 # higher than the specified value
903 # if specified, the delegation will only consider plugins with a priority
904 # lower than the specified value
906 def delegate(method, *args)
907 # if the priorities order of the delegate list is dirty,
908 # meaning some modules have been added or priorities have been
909 # changed, then the delegate list will need to be sorted before
910 # delegation. This should always be true for the first delegation.
911 sort_modules unless @sorted_modules
914 opts.merge(args.pop) if args.last.class == Hash
917 if BasicUserMessage === m
918 # ignored messages should not be delegated
919 # to plugins with positive priority
920 opts[:below] ||= 0 if m.ignored?
921 # fake messages should not be delegated
922 # to plugins with negative priority
923 opts[:above] ||= 0 if m.recurse_depth > 0
929 # debug "Delegating #{method.inspect}"
931 if method.match(DEFAULT_DELEGATE_PATTERNS)
932 debug "fast-delegating #{method}"
934 debug "no-one to delegate to" unless @delegate_list.has_key?(m)
935 return [] unless @delegate_list.has_key?(m)
936 @delegate_list[m].each { |p|
939 unless (above and above >= prio) or (below and below <= prio)
940 ret.push p.send(method, *args)
942 rescue Exception => err
943 raise if err.kind_of?(SystemExit)
944 error report_error("#{p.botmodule_class} #{p.name} #{method}() failed:", err)
945 raise if err.kind_of?(DBFatal)
949 debug "slow-delegating #{method}"
950 @sorted_modules.each { |p|
951 if(p.respond_to? method)
953 # debug "#{p.botmodule_class} #{p.name} responds"
955 unless (above and above >= prio) or (below and below <= prio)
956 ret.push p.send(method, *args)
958 rescue Exception => err
959 raise if err.kind_of?(SystemExit)
960 error report_error("#{p.botmodule_class} #{p.name} #{method}() failed:", err)
961 raise if err.kind_of?(DBFatal)
967 # debug "Finished delegating #{method.inspect}"
970 # see if we have a plugin that wants to handle this message, if so, pass
971 # it to the plugin and return true, otherwise false
973 debug "Delegating privmsg #{m.inspect} with pluginkey #{m.plugin.inspect}"
974 return unless m.plugin
976 if commands.has_key?(k)
977 p = commands[k][:botmodule]
978 a = commands[k][:auth]
979 # We check here for things that don't check themselves
980 # (e.g. mapped things)
981 debug "Checking auth ..."
982 if a.nil? || @bot.auth.allow?(a, m.source, m.replyto)
983 debug "Checking response ..."
984 if p.respond_to?("privmsg")
986 debug "#{p.botmodule_class} #{p.name} responds"
988 rescue Exception => err
989 raise if err.kind_of?(SystemExit)
990 error report_error("#{p.botmodule_class} #{p.name} privmsg() failed:", err)
991 raise if err.kind_of?(DBFatal)
993 debug "Successfully delegated #{m.inspect}"
996 debug "#{p.botmodule_class} #{p.name} is registered, but it doesn't respond to privmsg()"
999 debug "#{p.botmodule_class} #{p.name} is registered, but #{m.source} isn't allowed to call #{m.plugin.inspect} on #{m.replyto}"
1002 debug "Command #{k} isn't handled"
1007 # delegate IRC messages, by delegating 'listen' first, and the actual method
1008 # afterwards. Delegating 'privmsg' also delegates ctcp_listen and message
1010 def irc_delegate(method, m)
1011 delegate('listen', m)
1012 if method.to_sym == :privmsg
1013 delegate('ctcp_listen', m) if m.ctcp
1014 delegate('message', m)
1015 privmsg(m) if m.address? and not m.ignored?
1016 delegate('unreplied', m) unless m.replied
1023 # Returns the only PluginManagerClass instance
1025 return PluginManagerClass.instance