### Home Classes Methods

### In Files

- lib/rbot/core/userdata.rb

### Parent

CoreBotModule

### Methods

- ::new
- #delete_data
- #event_botuser
- #get_data
- #get_data_hash
- #handle_get
- #set_data
- #set_data_hash
- #with_data

### 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.

# UserDataModule

User data is stored in registries indexed by BotUser name and Irc::User nick. This core module takes care of handling its usage.

### Public Class Methods

new() click to toggle source

    # File lib/rbot/core/userdata.rb, line 57
    def initialize
      super
      @ircuser = @registry.sub_registry('ircuser')
      @transient = @registry.sub_registry('transient')
      @botuser = @registry.sub_registry('botuser')
    end

### Public Instance Methods

delete_data(user, *keys) click to toggle source

    # File lib/rbot/core/userdata.rb, line 148
    def delete_data(user, *keys)
      h = get_data_hash(user)
      debug h
      rv = keys.map { |k| h.delete k }
      set_data_hash(user, h)
      rv.size == 1 ? rv.first : rv
    end

event_botuser(action, opts={}) click to toggle source

    TODO FIXME not yet: are we going to allow non-string
    values for data? if so, this can't work ...

def handle_set(m, params)

    user = m.server.get_user(params[:nick]) || m.source
    key = params[:key].intern
    data = params[:data].to_s

end

    # File lib/rbot/core/userdata.rb, line 183
    def event_botuser(action, opts={})
      case action
      when :copy, :rename
        source = opts[:source]
        return unless @botuser.key?(source)
        dest = opts[:dest]
        @botuser[dest] = @botuser[source].dup
        @botuser.delete(source) if action == :rename
      when :pre_perm
        @permification ||= {}
        k = [opts[:irc_user], opts[:bot_user]]
        @permification[k] = get_data_hash(opts[:irc_user], :plain => true)
      when :post_perm
        @permification ||= {}
        k = [opts[:irc_user], opts[:bot_user]]
        if @permification.has_key?(k)
          @botuser[opts[:bot_user]] = @permification[k]
          @permification.delete(k)
        end
      end
    end

get_data(user, key=nil) click to toggle source

    # File lib/rbot/core/userdata.rb, line 91
    def get_data(user, key=nil)
      h = get_data_hash(user)
      debug h
      return h if key.nil?
      return h[key]
    end

get_data_hash(user, opts={}) click to toggle source

    # File lib/rbot/core/userdata.rb, line 64
    def get_data_hash(user, opts={})
      plain = opts[:plain]
      iu = user.to_irc_user
      bu = iu.botuser

      ih = @ircuser[iu.nick] || {}

      if bu.default?
        return ih
      elsif bu.transient?
        bh = @transient[bu.netmasks.first.fullform] || {}
      else
        bh = @botuser[bu.username] || {}
      end
      ih.merge!(bh)

      unless plain
        class << ih
          alias :single_retrieve :[]
          alias :single_assign :[]=
            include DottedIndex
        end
      end

      return ih
    end

handle_get(m, params) click to toggle source

    # File lib/rbot/core/userdata.rb, line 156
    def handle_get(m, params)
      user = m.server.get_user(params[:nick]) || m.source
      key = params[:key].intern
      data = get_data(user, key)
      if data
        m.reply(_("%{key} data for %{user}: %{data}") % {
          :key => key,
          :user => user.nick,
          :data => data
        })
      else
        m.reply(_("sorry, no %{key} data for %{user}") % {
          :key => key,
          :user => user.nick,
        })
      end
    end

set_data(user, key, value=nil, &block) click to toggle source

    # File lib/rbot/core/userdata.rb, line 117
    def set_data(user, key, value=nil, &block)
      h = get_data_hash(user)
      debug h

      ret = value

      if not block_given?
        h[key] = value
      else
        if value and not h.has_key?(key)
          h[key] = value
        end
        ret = yield h[key]
      end
      debug ret

      set_data_hash(user, h)

      return ret
    end

set_data_hash(user, hh) click to toggle source

    # File lib/rbot/core/userdata.rb, line 98
    def set_data_hash(user, hh)
      iu = user.to_irc_user
      bu = iu.botuser

      # we .dup the hash to remove singleton methods
      # and make it dump-able
      h = hh.dup

      @ircuser[iu.nick] = h
      return h if bu.default?

      if bu.transient?
        @transient[bu.netmasks.first.fullform] = h
      else
        @botuser[bu.username] = h
      end
      return h
    end

with_data(user, &block) click to toggle source

    # File lib/rbot/core/userdata.rb, line 138
    def with_data(user, &block)
      h = get_data_hash(user)
      debug h
      yield h

      set_data_hash(user, h)

      return h
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.