### Home Classes Methods

### In Files

- lib/rbot/core/remote.rb

### Parent

MessageMapper

### Methods

- ::new
- #handle
- #map
- #unmap

### Class/Module Index

Quicksearch

- Irc
- Irc::AsciiCasemap
- Irc::BanlistMessage
- Irc::BasicUserMessage
- Irc::Bot
- Irc::Bot::Auth
- Irc::Bot::Auth::BotOwnerClass
- Irc::Bot::Auth::BotUser
- Irc::Bot::Auth::Command
- Irc::Bot::Auth::DefaultBotUserClass
- Irc::Bot::Auth::InvalidPassword
- Irc::Bot::Auth::ManagerClass
- Irc::Bot::Auth::PermissionSet
- Irc::Bot::Config
- Irc::Bot::Config::ArrayValue
- Irc::Bot::Config::BooleanValue
- Irc::Bot::Config::EnumValue
- Irc::Bot::Config::FloatValue
- Irc::Bot::Config::IntegerValue
- Irc::Bot::Config::ManagerClass
- Irc::Bot::Config::StringValue
- Irc::Bot::Config::Value
- Irc::Bot::Config::Wizard
- Irc::Bot::DataFilter
- Irc::Bot::DataStream
- Irc::Bot::Language
- Irc::Bot::MessageMapper
- Irc::Bot::MessageMapper::Failure
- Irc::Bot::MessageMapper::FriendlyFailure
- Irc::Bot::MessageMapper::NoActionFailure
- Irc::Bot::MessageMapper::NoMatchFailure
- Irc::Bot::MessageMapper::NotPrivateFailure
- Irc::Bot::MessageMapper::NotPublicFailure
- Irc::Bot::MessageMapper::PartialMatchFailure
- Irc::Bot::MessageParameter
- Irc::Bot::MessageTemplate
- Irc::Bot::Plugins
- Irc::Bot::Plugins::BotModule
- Irc::Bot::Plugins::CoreBotModule
- Irc::Bot::Plugins::Plugin
- Irc::Bot::Plugins::PluginManagerClass
- Irc::Bot::Plugins::RecurseTooDeep
- Irc::Bot::Plugins::RemoteBotModule
- Irc::Bot::Plugins::RemoteCoreBotModule
- Irc::Bot::Plugins::RemotePlugin
- Irc::Bot::Registry
- Irc::Bot::Registry::Accessor
- Irc::Bot::RemoteDispatcher
- Irc::Bot::RemoteMessage
- Irc::Bot::RemoteObject
- Irc::Bot::Wordlist
- Irc::BotConfig
- Irc::Casemap
- Irc::Channel
- Irc::Channel::Mode
- Irc::Channel::ModeHash
- Irc::Channel::ModeTypeA
- Irc::Channel::ModeTypeB
- Irc::Channel::ModeTypeC
- Irc::Channel::ModeTypeD
- Irc::Channel::Topic
- Irc::Channel::UserMode
- Irc::ChannelList
- Irc::Client
- Irc::DBHash
- Irc::DBTree
- Irc::InviteMessage
- Irc::JoinMessage
- Irc::KickMessage
- Irc::MessageQueue
- Irc::ModeChangeMessage
- Irc::MotdMessage
- Irc::NamesMessage
- Irc::Netmask
- Irc::NetmaskDb
- Irc::NetmaskDb::Tree
- Irc::NetmaskList
- Irc::NickMessage
- Irc::NoSuchTargetMessage
- Irc::NoticeMessage
- Irc::PartMessage
- Irc::PrivMessage
- Irc::QueueRing
- Irc::QuitMessage
- Irc::RfcCasemap
- Irc::Server
- Irc::ServerOrCasemap
- Irc::Socket
- Irc::Socket::IdentityFilter
- Irc::StrictRfcCasemap
- Irc::TopicMessage
- Irc::UnknownMessage
- Irc::User
- Irc::UserList
- Irc::UserMessage
- Irc::Utils
- Irc::Utils::HttpUtil
- Irc::Utils::HttpUtil::CachedObject
- Irc::Utils::ParseTime
- Irc::WelcomeMessage
- Irc::WhoisMessage
- BDB
- BDB::CIBtree
- MonitorMixin
- MonitorMixin::ConditionVariable
- Net
- Net::HTTPResponse
- Regexp
- Regexp::Irc
- Singleton
- Singleton::SingletonClassMethods
- Timer
- Timer::Action
- TokyoCabinet
- TokyoCabinet::CIBDB
- UnicodePlugin
- UnicodePlugin::UnicodeFilter
- Array
- ArrayOf
- AuthModule
- BasicsModule
- ConditionVariable
- ConfigModule
- DottedIndex
- Enumerable
- Exception
- FiltersModule
- GetText
- GetTextVersionError
- HttpUtilPlugin
- IrcLogModule
- Module
- Numeric
- Object
- Range
- RemoteModule
- ServerError
- String
- Symbol
- UserDataModule
- WordlistModule
- YAML

No matching classes.

# Irc::Bot::RemoteDispatcher

The RemoteDispatcher is a kind of MessageMapper, tuned to handle RemoteMessages

### Public Class Methods

new(bot) click to toggle source

It is initialized by passing it the bot instance

    # File lib/rbot/core/remote.rb, line 119
    def initialize(bot)
      super
    end

### Public Instance Methods

handle(m) click to toggle source

We redefine the handle() method from MessageMapper, taking into account that @parent is a bot, and that we don't handle fallbacks.

On failure to dispatch anything, the method returns false. If dispatching is successfull, the method returns a Hash.

Presently, the hash returned on success has only one key, :return, whose value is the actual return value of the successfull dispatch.

TODO this same kind of mechanism could actually be used in MessageMapper itself to be able to handle the case of multiple plugins having the same 'first word' ...

    # File lib/rbot/core/remote.rb, line 156
    def handle(m)
      return false if @templates.empty?
      failures = []
      @templates.each do |tmpl|
        # Skip this element if it was unmapped
        next unless tmpl
        botmodule = @parent.plugins[tmpl.botmodule]
        options = tmpl.recognize(m)
        if options.kind_of? Failure
          failures << options
        else
          action = tmpl.options[:action]
          unless botmodule.respond_to?(action)
            failures << NoActionFailure.new(tmpl, m)
            next
          end
          auth = tmpl.options[:full_auth_path]
          debug "checking auth for #{auth}"
          # We check for private permission
          if m.bot.auth.permit?(m.source, auth, '?')
            debug "template match found and auth'd: #{action.inspect} #{options.inspect}"
            return :return => botmodule.send(action, m, options)
          end
          debug "auth failed for #{auth}"
          # if it's just an auth failure but otherwise the match is good,
          # don't try any more handlers
          return false
        end
      end
      failures.each {|r|
        debug "#{r.template.inspect} => #{r}"
      }
      debug "no handler found"
      return false
    end

map(botmodule, *args) click to toggle source

The map method for the RemoteDispatcher returns the index of the inserted template

    # File lib/rbot/core/remote.rb, line 126
    def map(botmodule, *args)
      super
      return @templates.length - 1
    end

unmap(botmodule, handle) click to toggle source

The unmap method for the RemoteDispatcher nils the template at the given index, therefore effectively removing the mapping

    # File lib/rbot/core/remote.rb, line 134
    def unmap(botmodule, handle)
      tmpl = @templates[handle]
      raise "Botmodule #{botmodule.name} tried to unmap #{tmpl.inspect} that was handled by #{tmpl.botmodule}" unless tmpl.botmodule == botmodule.name
      debug "Unmapping #{tmpl.inspect}"
      @templates[handle] = nil
      @templates.clear unless @templates.compact.size > 0
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.