Class UserDataModule
In: lib/rbot/core/userdata.rb
Parent: CoreBotModule
User HTTPResponse BasicUserMessage Bot\n[lib/rbot/core/remote.rb\nlib/rbot/core/utils/extends.rb\nlib/rbot/core/utils/filters.rb\nlib/rbot/core/utils/wordlist.rb] HttpUtil UserDataModule CoreBotModule lib/rbot/core/userdata.rb lib/rbot/core/utils/httputil.rb lib/rbot/core/utils/extends.rb lib/rbot/core/remote.rb lib/rbot/core/utils/httputil.rb ParseTime Utils (null) dot/f_7.png

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

Methods

Public Class methods

[Source]

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

Public Instance methods

[Source]

     # File lib/rbot/core/userdata.rb, line 148
148:   def delete_data(user, *keys)
149:     h = get_data_hash(user)
150:     debug h
151:     rv = keys.map { |k| h.delete k }
152:     set_data_hash(user, h)
153:     rv.size == 1 ? rv.first : rv
154:   end
  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

[Source]

     # File lib/rbot/core/userdata.rb, line 183
183:   def event_botuser(action, opts={})
184:     case action
185:     when :copy, :rename
186:       source = opts[:source]
187:       return unless @botuser.key?(source)
188:       dest = opts[:dest]
189:       @botuser[dest] = @botuser[source].dup
190:       @botuser.delete(source) if action == :rename
191:     when :pre_perm
192:       @permification ||= {}
193:       k = [opts[:irc_user], opts[:bot_user]]
194:       @permification[k] = get_data_hash(opts[:irc_user], :plain => true)
195:     when :post_perm
196:       @permification ||= {}
197:       k = [opts[:irc_user], opts[:bot_user]]
198:       if @permification.has_key?(k)
199:         @botuser[opts[:bot_user]] = @permification[k]
200:         @permification.delete(k)
201:       end
202:     end
203:   end

[Source]

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

[Source]

    # File lib/rbot/core/userdata.rb, line 64
64:   def get_data_hash(user, opts={})
65:     plain = opts[:plain]
66:     iu = user.to_irc_user
67:     bu = iu.botuser
68: 
69:     ih = @ircuser[iu.nick] || {}
70: 
71:     if bu.default?
72:       return ih
73:     elsif bu.transient?
74:       bh = @transient[bu.netmasks.first.fullform] || {}
75:     else
76:       bh = @botuser[bu.username] || {}
77:     end
78:     ih.merge!(bh)
79: 
80:     unless plain
81:       class << ih
82:         alias :single_retrieve :[]
83:         alias :single_assign :[]=
84:           include DottedIndex
85:       end
86:     end
87: 
88:     return ih
89:   end

[Source]

     # File lib/rbot/core/userdata.rb, line 156
156:   def handle_get(m, params)
157:     user = m.server.get_user(params[:nick]) || m.source
158:     key = params[:key].intern
159:     data = get_data(user, key)
160:     if data
161:       m.reply(_("%{key} data for %{user}: %{data}") % {
162:         :key => key,
163:         :user => user.nick,
164:         :data => data
165:       })
166:     else
167:       m.reply(_("sorry, no %{key} data for %{user}") % {
168:         :key => key,
169:         :user => user.nick,
170:       })
171:     end
172:   end

[Source]

     # File lib/rbot/core/userdata.rb, line 117
117:   def set_data(user, key, value=nil, &block)
118:     h = get_data_hash(user)
119:     debug h
120: 
121:     ret = value
122: 
123:     if not block_given?
124:       h[key] = value
125:     else
126:       if value and not h.has_key?(key)
127:         h[key] = value
128:       end
129:       ret = yield h[key]
130:     end
131:     debug ret
132: 
133:     set_data_hash(user, h)
134: 
135:     return ret
136:   end

[Source]

     # File lib/rbot/core/userdata.rb, line 98
 98:   def set_data_hash(user, hh)
 99:     iu = user.to_irc_user
100:     bu = iu.botuser
101: 
102:     # we .dup the hash to remove singleton methods
103:     # and make it dump-able
104:     h = hh.dup
105: 
106:     @ircuser[iu.nick] = h
107:     return h if bu.default?
108: 
109:     if bu.transient?
110:       @transient[bu.netmasks.first.fullform] = h
111:     else
112:       @botuser[bu.username] = h
113:     end
114:     return h
115:   end

[Source]

     # File lib/rbot/core/userdata.rb, line 138
138:   def with_data(user, &block)
139:     h = get_data_hash(user)
140:     debug h
141:     yield h
142: 
143:     set_data_hash(user, h)
144: 
145:     return h
146:   end

[Validate]